Skip to content

Commit

Permalink
Added a unique error level for wrong layer names.
Browse files Browse the repository at this point in the history
Added sanity check for Inner.N layers.
Added 3 tests.
  • Loading branch information
set-soft committed May 8, 2020
1 parent b3b4bc2 commit c685f7d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
1 change: 1 addition & 0 deletions kicad_auto/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
KICAD_CFG_PRESENT = 3
NO_PCB = 4
PCBNEW_CFG_PRESENT = 5
WRONG_LAYER_NAME = 6
# Wait 25 s to pcbnew/eeschema window to be present
WAIT_START = 25

Expand Down
12 changes: 8 additions & 4 deletions src/pcbnew_do
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sys.path.insert(0, os.path.dirname(script_dir))
from kicad_auto import log
log.set_domain(os.path.splitext(os.path.basename(__file__))[0])
from kicad_auto import file_util
from kicad_auto.misc import (REC_W, REC_H, __version__, NO_PCB, PCBNEW_CFG_PRESENT, WAIT_START)
from kicad_auto.misc import (REC_W, REC_H, __version__, NO_PCB, PCBNEW_CFG_PRESENT, WAIT_START, WRONG_LAYER_NAME)
from kicad_auto.ui_automation import (
PopenContext,
xdotool,
Expand Down Expand Up @@ -364,13 +364,17 @@ if __name__ == '__main__':
m = re.match(r"^Inner\.([0-9]+)$", layer)
if not m:
logger.error('Malformed inner layer name: '+layer+', use Inner.N')
sys.exit(1)
used_layers[int(m.group(1))] = 1
sys.exit(WRONG_LAYER_NAME)
layer_n = int(m.group(1))
if layer_n > 49 or layer_names[layer_n] == '-':
logger.error(layer+" isn't a valid layer")
sys.exit(WRONG_LAYER_NAME)
used_layers[layer_n] = 1
else:
used_layers[layer_names.index(layer)] = 1
except ValueError:
logger.error('Unknown layer '+layer)
sys.exit(1)
sys.exit(WRONG_LAYER_NAME)
# List all posible layers, indicating which ones are requested
for x in range(0, 50):
text_file.write('PlotLayer_%d=%d\n' % (x, used_layers[x]))
Expand Down
36 changes: 35 additions & 1 deletion tests/pcbnew/test_print_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
import sys
# Look for the 'utils' module from where the script is running
script_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.dirname(script_dir))
prev_dir = os.path.dirname(script_dir)
sys.path.insert(0, prev_dir)
# Utils import
from utils import context
sys.path.insert(0, os.path.dirname(prev_dir))
from kicad_auto.misc import (WRONG_LAYER_NAME)


PROG = 'pcbnew_do'
DEFAULT = 'printed.pdf'
Expand Down Expand Up @@ -64,3 +68,33 @@ def test_print_pcb_good_dwg_dism():
ctx.compare_image(pdf)
assert ctx.search_err(r"Dismiss pcbnew already running") is not None
ctx.clean_up()


def test_wrong_layer_name_kiplot():
ctx = context.TestContext('Wrong_Inner', 'good-project')
cmd = [PROG, 'export']
layers = ['F.Cu', 'Inner_1']
ctx.run(cmd, WRONG_LAYER_NAME, extra=layers)
m = ctx.search_err(r'Malformed inner layer name')
assert m is not None
ctx.clean_up()


def test_wrong_layer_big():
ctx = context.TestContext('Wrong_Inner_Big', 'good-project')
cmd = [PROG, 'export']
layers = ['F.Cu', 'Inner.8']
ctx.run(cmd, WRONG_LAYER_NAME, extra=layers)
m = ctx.search_err(r"Inner.8 isn't a valid layer")
assert m is not None
ctx.clean_up()


def test_wrong_layer_bogus():
ctx = context.TestContext('Wrong_Inner_Name', 'good-project')
cmd = [PROG, 'export']
layers = ['F.Cu', 'GND_Cu']
ctx.run(cmd, WRONG_LAYER_NAME, extra=layers)
m = ctx.search_err(r"Unknown layer GND_Cu")
assert m is not None
ctx.clean_up()

0 comments on commit c685f7d

Please sign in to comment.