diff --git a/tests/test_migrate_benchmarks.py b/tests/test_migrate_benchmarks.py new file mode 100644 index 0000000000000000000000000000000000000000..dda52a8b8613b4e77a94da63e7d74cc46fab8e3b_dGVzdHMvdGVzdF9taWdyYXRlX2JlbmNobWFya3MucHk= --- /dev/null +++ b/tests/test_migrate_benchmarks.py @@ -0,0 +1,366 @@ +from __future__ import unicode_literals +from __future__ import print_function + +import pytest + +from script.migrate_benchmarks import ( + rewrite_params_results_and_stats, + is_new_format, +) + +simple_test = pytest.param( + [ + [ + "'mercurial-2018-08-01'", + "'mozilla-central-2018-08-01'", + "'netbeans-2018-08-01'", + "'pypy-2018-08-01'", + ] + ], + [0.1, 0.2, 0.3, 0.4], + None, + [ + [ + "'mercurial-2018-08-01'", + "'mozilla-central-2018-08-01'", + "'netbeans-2018-08-01'", + "'pypy-2018-08-01'", + ], + ["'zlib'"], + ["True"], + ["True"], + ["True"], + ["True"], + ["True", "False"], + ], + [None, 0.1, None, 0.2, None, 0.3, None, 0.4], + None, + id="No sparse-revlog, no additional params, no stats", +) + +sparse_test = pytest.param( + [ + [ + "'mercurial-2018-08-01-sparse-revlog'", # Out of order + "'mercurial-2018-08-01'", + "'mozilla-central-2018-08-01'", + "'mozilla-central-2018-08-01-sparse-revlog'", + "'netbeans-2018-08-01-sparse-revlog'", # Out of order + "'netbeans-2018-08-01'", + "'pypy-2018-08-01'", + "'pypy-2018-08-01-sparse-revlog'", + ] + ], + [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8], + None, + [ + [ + "'mercurial-2018-08-01'", + "'mozilla-central-2018-08-01'", + "'netbeans-2018-08-01'", + "'pypy-2018-08-01'", + ], + ["'zlib'"], + ["True"], + ["True"], + ["True"], + ["True"], + ["True", "False"], + ], + [0.1, 0.2, 0.4, 0.3, 0.5, 0.6, 0.8, 0.7], + None, + id="Sparse-revlog, no additional params, no stats", +) + +only_sparse_test = pytest.param( + [ + [ + "'mercurial-2018-08-01-sparse-revlog'", + "'mercurial-2018-08-01'", + "'mozilla-central-2018-08-01'", + "'mozilla-central-2018-08-01-sparse-revlog'", # Out of order + "'netbeans-2018-08-01-sparse-revlog'", + "'netbeans-2018-08-01'", + "'pypy-2018-08-01'", # Out of order + "'pypy-2018-08-01-sparse-revlog'", + "'mozilla-try-2019-03-01-sparse-revlog'", # Only sparse + ] + ], + [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9], + None, + [ + [ + "'mercurial-2018-08-01'", + "'mozilla-central-2018-08-01'", + "'netbeans-2018-08-01'", + "'pypy-2018-08-01'", + "'mozilla-try-2019-03-01'", + ], + ["'zlib'"], + ["True"], + ["True"], + ["True"], + ["True"], + ["True", "False"], + ], + [0.1, 0.2, 0.4, 0.3, 0.5, 0.6, 0.8, 0.7, 0.9, None], + None, + id="One only sparse-revlog, no additional params, no stats", +) + +sparse_params_test = pytest.param( + [ + [ + "'mercurial-2018-08-01-sparse-revlog'", + "'mercurial-2018-08-01'", + "'mozilla-central-2018-08-01'", + "'mozilla-central-2018-08-01-sparse-revlog'", # Out of order + "'netbeans-2018-08-01'", + "'netbeans-2018-08-01-sparse-revlog'", # Out of order + "'pypy-2018-08-01-sparse-revlog'", + "'pypy-2018-08-01'", + ], + ["'superparam'"], + ["100", "1000"], + ], + list(range(1, 17)), + None, + [ + [ + "'mercurial-2018-08-01'", + "'mozilla-central-2018-08-01'", + "'netbeans-2018-08-01'", + "'pypy-2018-08-01'", + ], + ["'zlib'"], + ["True"], + ["True"], + ["True"], + ["True"], + ["True", "False"], + ["'superparam'"], + ["100", "1000"], + ], + [1, 2, 3, 4, 7, 8, 5, 6, 11, 12, 9, 10, 13, 14, 15, 16], + None, + id="Sparse-revlog, additional params, no stats", +) + +sparse_params_stats_test = pytest.param( + [ + [ + "'mercurial-2018-08-01-sparse-revlog'", + "'mercurial-2018-08-01'", + "'mozilla-central-2018-08-01'", + "'mozilla-central-2018-08-01-sparse-revlog'", # Out of order + "'netbeans-2018-08-01'", + "'netbeans-2018-08-01-sparse-revlog'", # Out of order + "'pypy-2018-08-01-sparse-revlog'", + "'pypy-2018-08-01'", + ], + ["'superparam'"], + ["100", "1000"], + ], + list(range(1, 17)), + [ + {"stat{}".format(index): "value{}".format(index)} + for index in range(1, 17) + ], + [ + [ + "'mercurial-2018-08-01'", + "'mozilla-central-2018-08-01'", + "'netbeans-2018-08-01'", + "'pypy-2018-08-01'", + ], + ["'zlib'"], + ["True"], + ["True"], + ["True"], + ["True"], + ["True", "False"], + ["'superparam'"], + ["100", "1000"], + ], + [1, 2, 3, 4, 7, 8, 5, 6, 11, 12, 9, 10, 13, 14, 15, 16], + [ + {"stat1": "value1"}, + {"stat2": "value2"}, + {"stat3": "value3"}, + {"stat4": "value4"}, + {"stat7": "value7"}, + {"stat8": "value8"}, + {"stat5": "value5"}, + {"stat6": "value6"}, + {"stat11": "value11"}, + {"stat12": "value12"}, + {"stat9": "value9"}, + {"stat10": "value10"}, + {"stat13": "value13"}, + {"stat14": "value14"}, + {"stat15": "value15"}, + {"stat16": "value16"}, + ], + id="Sparse-revlog, additional params, stats", +) + +only_one_null_result_test = pytest.param( + [ + [ + "'mercurial-2018-08-01'", + "'mozilla-central-2018-08-01'", + "'netbeans-2018-08-01'", + "'pypy-2018-08-01'", + ] + ], + [None], + None, + [ + [ + "'mercurial-2018-08-01'", + "'mozilla-central-2018-08-01'", + "'netbeans-2018-08-01'", + "'pypy-2018-08-01'", + ], + ["'zlib'"], + ["True"], + ["True"], + ["True"], + ["True"], + ["True", "False"], + ], + [None for _ in range(8)], + None, + id="Only one null result", # Can be found in a few files +) + +null_results_test = pytest.param( + [ + [ + "'mercurial-2018-08-01'", + "'mozilla-central-2018-08-01'", + "'netbeans-2018-08-01'", + "'pypy-2018-08-01'", + ] + ], + None, + None, + [ + [ + "'mercurial-2018-08-01'", + "'mozilla-central-2018-08-01'", + "'netbeans-2018-08-01'", + "'pypy-2018-08-01'", + ], + ["'zlib'"], + ["True"], + ["True"], + ["True"], + ["True"], + ["True", "False"], + ], + [None for _ in range(8)], + None, + id="Results are null", # Can be found in a few files +) + + +@pytest.mark.parametrize( + [ + "old_params", + "old_results", + "old_stats", + "new_params", + "new_results", + "new_stats", + ], + [ + simple_test, + sparse_test, + sparse_params_test, + only_sparse_test, + sparse_params_stats_test, + only_one_null_result_test, + null_results_test, + ], +) +def test_rewrite_params_results_and_stats( + old_params, old_results, old_stats, new_params, new_results, new_stats +): + rewrite = rewrite_params_results_and_stats( + old_params=old_params, old_results=old_results, old_stats=old_stats + ) + assert rewrite == (new_params, new_results, new_stats) + + +@pytest.mark.parametrize( + ["params", "new_format"], + [ + pytest.param( + [ + [ + "'mercurial-2018-08-01'", + "'mozilla-central-2018-08-01'", + "'netbeans-2018-08-01'", + "'pypy-2018-08-01'", + ] + ], + False, + id="Only one parameter", + ), + pytest.param( + [ + [ + "'mercurial-2018-08-01'", + "'mozilla-central-2018-08-01'", + "'netbeans-2018-08-01'", + "'pypy-2018-08-01'", + ], + ["'zlib'"], + ["True"], + ["True"], + ["True"], + ["True"], + ["True", "False"], + ], + True, + id="New format", + ), + pytest.param( + [ + [ + "'mercurial-2018-08-01'", + "'mozilla-central-2018-08-01'", + "'netbeans-2018-08-01'", + "'pypy-2018-08-01'", + ], + ["'zlib'"], + ["True"], + ["True"], + ["True"], + ["True"], + ["False", "True"], + ], + True, + id="Other new format", + ), + pytest.param( + [ + [ + "'mercurial-2018-08-01-sparse-revlog'", + "'mercurial-2018-08-01'", + "'mozilla-central-2018-08-01-sparse-revlog'", + "'mozilla-central-2018-08-01'", + "'netbeans-2018-08-01-sparse-revlog'", + "'netbeans-2018-08-01'", + "'pypy-2018-08-01-sparse-revlog'", + "'pypy-2018-08-01'", + ] + ], + False, + id="Old format", + ), + ], +) +def test_is_new_format(params, new_format): + assert is_new_format({"params": params}) == new_format