From 5883b1a61627902b5d3da982944358d4b11a6b0d Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Tue, 26 May 2020 14:22:58 -0300 Subject: [PATCH] Added test for command line -q (quite) --- tests/test_plot/test_position.py | 14 ++++++++++---- tests/utils/context.py | 5 +++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/test_plot/test_position.py b/tests/test_plot/test_position.py index c0b99c52..82b6b040 100644 --- a/tests/test_plot/test_position.py +++ b/tests/test_plot/test_position.py @@ -7,7 +7,10 @@ We test (both CSV and ASCII): - Unified file, mm, only SMD - Unified file, mm, not only SMD - Separated files, inches, only SMD -- Also test a case without 'comment' field +- Also test a case: + - without 'comment' field + - with coloured logs + - in quiet mode For debug information use: pytest-3 --log-cli-level debug @@ -100,22 +103,25 @@ def test_3Rs_position_inches(): def test_3Rs_position_csv(): - """ Also test a case without comment """ + """ Also test a case without comment and color logs """ ctx = context.TestContext('3Rs_position_csv', '3Rs', 'simple_position_csv', POS_DIR) - ctx.run() + ctx.run(use_a_tty=True) pos_top = ctx.get_pos_top_csv_filename() pos_bot = ctx.get_pos_bot_csv_filename() ctx.expect_out_file(pos_top) ctx.expect_out_file(pos_bot) expect_position(ctx, pos_top, ['R1'], ['R2', 'R3'], csv=True) expect_position(ctx, pos_bot, ['R2'], ['R1', 'R3'], csv=True) + assert ctx.search_err(r"\[36;1mDEBUG:") is not None ctx.clean_up() def test_3Rs_position_unified_csv(): + """ Also test the quiet mode """ ctx = context.TestContext('3Rs_position_unified_csv', '3Rs', 'simple_position_unified_csv', POS_DIR) - ctx.run() + ctx.run(no_verbose=True, extra=['-q']) expect_position(ctx, ctx.get_pos_both_csv_filename(), ['R1', 'R2'], ['R3'], csv=True) + assert os.path.getsize(ctx.get_out_path('error.txt')) == 0 ctx.clean_up() diff --git a/tests/utils/context.py b/tests/utils/context.py index 6e73573e..520cb1d1 100644 --- a/tests/utils/context.py +++ b/tests/utils/context.py @@ -146,7 +146,7 @@ class TestContext(object): f.write('Dummy file\n') def run(self, ret_val=None, extra=None, use_a_tty=False, filename=None, no_out_dir=False, no_board_file=False, - no_yaml_file=False, chdir_out=False): + no_yaml_file=False, chdir_out=False, no_verbose=False): logging.debug('Running '+self.test_name) # Change the command to be local and add the board and output arguments cmd = [COVERAGE_SCRIPT, 'run', '-a'] @@ -154,7 +154,8 @@ class TestContext(object): cmd.append('--rcfile=../../.coveragerc') os.environ['COVERAGE_FILE'] = os.path.join(os.getcwd(), '.coverage') cmd.append(os.path.abspath(os.path.dirname(os.path.abspath(__file__))+'/../../src/kiplot')) - cmd.append('-vv') + if not no_verbose: + cmd.append('-vv') if not no_board_file: cmd = cmd+['-b', filename if filename else self.board_file] if not no_yaml_file: