From f72ff3f44192e357fb111c49eda21226c19d10c3 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Thu, 9 Jul 2020 12:50:27 -0300 Subject: [PATCH] Extra dot in step.metric_units docstring. Remove dead code in check_eeschema_do() Fixed the way we read scale stuff from a PCB Added special checks for check_script and check_version --- README.md | 2 +- docs/samples/generic_plot.kiplot.yaml | 2 +- kiplot/kiplot.py | 6 +-- kiplot/out_hpgl.py | 8 ++-- kiplot/out_kibom.py | 3 +- kiplot/out_pdf_pcb_print.py | 2 +- kiplot/out_ps.py | 7 ++-- tests/test_plot/test_misc.py | 3 +- tests/test_plot/test_script_checks.py | 56 +++++++++++++++++++++++++ tests/yaml_samples/pre_skip.kiplot.yaml | 2 +- 10 files changed, 72 insertions(+), 19 deletions(-) create mode 100644 tests/test_plot/test_script_checks.py diff --git a/README.md b/README.md index 51d0d4f9..af23355d 100644 --- a/README.md +++ b/README.md @@ -609,7 +609,7 @@ Next time you need this list just use an alias, like this: - `name`: [string=''] Used to identify this particular output definition. - `options`: [dict] Options for the `step` output. * Valid keys: - - `metric_units`: [boolean=true] use metric units instead of inches.. + - `metric_units`: [boolean=true] use metric units instead of inches. - `min_distance`: [number=-1] the minimum distance between points to treat them as separate ones (-1 is KiCad default: 0.01 mm). - `no_virtual`: [boolean=false] used to exclude 3D models for components with 'virtual' attribute. - `origin`: [string='grid'] determines the coordinates origin. Using grid the coordinates are the same as you have in the design sheet. diff --git a/docs/samples/generic_plot.kiplot.yaml b/docs/samples/generic_plot.kiplot.yaml index bd2ab973..c1eeded5 100644 --- a/docs/samples/generic_plot.kiplot.yaml +++ b/docs/samples/generic_plot.kiplot.yaml @@ -387,7 +387,7 @@ outputs: type: 'step' dir: 'Example/step_dir' options: - # [boolean=true] use metric units instead of inches. + # [boolean=true] use metric units instead of inches metric_units: true # [number=-1] the minimum distance between points to treat them as separate ones (-1 is KiCad default: 0.01 mm) min_distance: -1 diff --git a/kiplot/kiplot.py b/kiplot/kiplot.py index 5ef48013..299e7202 100644 --- a/kiplot/kiplot.py +++ b/kiplot/kiplot.py @@ -12,8 +12,7 @@ from distutils.version import StrictVersion from importlib.util import (spec_from_file_location, module_from_spec) from .gs import (GS) -from .misc import (PLOT_ERROR, NO_PCBNEW_MODULE, MISSING_TOOL, CMD_EESCHEMA_DO, URL_EESCHEMA_DO, NO_SCH_FILE, CORRUPTED_PCB, - EXIT_BAD_ARGS) +from .misc import (PLOT_ERROR, NO_PCBNEW_MODULE, MISSING_TOOL, CMD_EESCHEMA_DO, URL_EESCHEMA_DO, CORRUPTED_PCB, EXIT_BAD_ARGS) from .error import (PlotError, KiPlotConfigurationError, config_error) from .pre_base import BasePreFlight from . import log @@ -89,9 +88,6 @@ def check_script(cmd, url, version=None): def check_eeschema_do(): check_script(CMD_EESCHEMA_DO, URL_EESCHEMA_DO, '1.4.0') - if not GS.sch_file: - logger.error('Missing schematic file') - exit(NO_SCH_FILE) def load_board(pcb_file=None): diff --git a/kiplot/out_hpgl.py b/kiplot/out_hpgl.py index 79914a2c..6fe884ac 100644 --- a/kiplot/out_hpgl.py +++ b/kiplot/out_hpgl.py @@ -3,6 +3,7 @@ from kiplot.misc import AUTO_SCALE from kiplot.out_any_layer import AnyLayer from kiplot.drill_marks import DrillMarks from kiplot.macros import macros, document, output_class # noqa: F401 +from . import log class HPGLOptions(DrillMarks): @@ -46,10 +47,9 @@ class HPGLOptions(DrillMarks): self.sketch_plot = po.GetPlotMode() == SKETCH self.mirror_plot = po.GetMirror() # scaleselection - if po.GetAutoScale(): - self.scaling = AUTO_SCALE - else: - self.scaling = po.GetScale() + sel = po.GetScaleSelection() + sel = sel if sel < 0 or sel > 4 else 4 + self.scaling = (AUTO_SCALE, 1.0, 1.5, 2.0, 3.0)[sel] @output_class diff --git a/kiplot/out_kibom.py b/kiplot/out_kibom.py index b1edd0ee..b8067dcb 100644 --- a/kiplot/out_kibom.py +++ b/kiplot/out_kibom.py @@ -54,7 +54,8 @@ class KiBoMOptions(BaseOptions): exit(BOM_ERROR) prj = os.path.basename(prj) for f in glob(os.path.join(output_dir, prj)+'*.tmp'): - os.remove(f) + # I'm not sure when these files are left, but they are annoying + os.remove(f) # pragma: no cover logger.debug('Output from command:\n'+cmd_output.decode()) diff --git a/kiplot/out_pdf_pcb_print.py b/kiplot/out_pdf_pcb_print.py index 41d8b88f..b3481779 100644 --- a/kiplot/out_pdf_pcb_print.py +++ b/kiplot/out_pdf_pcb_print.py @@ -40,7 +40,7 @@ class PDF_Pcb_PrintOptions(BaseOptions): # Execute it logger.debug('Executing: '+str(cmd)) ret = call(cmd) - if ret: # pragma: no cover + if ret: # pragma: no cover # We check all the arguments, we even load the PCB # A fail here isn't easy to reproduce logger.error(CMD_PCBNEW_PRINT_LAYERS+' returned %d', ret) diff --git a/kiplot/out_ps.py b/kiplot/out_ps.py index 50382e53..5c9f46d0 100644 --- a/kiplot/out_ps.py +++ b/kiplot/out_ps.py @@ -59,10 +59,9 @@ class PSOptions(DrillMarks): self.negative_plot = po.GetNegative() self.mirror_plot = po.GetMirror() # scaleselection - if po.GetAutoScale(): - self.scaling = AUTO_SCALE - else: - self.scaling = po.GetScale() + sel = po.GetScaleSelection() + sel = sel if sel < 0 or sel > 4 else 4 + self.scaling = (AUTO_SCALE, 1.0, 1.5, 2.0, 3.0)[sel] @output_class diff --git a/tests/test_plot/test_misc.py b/tests/test_plot/test_misc.py index 3e498079..824c64b4 100644 --- a/tests/test_plot/test_misc.py +++ b/tests/test_plot/test_misc.py @@ -337,7 +337,8 @@ def test_help_output(): def test_help_output_unk(): ctx = context.TestContext('HelpOutputUnk', '3Rs', 'pre_and_position', POS_DIR) - ctx.run(EXIT_BAD_ARGS, extra=['--help-output', 'bogus'], no_verbose=True, no_out_dir=True, no_yaml_file=True, no_board_file=True) + ctx.run(EXIT_BAD_ARGS, extra=['--help-output', 'bogus'], no_verbose=True, no_out_dir=True, no_yaml_file=True, + no_board_file=True) assert ctx.search_err('Unknown output type') ctx.clean_up() diff --git a/tests/test_plot/test_script_checks.py b/tests/test_plot/test_script_checks.py new file mode 100644 index 00000000..f6e60b64 --- /dev/null +++ b/tests/test_plot/test_script_checks.py @@ -0,0 +1,56 @@ +""" +Tests the checks for utilities + +For debug information use: +pytest-3 --log-cli-level debug + +""" + +import os +import sys +import pytest +import coverage +prev_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +if prev_dir not in sys.path: + sys.path.insert(0, prev_dir) +from kiplot.misc import (MISSING_TOOL, CMD_EESCHEMA_DO) +from kiplot.kiplot import (check_script, check_version) + + +cov = coverage.Coverage() + + +def test_check_script(caplog): + cov.load() + cov.start() + with pytest.raises(SystemExit) as pytest_wrapped_e: + check_script('bogus', '') + cov.stop() + cov.save() + assert pytest_wrapped_e.type == SystemExit + assert pytest_wrapped_e.value.code == MISSING_TOOL + assert "No `bogus` command found" in caplog.text + + +def test_check_version_1(caplog): + cov.load() + cov.start() + with pytest.raises(SystemExit) as pytest_wrapped_e: + check_version('ls', '1.1.1') + cov.stop() + cov.save() + assert pytest_wrapped_e.type == SystemExit + assert pytest_wrapped_e.value.code == MISSING_TOOL + assert "Unable to determine ls version" in caplog.text + + +def test_check_version_2(caplog): + cov.load() + cov.start() + with pytest.raises(SystemExit) as pytest_wrapped_e: + check_version(CMD_EESCHEMA_DO, '20.1.1') + cov.stop() + cov.save() + assert pytest_wrapped_e.type == SystemExit + assert pytest_wrapped_e.value.code == MISSING_TOOL + assert "Wrong version for `eeschema_do`" in caplog.text diff --git a/tests/yaml_samples/pre_skip.kiplot.yaml b/tests/yaml_samples/pre_skip.kiplot.yaml index b36d4668..19073c6c 100644 --- a/tests/yaml_samples/pre_skip.kiplot.yaml +++ b/tests/yaml_samples/pre_skip.kiplot.yaml @@ -3,5 +3,5 @@ kiplot: version: 1 preflight: - run_drc: true + run_erc: true