From 4f75b36ef91775bcf939278b5bf68ce87815dba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Madon?= <mael.madon@irit.fr> Date: Fri, 2 Jun 2023 18:19:39 +0200 Subject: [PATCH] test: adding the necessary to test the expected_behavio_logs. Some tests now broke. See MR sh fichiers_cpp.sh --- test/conftest.py | 10 +++++++--- test/helper.py | 7 +++++-- test/test_users.py | 3 +++ test/test_zexpected_output.py | 11 ++++++----- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index 196895b..b80d588 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -48,13 +48,17 @@ def pytest_generate_tests(metafunc): ] metafunc.parametrize('sched_multi', scheds) - if 'test_instance' in metafunc.fixturenames: + if 'test_with_expected_log' in metafunc.fixturenames: instance_files = glob.glob('test/expected_log/*') instances = [basename(instance_file).replace('_jobs.csv', '') for instance_file in instance_files] - metafunc.parametrize('test_instance', instances) + metafunc.parametrize('test_with_expected_log', instances) - + if 'test_with_expected_behavior' in metafunc.fixturenames: + instance_files = glob.glob('test/expected_behavior_log/*') + instances = [basename(instance_file).replace('_user_stats_behaviors.csv', '') + for instance_file in instance_files] + metafunc.parametrize('test_with_expected_behavior', instances) # def pytest_cmdline_preparse(config, args): # html_file = "test-out/testreport.html" diff --git a/test/helper.py b/test/helper.py index e11d20e..7f6579a 100644 --- a/test/helper.py +++ b/test/helper.py @@ -68,10 +68,13 @@ def assert_expected_output(test_file): Files {expected} and {obtained} should be equal but are not.\n\ Run `diff {expected} {obtained}` to investigate why.\n\ Run `cp {obtained} {expected}` to override the expected file with the obtained." + +def has_expected_behavior(test_file): + return os.path.exists(f"test/expected_behavior_log/{test_file}_user_stats_behaviors.csv") def assert_expected_behavior(test_file) : - expected = "test/expected_behavior_log/" + test_file + "_user_stats_behaviors.csv" - obtained = "test-out/" + test_file + "/user_stats_behaviors.csv" + expected = f"test/expected_behavior_log/{test_file}_user_stats_behaviors.csv" + obtained = f"test-out/{test_file}/user_stats_behaviors.csv" if os.path.exists(expected) : assert filecmp.cmp(expected, obtained), f"\ Files {expected} and {obtained} should be equal but are not.\n\ diff --git a/test/test_users.py b/test/test_users.py index 5be9550..d794313 100644 --- a/test/test_users.py +++ b/test/test_users.py @@ -61,6 +61,9 @@ def run_user(user_name, platform_multiC, test_name=None, schedconf=None): if has_expected_output(test_name): assert_expected_output(test_name) + if has_expected_behavior(test_name): + assert_expected_behavior(test_name) + return output_dir diff --git a/test/test_zexpected_output.py b/test/test_zexpected_output.py index 93528b0..f87df37 100644 --- a/test/test_zexpected_output.py +++ b/test/test_zexpected_output.py @@ -1,13 +1,14 @@ from helper import * -def test_expected_output(test_instance): +def test_expected_output(test_with_expected_log): """Test for each expected log (thanks to pytest fixtures) that the test was run and the _jobs.csv outputs are strictly equal""" - assert_expected_output(test_instance) + assert_expected_output(test_with_expected_log) -def test_expected_behavior(test_instance) : +def test_expected_behavior(test_with_expected_behavior) : """Test for each expected log (thanks to pytest fixtures) that the test was -run and the user_behavior_stats.csv outputs are strictly equal if they both exists""" - assert_expected_behavior(test_instance) + run and the user_behavior_stats.csv outputs are strictly equal if they both + exists""" + assert_expected_behavior(test_with_expected_behavior) -- GitLab