[Position] Added an error message for wrong file names
- If a user asks for separated files and doesn't use %i to differentiate the names now we inform it as an error. Related to #222
This commit is contained in:
parent
45285c4807
commit
ba7bebd980
|
|
@ -31,6 +31,12 @@ def _ref_key(ref_str):
|
|||
return [pre, 0 if suf == '?' else int(suf)]
|
||||
|
||||
|
||||
def check_names(top, bot):
|
||||
if top == bot:
|
||||
raise KiPlotConfigurationError("Asking for two separated files, but both with the same name.\n"
|
||||
"Try using %i in the name.")
|
||||
|
||||
|
||||
class PosColumns(Optionable):
|
||||
""" Which columns we want and its names """
|
||||
def __init__(self):
|
||||
|
|
@ -98,8 +104,11 @@ class PositionOptions(VariantOptions):
|
|||
botf = None
|
||||
bothf = None
|
||||
if self.separate_files_for_front_and_back:
|
||||
topf = open(self.expand_filename(output_dir, self.output, 'top_pos', 'pos'), 'w')
|
||||
botf = open(self.expand_filename(output_dir, self.output, 'bottom_pos', 'pos'), 'w')
|
||||
topf_name = self.expand_filename(output_dir, self.output, 'top_pos', 'pos')
|
||||
botf_name = self.expand_filename(output_dir, self.output, 'bottom_pos', 'pos')
|
||||
check_names(topf_name, botf_name)
|
||||
topf = open(topf_name, 'w')
|
||||
botf = open(botf_name, 'w')
|
||||
else:
|
||||
bothf = open(self.expand_filename(output_dir, self.output, 'both_pos', 'pos'), 'w')
|
||||
|
||||
|
|
@ -156,8 +165,11 @@ class PositionOptions(VariantOptions):
|
|||
botf = None
|
||||
bothf = None
|
||||
if self.separate_files_for_front_and_back:
|
||||
topf = open(self.expand_filename(output_dir, self.output, 'top_pos', 'csv'), 'w')
|
||||
botf = open(self.expand_filename(output_dir, self.output, 'bottom_pos', 'csv'), 'w')
|
||||
topf_name = self.expand_filename(output_dir, self.output, 'top_pos', 'csv')
|
||||
botf_name = self.expand_filename(output_dir, self.output, 'bottom_pos', 'csv')
|
||||
check_names(topf_name, botf_name)
|
||||
topf = open(topf_name, 'w')
|
||||
botf = open(botf_name, 'w')
|
||||
else:
|
||||
bothf = open(self.expand_filename(output_dir, self.output, 'both_pos', 'csv'), 'w')
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ pytest-3 --log-cli-level debug
|
|||
"""
|
||||
import os
|
||||
import logging
|
||||
from kibot.misc import EXIT_BAD_CONFIG
|
||||
from . import context
|
||||
|
||||
POS_DIR = 'positiondir'
|
||||
|
|
@ -271,3 +272,10 @@ def test_position_rot_bottom(test_dir):
|
|||
ctx.expect_out_file(pos_bot)
|
||||
expect_position(ctx, pos_bot, ['U1'], neg_x=True)
|
||||
ctx.clean_up()
|
||||
|
||||
|
||||
def test_position_error_same_name(test_dir):
|
||||
ctx = context.TestContext(test_dir, '3Rs', 'error_position_same_name', POS_DIR)
|
||||
ctx.run(EXIT_BAD_CONFIG)
|
||||
ctx.search_err(r"(.*)but both with the same name")
|
||||
ctx.clean_up()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
# Example KiBot config file for a basic 2-layer board
|
||||
kibot:
|
||||
version: 1
|
||||
|
||||
outputs:
|
||||
|
||||
- name: 'position'
|
||||
type: position
|
||||
dir: positiondir
|
||||
options:
|
||||
output: '%f.%x'
|
||||
format: CSV # CSV or ASCII format
|
||||
units: millimeters # millimeters or inches
|
||||
separate_files_for_front_and_back: true
|
||||
only_smd: true
|
||||
Loading…
Reference in New Issue