Added --example basic tests
Also added support for output directory to --example
This commit is contained in:
parent
4ae54f3ded
commit
d926a5419e
|
|
@ -510,7 +510,7 @@ Usage:
|
|||
kiplot [-b BOARD] [-e SCHEMA] [-c CONFIG] [-d OUT_DIR] [-s PRE]
|
||||
[-q | -v...] [-i] [TARGET...]
|
||||
kiplot [-c PLOT_CONFIG] --list
|
||||
kiplot [-b BOARD] --example
|
||||
kiplot [-b BOARD] [-d OUT_DIR] --example
|
||||
kiplot --help-list-outputs
|
||||
kiplot --help-output=HELP_OUTPUT
|
||||
kiplot --help-outputs
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ Usage:
|
|||
kiplot [-b BOARD] [-e SCHEMA] [-c CONFIG] [-d OUT_DIR] [-s PRE]
|
||||
[-q | -v...] [-i] [TARGET...]
|
||||
kiplot [-c PLOT_CONFIG] --list
|
||||
kiplot [-b BOARD] --example
|
||||
kiplot [-b BOARD] [-d OUT_DIR] --example
|
||||
kiplot --help-list-outputs
|
||||
kiplot --help-output=HELP_OUTPUT
|
||||
kiplot --help-outputs
|
||||
|
|
@ -172,7 +172,7 @@ def main():
|
|||
sys.exit(0)
|
||||
if args.example:
|
||||
check_board_file(args.board_file)
|
||||
create_example(args.board_file)
|
||||
create_example(args.board_file, GS.out_dir)
|
||||
sys.exit(0)
|
||||
|
||||
# Determine the YAML file
|
||||
|
|
|
|||
|
|
@ -303,12 +303,15 @@ def print_preflights_help():
|
|||
print('- {}: {}.'.format(n, help.rstrip()))
|
||||
|
||||
|
||||
def create_example(pcb_file):
|
||||
if os.path.isfile(EXAMPLE_CFG):
|
||||
logger.error(EXAMPLE_CFG+" already exists, won't overwrite")
|
||||
def create_example(pcb_file, out_dir):
|
||||
if not os.path.exists(out_dir):
|
||||
os.makedirs(out_dir)
|
||||
fname = os.path.join(out_dir, EXAMPLE_CFG)
|
||||
if os.path.isfile(fname):
|
||||
logger.error(fname+" already exists, won't overwrite")
|
||||
exit(WONT_OVERWRITE)
|
||||
with open(EXAMPLE_CFG, 'w') as f:
|
||||
logger.info('Creating {} example configuration'.format(EXAMPLE_CFG))
|
||||
with open(fname, 'w') as f:
|
||||
logger.info('Creating {} example configuration'.format(fname))
|
||||
f.write('kiplot:\n version: 1\n')
|
||||
# Preflights
|
||||
f.write('\npreflight:\n')
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@ Tests miscellaneous stuff.
|
|||
- Guess the SCH and YAML
|
||||
- Guess the SCH and YAML when more than one is present
|
||||
- --list
|
||||
- Create example
|
||||
- with PCB
|
||||
- already exists
|
||||
|
||||
For debug information use:
|
||||
pytest-3 --log-cli-level debug
|
||||
|
|
@ -35,7 +38,7 @@ from utils import context
|
|||
prev_dir = os.path.dirname(prev_dir)
|
||||
if prev_dir not in sys.path:
|
||||
sys.path.insert(0, prev_dir)
|
||||
from kiplot.misc import (EXIT_BAD_ARGS, EXIT_BAD_CONFIG, NO_PCB_FILE, NO_SCH_FILE)
|
||||
from kiplot.misc import (EXIT_BAD_ARGS, EXIT_BAD_CONFIG, NO_PCB_FILE, NO_SCH_FILE, EXAMPLE_CFG, WONT_OVERWRITE)
|
||||
|
||||
|
||||
POS_DIR = 'positiondir'
|
||||
|
|
@ -334,3 +337,29 @@ def test_help_preflights():
|
|||
ctx.run(extra=['--help-preflights'], no_verbose=True, no_out_dir=True, no_yaml_file=True, no_board_file=True)
|
||||
assert ctx.search_out('Supported preflight options')
|
||||
ctx.clean_up()
|
||||
|
||||
|
||||
def test_example_1():
|
||||
ctx = context.TestContext('Example1', '3Rs', 'pre_and_position', '')
|
||||
ctx.run(extra=['--example'], no_verbose=True, no_yaml_file=True, no_board_file=True)
|
||||
assert ctx.expect_out_file(EXAMPLE_CFG)
|
||||
os.remove(ctx.get_out_path(EXAMPLE_CFG))
|
||||
ctx.clean_up()
|
||||
|
||||
|
||||
def test_example_2():
|
||||
ctx = context.TestContext('Example2', 'good-project', 'pre_and_position', '')
|
||||
ctx.run(extra=['--example'], no_verbose=True, no_yaml_file=True)
|
||||
assert ctx.expect_out_file(EXAMPLE_CFG)
|
||||
ctx.search_in_file(EXAMPLE_CFG, ['GND.Cu'])
|
||||
os.remove(ctx.get_out_path(EXAMPLE_CFG))
|
||||
ctx.clean_up()
|
||||
|
||||
|
||||
def test_example_3():
|
||||
ctx = context.TestContext('Example3', 'good-project', 'pre_and_position', '')
|
||||
ctx.run(extra=['--example'], no_verbose=True, no_yaml_file=True)
|
||||
assert ctx.expect_out_file(EXAMPLE_CFG)
|
||||
ctx.run(WONT_OVERWRITE, extra=['--example'], no_verbose=True, no_yaml_file=True)
|
||||
os.remove(ctx.get_out_path(EXAMPLE_CFG))
|
||||
ctx.clean_up()
|
||||
|
|
|
|||
Loading…
Reference in New Issue