diff --git a/kibot/out_position.py b/kibot/out_position.py index 71df3698..3de348e9 100644 --- a/kibot/out_position.py +++ b/kibot/out_position.py @@ -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') diff --git a/tests/test_plot/test_position.py b/tests/test_plot/test_position.py index 4927208b..59df90b2 100644 --- a/tests/test_plot/test_position.py +++ b/tests/test_plot/test_position.py @@ -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() diff --git a/tests/yaml_samples/error_position_same_name.kibot.yaml b/tests/yaml_samples/error_position_same_name.kibot.yaml new file mode 100644 index 00000000..8fdeba00 --- /dev/null +++ b/tests/yaml_samples/error_position_same_name.kibot.yaml @@ -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