From 07f63346599cdf90ab6e3bd240c1d162a00dc546 Mon Sep 17 00:00:00 2001 From: Sandro Campos Date: Mon, 30 Oct 2023 16:36:02 -0400 Subject: [PATCH] Add tests for verbose outputs --- pyproject.toml | 6 +++ src/lf_asv_formatter/__main__.py | 1 + tests/conftest.py | 20 -------- tests/data/simple/expected_output_verbose | 7 +++ tests/data/simple/original_output_verbose | 25 +++++++++ tests/data/tabulate/expected_output_verbose | 9 ++++ tests/data/tabulate/original_output_verbose | 23 +++++++++ tests/lf_asv_formatter/test_asv_formatter.py | 54 +++++++++++++++----- 8 files changed, 111 insertions(+), 34 deletions(-) create mode 100644 tests/data/simple/expected_output_verbose create mode 100644 tests/data/simple/original_output_verbose create mode 100644 tests/data/tabulate/expected_output_verbose create mode 100644 tests/data/tabulate/original_output_verbose diff --git a/pyproject.toml b/pyproject.toml index 1737d39..e1fc355 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,3 +41,9 @@ write_to = "src/lf_asv_formatter/_version.py" testpaths = [ "tests", ] + +[tool.coverage.report] +omit = [ + "src/lf_asv_formatter/_version.py", + "src/lf_asv_formatter/__main__.py", +] \ No newline at end of file diff --git a/src/lf_asv_formatter/__main__.py b/src/lf_asv_formatter/__main__.py index db2b281..d5045ec 100644 --- a/src/lf_asv_formatter/__main__.py +++ b/src/lf_asv_formatter/__main__.py @@ -6,6 +6,7 @@ def parse_asv_version(): + """Parses asv version from command line arguments.""" parser = argparse.ArgumentParser("lf_asv_formatter") parser.add_argument("--asv_version", help="Version of asv", type=str, required=True) return parser.parse_args().asv_version diff --git a/tests/conftest.py b/tests/conftest.py index 82e2800..39bfd69 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -24,26 +24,6 @@ def test_data_tabulate_dir(test_data_dir): return os.path.join(test_data_dir, "tabulate") -@pytest.fixture -def original_output_simple_path(test_data_simple_dir): - return os.path.join(test_data_simple_dir, "original_output") - - -@pytest.fixture -def expected_output_simple_path(test_data_simple_dir): - return os.path.join(test_data_simple_dir, "expected_output") - - -@pytest.fixture -def original_output_tabulate_path(test_data_tabulate_dir): - return os.path.join(test_data_tabulate_dir, "original_output") - - -@pytest.fixture -def expected_output_tabulate_path(test_data_tabulate_dir): - return os.path.join(test_data_tabulate_dir, "expected_output") - - @pytest.fixture def assert_text_file_matches(): def assert_text_file_matches(file_name, golden_file_name): diff --git a/tests/data/simple/expected_output_verbose b/tests/data/simple/expected_output_verbose new file mode 100644 index 0000000..f69f412 --- /dev/null +++ b/tests/data/simple/expected_output_verbose @@ -0,0 +1,7 @@ +| Change | Before [a4e3082d] | After [8110f9f7] | Ratio | Benchmark (Parameter) | +|----------|-----------------------------------|----------------------------------|---------|------------------------------------| +| | 692±600ms | 2.72±1s | ~3.93 | benchmarks.TimeSuite.time_iterkeys | +| | 867±400ms | 2.21±1s | ~2.55 | benchmarks.TimeSuite.time_range | +| | 1.31±0.2s | 2.50±1s | ~1.92 | benchmarks.TimeSuite.time_keys | +| | 1.35±0.6s | 1.26±0.6s | 0.93 | benchmarks.TimeSuite.time_xrange | +| - | 2.92k | 1.46k | 0.50 | benchmarks.MemSuite.mem_list | \ No newline at end of file diff --git a/tests/data/simple/original_output_verbose b/tests/data/simple/original_output_verbose new file mode 100644 index 0000000..a945a47 --- /dev/null +++ b/tests/data/simple/original_output_verbose @@ -0,0 +1,25 @@ +· Running '/usr/bin/git config init.defaultBranch' + OUTPUT --------> + main +· Running '/usr/bin/git rev-parse upstream/main^{commit}' + OUTPUT -------->cs + a4e3082dc3f9f5b724089189082d33f401061a21 +· Running '/usr/bin/git rev-parse HEAD^{commit}' + OUTPUT --------> + 8110f9f74a714a807867479993593bd9f326e1c5 +· Running '/usr/bin/git name-rev --name-only --exclude=remotes/* --no-undefined a4e3082dc3f9f5b724089189082d33f401061a21' + OUTPUT --------> + add-docs~15 +· Running '/usr/bin/git name-rev --name-only --exclude=remotes/* --no-undefined 8110f9f74a714a807867479993593bd9f326e1c5' + OUTPUT --------> + upgrade-asv + +All benchmarks: + +| Change | Before [a4e3082d] | After [8110f9f7] | Ratio | Benchmark (Parameter) | +|----------|-----------------------------------|----------------------------------|---------|------------------------------------| +| | 692±600ms | 2.72±1s | ~3.93 | benchmarks.TimeSuite.time_iterkeys | +| | 867±400ms | 2.21±1s | ~2.55 | benchmarks.TimeSuite.time_range | +| | 1.31±0.2s | 2.50±1s | ~1.92 | benchmarks.TimeSuite.time_keys | +| | 1.35±0.6s | 1.26±0.6s | 0.93 | benchmarks.TimeSuite.time_xrange | +| - | 2.92k | 1.46k | 0.50 | benchmarks.MemSuite.mem_list | \ No newline at end of file diff --git a/tests/data/tabulate/expected_output_verbose b/tests/data/tabulate/expected_output_verbose new file mode 100644 index 0000000..b2f8434 --- /dev/null +++ b/tests/data/tabulate/expected_output_verbose @@ -0,0 +1,9 @@ +| Before | After | Ratio | Method | +|---------------|---------------|---------|------------------------------------| +| [a4e3082d] | [8110f9f7] | | | +| | | | | +| 692±600ms | 2.72±1s | ~3.93 | benchmarks.TimeSuite.time_iterkeys | +| 867±400ms | 2.21±1s | ~2.55 | benchmarks.TimeSuite.time_range | +| 1.31±0.2s | 2.50±1s | ~1.92 | benchmarks.TimeSuite.time_keys | +| 1.35±0.6s | 1.26±0.6s | 0.93 | benchmarks.TimeSuite.time_xrange | +| 2.92k | 1.46k | 0.50 | benchmarks.MemSuite.mem_list | \ No newline at end of file diff --git a/tests/data/tabulate/original_output_verbose b/tests/data/tabulate/original_output_verbose new file mode 100644 index 0000000..49c195d --- /dev/null +++ b/tests/data/tabulate/original_output_verbose @@ -0,0 +1,23 @@ +· Running '/usr/bin/git rev-parse upstream/main^{commit}' + OUTPUT --------> + a4e3082dc3f9f5b724089189082d33f401061a21 +· Running '/usr/bin/git rev-parse HEAD^{commit}' + OUTPUT --------> + 8110f9f74a714a807867479993593bd9f326e1c5 +· Running '/usr/bin/git name-rev --name-only --exclude=remotes/* --no-undefined a4e3082dc3f9f5b724089189082d33f401061a21' + OUTPUT --------> + add-docs~15 +· Running '/usr/bin/git name-rev --name-only --exclude=remotes/* --no-undefined 8110f9f74a714a807867479993593bd9f326e1c5' + OUTPUT --------> + upgrade-asv + +All benchmarks: + + before after ratio + [a4e3082d] [8110f9f7] + + 692±600ms 2.72±1s ~3.93 benchmarks.TimeSuite.time_iterkeys + 867±400ms 2.21±1s ~2.55 benchmarks.TimeSuite.time_range + 1.31±0.2s 2.50±1s ~1.92 benchmarks.TimeSuite.time_keys + 1.35±0.6s 1.26±0.6s 0.93 benchmarks.TimeSuite.time_xrange +- 2.92k 1.46k 0.50 benchmarks.MemSuite.mem_list \ No newline at end of file diff --git a/tests/lf_asv_formatter/test_asv_formatter.py b/tests/lf_asv_formatter/test_asv_formatter.py index 5681857..4bf594e 100644 --- a/tests/lf_asv_formatter/test_asv_formatter.py +++ b/tests/lf_asv_formatter/test_asv_formatter.py @@ -4,25 +4,51 @@ from lf_asv_formatter.tabulate_formatter import TabulateFormatter -def test_rewrite_file_simple( - assert_text_file_matches, - tmp_path, - original_output_simple_path, - expected_output_simple_path, -): +def get_test_files(folder): + """Gets test files in folder.""" + original_output = os.path.join(folder, "original_output") + original_output_verbose = os.path.join(folder, "original_output_verbose") + expected_output = os.path.join(folder, "expected_output") + expected_output_verbose = os.path.join(folder, "expected_output_verbose") + return ( + original_output, + original_output_verbose, + expected_output, + expected_output_verbose, + ) + + +def test_rewrite_file_simple(assert_text_file_matches, tmp_path, test_data_simple_dir): """Confirm that we write out the file with the expected format using the simple formatter.""" + ( + original_output, + original_output_verbose, + expected_output, + expected_output_verbose, + ) = get_test_files(test_data_simple_dir) output_file = os.path.join(tmp_path, "output_file") - SimpleFormatter(original_output_simple_path, output_file).rewrite_file() - assert_text_file_matches(output_file, expected_output_simple_path) + # If the output is non-verbose + SimpleFormatter(original_output, output_file).rewrite_file() + assert_text_file_matches(output_file, expected_output) + # If the output is verbose + SimpleFormatter(original_output_verbose, output_file).rewrite_file() + assert_text_file_matches(output_file, expected_output_verbose) def test_rewrite_file_tabulate( - assert_text_file_matches, - tmp_path, - original_output_tabulate_path, - expected_output_tabulate_path, + assert_text_file_matches, tmp_path, test_data_tabulate_dir ): """Confirm that we write out the file with the expected GitHub formatting using tabulate.""" + ( + original_output, + original_output_verbose, + expected_output, + expected_output_verbose, + ) = get_test_files(test_data_tabulate_dir) output_file = os.path.join(tmp_path, "output_file") - TabulateFormatter(original_output_tabulate_path, output_file).rewrite_file() - assert_text_file_matches(output_file, expected_output_tabulate_path) + # If the output is non-verbose + TabulateFormatter(original_output, output_file).rewrite_file() + assert_text_file_matches(output_file, expected_output) + # If the output is verbose + TabulateFormatter(original_output_verbose, output_file).rewrite_file() + assert_text_file_matches(output_file, expected_output_verbose)