From c637dd50c6732761cec57ce3f4a3476d73e4637a Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Tue, 9 Jan 2024 08:35:40 -0300 Subject: [PATCH] [Tests][Added] --list --no-names --- tests/test_plot/test_misc.py | 17 +++++++++++------ tests/utils/context.py | 26 +++++++++++++------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/tests/test_plot/test_misc.py b/tests/test_plot/test_misc.py index 0f4ad184..57941f99 100644 --- a/tests/test_plot/test_misc.py +++ b/tests/test_plot/test_misc.py @@ -273,14 +273,19 @@ def test_auto_pcb_and_cfg_5(test_dir): ctx.clean_up() -def test_list(test_dir): +def test_list_full(test_dir): ctx = context.TestContext(test_dir, '3Rs', 'pre_and_position') ctx.run(extra=['--list'], no_verbose=True, no_out_dir=True) - assert ctx.search_out('run_erc: True') - assert ctx.search_out('run_drc: True') - assert ctx.search_out('update_xml: True') - assert ctx.search_out(r'Pick and place file.? \(position\) \[position\]') - assert ctx.search_out(r'Pick and place file.? \(pos_ascii\) \[position\]') + ctx.search_out(['run_erc: True', 'run_drc: True', 'update_xml: True', r'Pick and place file.? \(position\) \[position\]', + r'Pick and place file.? \(pos_ascii\) \[position\]']) + ctx.clean_up() + + +def test_list_only_names(test_dir): + ctx = context.TestContext(test_dir, '3Rs', 'pre_and_position') + ctx.run(extra=['--list', '--only-names'], no_verbose=True, no_out_dir=True) + ctx.search_out(['position', 'pos_ascii']) + ctx.search_out('Pick and place file', invert=True) ctx.clean_up() diff --git a/tests/utils/context.py b/tests/utils/context.py index 84b4503d..102845e8 100644 --- a/tests/utils/context.py +++ b/tests/utils/context.py @@ -444,34 +444,34 @@ class TestContext(object): else: del os.environ['LANG'] - def search_out(self, text): - m = re.search(text, self.out, re.MULTILINE) - assert m is not None, text - logging.debug('output match: `{}` OK'.format(text)) - return m - - def search_err(self, text, invert=False): + def _search_txt(self, text, msgs, where, invert=False): if isinstance(text, list): res = [] for t in text: - m = re.search(t, self.err, re.MULTILINE) + m = re.search(t, msgs, re.MULTILINE) if invert: assert m is None, t - logging.debug('error no match: `{}` OK'.format(t)) + logging.debug(f'{where} no match: `{t}` OK') else: assert m is not None, t - logging.debug('error match: `{}` (`{}`) OK'.format(t, m.group(0))) + logging.debug(f'{where} match: `{t}` (`{m.group(0)}`) OK') res.append(m) return res - m = re.search(text, self.err, re.MULTILINE) + m = re.search(text, msgs, re.MULTILINE) if invert: assert m is None, text - logging.debug('error no match: `{}` OK'.format(text)) + logging.debug(f'{where} no match: `{text}` OK') else: assert m is not None, text - logging.debug('error match: `{}` (`{}`) OK'.format(text, m.group(0))) + logging.debug(f'{where} match: `{text}` (`{m.group(0)}`) OK') return m + def search_out(self, text, invert=False): + return self._search_txt(text, self.out, 'output', invert) + + def search_err(self, text, invert=False): + return self._search_txt(text, self.err, 'error', invert) + def search_in_file(self, file, texts, sub=False): logging.debug('Searching in "'+file+'" output') with open(self.get_out_path(file, sub=sub)) as f: