Added tests for guessing the board and YAML, also missing YAML
This commit is contained in:
parent
b5448739ee
commit
c41faba302
|
|
@ -9,6 +9,9 @@ Tests miscellaneous stuff.
|
|||
- -s all and_one_of_two_outs
|
||||
- Missing schematic
|
||||
- Missing PCB
|
||||
- Missing config
|
||||
- Guess the PCB and YAML
|
||||
- Guess the PCB and YAML when more than one is present
|
||||
|
||||
For debug information use:
|
||||
pytest-3 --log-cli-level debug
|
||||
|
|
@ -16,6 +19,7 @@ pytest-3 --log-cli-level debug
|
|||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
# Look for the 'utils' module from where the script is running
|
||||
prev_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
sys.path.insert(0, os.path.dirname(prev_dir))
|
||||
|
|
@ -99,7 +103,7 @@ def test_select_output():
|
|||
ctx.clean_up()
|
||||
|
||||
|
||||
def test_select_miss_sch():
|
||||
def test_miss_sch():
|
||||
prj = '3Rs'
|
||||
ctx = context.TestContext('MissingSCH', prj, 'pre_and_position', POS_DIR)
|
||||
ctx.run(NO_SCH_FILE, extra=['pos_ascii'])
|
||||
|
|
@ -109,7 +113,7 @@ def test_select_miss_sch():
|
|||
ctx.clean_up()
|
||||
|
||||
|
||||
def test_select_miss_pcb():
|
||||
def test_miss_pcb():
|
||||
prj = '3Rs'
|
||||
ctx = context.TestContext('MissingPCB', prj, 'pre_and_position', POS_DIR)
|
||||
ctx.board_file = 'bogus'
|
||||
|
|
@ -118,3 +122,56 @@ def test_select_miss_pcb():
|
|||
assert ctx.search_err('Board file not found')
|
||||
|
||||
ctx.clean_up()
|
||||
|
||||
|
||||
def test_miss_yaml():
|
||||
prj = '3Rs'
|
||||
ctx = context.TestContext('MissingYaml', prj, 'pre_and_position', POS_DIR)
|
||||
ctx.run(EXIT_BAD_ARGS, no_yaml_file=True)
|
||||
|
||||
#assert ctx.search_err('Board file not found')
|
||||
|
||||
ctx.clean_up()
|
||||
|
||||
|
||||
def test_auto_pcb_and_cfg():
|
||||
prj = '3Rs'
|
||||
ctx = context.TestContext('GuessPCB_cfg', prj, 'pre_and_position', POS_DIR)
|
||||
|
||||
board_file = os.path.basename(ctx.board_file)
|
||||
shutil.copy2(ctx.board_file, ctx.get_out_path(board_file))
|
||||
yaml_file = os.path.basename(ctx.yaml_file)
|
||||
shutil.copy2(ctx.yaml_file, ctx.get_out_path(yaml_file))
|
||||
|
||||
ctx.run(extra=['-s', 'all', '-i', 'pos_ascii'], no_out_dir=True, no_board_file=True, no_yaml_file=True, chdir_out=True)
|
||||
|
||||
ctx.dont_expect_out_file(ctx.get_pos_both_filename())
|
||||
ctx.expect_out_file(ctx.get_pos_both_csv_filename())
|
||||
assert ctx.search_err('Using PCB file: '+board_file)
|
||||
assert ctx.search_err('Using config file: '+yaml_file)
|
||||
|
||||
ctx.clean_up()
|
||||
|
||||
def test_auto_pcb_and_cfg_2():
|
||||
prj = '3Rs'
|
||||
ctx = context.TestContext('GuessPCB_cfg_rep', prj, 'pre_and_position', POS_DIR)
|
||||
|
||||
board_file = os.path.basename(ctx.board_file)
|
||||
shutil.copy2(ctx.board_file, ctx.get_out_path(board_file))
|
||||
shutil.copy2(ctx.board_file, ctx.get_out_path('b_'+board_file))
|
||||
yaml_file = os.path.basename(ctx.yaml_file)
|
||||
shutil.copy2(ctx.yaml_file, ctx.get_out_path(yaml_file))
|
||||
shutil.copy2(ctx.yaml_file, ctx.get_out_path('b_'+yaml_file))
|
||||
|
||||
ctx.run(extra=['-s', 'all', '-i', 'pos_ascii'], no_out_dir=True, no_board_file=True, no_yaml_file=True, chdir_out=True)
|
||||
|
||||
assert ctx.search_err('WARNING:More than one PCB')
|
||||
assert ctx.search_err('WARNING:More than one config')
|
||||
m = ctx.search_err('Using (.*).kicad_pcb')
|
||||
assert m
|
||||
ctx.board_name = m.group(1)
|
||||
|
||||
ctx.dont_expect_out_file(ctx.get_pos_both_filename())
|
||||
ctx.expect_out_file(ctx.get_pos_both_csv_filename())
|
||||
|
||||
ctx.clean_up()
|
||||
|
|
|
|||
|
|
@ -145,15 +145,22 @@ class TestContext(object):
|
|||
with open(file, 'w') as f:
|
||||
f.write('Dummy file\n')
|
||||
|
||||
def run(self, ret_val=None, extra=None, use_a_tty=False, filename=None):
|
||||
def run(self, ret_val=None, extra=None, use_a_tty=False, filename=None, no_out_dir=False, no_board_file=False,
|
||||
no_yaml_file=False, chdir_out=False):
|
||||
logging.debug('Running '+self.test_name)
|
||||
# Change the command to be local and add the board and output arguments
|
||||
cmd = [COVERAGE_SCRIPT, 'run', '-a']
|
||||
if chdir_out:
|
||||
cmd.append('--rcfile=../../.coveragerc')
|
||||
os.environ['COVERAGE_FILE'] = os.path.join(os.getcwd(), '.coverage')
|
||||
cmd.append(os.path.abspath(os.path.dirname(os.path.abspath(__file__))+'/../../src/kiplot'))
|
||||
cmd.append('-vv')
|
||||
cmd = cmd+['-b', filename if filename else self.board_file]
|
||||
cmd = cmd+['-c', self.yaml_file]
|
||||
cmd = cmd+['-d', self.output_dir]
|
||||
if not no_out_dir:
|
||||
cmd = cmd+['-b', filename if filename else self.board_file]
|
||||
if not no_yaml_file:
|
||||
cmd = cmd+['-c', self.yaml_file]
|
||||
if not no_out_dir:
|
||||
cmd = cmd+['-d', self.output_dir]
|
||||
if extra is not None:
|
||||
cmd = cmd+extra
|
||||
logging.debug(cmd)
|
||||
|
|
@ -169,7 +176,13 @@ class TestContext(object):
|
|||
f_out = os.open(out_filename, os.O_RDWR | os.O_CREAT)
|
||||
f_err = os.open(err_filename, os.O_RDWR | os.O_CREAT)
|
||||
# Run the process
|
||||
if chdir_out:
|
||||
cwd = os.getcwd()
|
||||
os.chdir(self.output_dir)
|
||||
process = subprocess.Popen(cmd, stdout=f_out, stderr=f_err)
|
||||
if chdir_out:
|
||||
os.chdir(cwd)
|
||||
del os.environ['COVERAGE_FILE']
|
||||
ret_code = process.wait()
|
||||
logging.debug('ret_code '+str(ret_code))
|
||||
if use_a_tty:
|
||||
|
|
|
|||
Loading…
Reference in New Issue