From 587ef177b31d77892fbe34794451b040c936c3dc Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Thu, 9 Jul 2020 09:54:25 -0300 Subject: [PATCH] Added test for corrupted PCB, skip a preflight that isn't in use and output plugin --- kiplot/kiplot.py | 2 +- kiplot/out_step.py | 2 +- tests/.config/kiplot/plugins/out_test.py | 28 +++++++++++++++++++ tests/test_plot/test_misc.py | 34 +++++++++++++++++++++++- tests/yaml_samples/pre_skip.kiplot.yaml | 7 +++++ 5 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 tests/.config/kiplot/plugins/out_test.py create mode 100644 tests/yaml_samples/pre_skip.kiplot.yaml diff --git a/kiplot/kiplot.py b/kiplot/kiplot.py index 8a777ceb..5ef48013 100644 --- a/kiplot/kiplot.py +++ b/kiplot/kiplot.py @@ -104,7 +104,7 @@ def load_board(pcb_file=None): pcbnew.ZONE_FILLER(board).Fill(board.Zones()) GS.board = board except OSError as e: - logger.error('Error loading PCB file. Currupted?') + logger.error('Error loading PCB file. Corrupted?') logger.error(e) exit(CORRUPTED_PCB) assert board is not None diff --git a/kiplot/out_step.py b/kiplot/out_step.py index ba7b48de..fc805371 100644 --- a/kiplot/out_step.py +++ b/kiplot/out_step.py @@ -16,7 +16,7 @@ class STEPOptions(BaseOptions): super().__init__() with document: self.metric_units = True - """ use metric units instead of inches. """ + """ use metric units instead of inches """ self._origin = 'grid' """ determines the coordinates origin. Using grid the coordinates are the same as you have in the design sheet. The drill option uses the auxiliar reference defined by the user. diff --git a/tests/.config/kiplot/plugins/out_test.py b/tests/.config/kiplot/plugins/out_test.py new file mode 100644 index 00000000..b1b39ef9 --- /dev/null +++ b/tests/.config/kiplot/plugins/out_test.py @@ -0,0 +1,28 @@ +from .optionable import BaseOptions +from kiplot.macros import macros, document, output_class # noqa: F401 +from . import log + +logger = log.get_logger(__name__) + + +class TestOptions(BaseOptions): + def __init__(self): + super().__init__() + with document: + self.foo = True + """ chocolate """ + self.bar = 'nope' + """ nothing """ # pragma: no cover + + +@output_class +class Test(BaseOutput): # noqa: F821 + """ Test for plugin + A loadable output. + Nothing useful, just a test. """ + def __init__(self): + super().__init__() + logger.debug('Creating a test') + with document: + self.options = TestOptions + """ [dict] Options for the `test` output """ # pragma: no cover diff --git a/tests/test_plot/test_misc.py b/tests/test_plot/test_misc.py index a358a837..3e498079 100644 --- a/tests/test_plot/test_misc.py +++ b/tests/test_plot/test_misc.py @@ -22,6 +22,7 @@ Tests miscellaneous stuff. - with PCB - already exists - Copying +- Load plugin For debug information use: pytest-3 --log-cli-level debug @@ -30,6 +31,7 @@ pytest-3 --log-cli-level debug import os import sys import shutil +import logging # Look for the 'utils' module from where the script is running prev_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) if prev_dir not in sys.path: @@ -39,7 +41,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, EXAMPLE_CFG, WONT_OVERWRITE) +from kiplot.misc import (EXIT_BAD_ARGS, EXIT_BAD_CONFIG, NO_PCB_FILE, NO_SCH_FILE, EXAMPLE_CFG, WONT_OVERWRITE, CORRUPTED_PCB) POS_DIR = 'positiondir' @@ -93,6 +95,14 @@ def test_skip_pre_and_outputs_4(): ctx.clean_up() +def test_skip_pre_and_outputs_5(): + prj = 'simple_2layer' + ctx = context.TestContext('SkipPreAndPos4', prj, 'pre_skip', POS_DIR) + ctx.run(extra=['-s', 'run_erc,run_drc']) + assert ctx.search_err('no need to skip') + ctx.clean_up() + + def test_unknown_out(): prj = 'simple_2layer' ctx = context.TestContext('UnknownOut', prj, 'unknown_out', POS_DIR) @@ -332,6 +342,20 @@ def test_help_output_unk(): ctx.clean_up() +def test_help_output_plugin(): + ctx = context.TestContext('HelpOutputPlugin', '3Rs', 'pre_and_position', POS_DIR) + home = os.environ['HOME'] + os.environ['HOME'] = os.path.join(ctx.get_board_dir(), '..') + logging.debug('HOME='+os.environ['HOME']) + ctx.run(extra=['--help-output', 'test'], no_verbose=True, no_out_dir=True, no_yaml_file=True, no_board_file=True) + os.environ['HOME'] = home + assert ctx.search_out('Test for plugin') + assert ctx.search_out('Type: .?test.?') + assert ctx.search_out('nothing') + assert ctx.search_out('chocolate') + ctx.clean_up() + + def test_help_outputs(): ctx = context.TestContext('HelpOutputs', '3Rs', 'pre_and_position', POS_DIR) ctx.run(extra=['--help-outputs'], no_verbose=True, no_out_dir=True, no_yaml_file=True, no_board_file=True) @@ -400,3 +424,11 @@ def test_example_6(): ctx.run(EXIT_BAD_ARGS, extra=['--example', '-p'], no_verbose=True, no_yaml_file=True, no_board_file=True) assert ctx.search_err('no PCB specified') ctx.clean_up() + + +def test_corrupted_pcb(): + prj = 'bom_no_xml' + ctx = context.TestContext('Corrupted', prj, 'print_pcb', '') + ctx.run(CORRUPTED_PCB) + assert ctx.search_err('Error loading PCB file') + ctx.clean_up() diff --git a/tests/yaml_samples/pre_skip.kiplot.yaml b/tests/yaml_samples/pre_skip.kiplot.yaml new file mode 100644 index 00000000..b36d4668 --- /dev/null +++ b/tests/yaml_samples/pre_skip.kiplot.yaml @@ -0,0 +1,7 @@ +# Example KiPlot config file +kiplot: + version: 1 + +preflight: + run_drc: true +