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
This commit is contained in:
Salvador E. Tropea 2020-07-09 12:50:27 -03:00
parent 587ef177b3
commit f72ff3f441
10 changed files with 72 additions and 19 deletions

View File

@ -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.

View File

@ -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

View File

@ -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):

View File

@ -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

View File

@ -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())

View File

@ -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)

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -3,5 +3,5 @@ kiplot:
version: 1
preflight:
run_drc: true
run_erc: true