Skip to content

Commit

Permalink
Add tests for verbose outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
camposandro committed Oct 30, 2023
1 parent dda46e4 commit 07f6334
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 34 deletions.
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
1 change: 1 addition & 0 deletions src/lf_asv_formatter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


def parse_asv_version():

Check warning on line 8 in src/lf_asv_formatter/__main__.py

View check run for this annotation

Codecov / codecov/patch

src/lf_asv_formatter/__main__.py#L8

Added line #L8 was not covered by tests
"""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

Check warning on line 12 in src/lf_asv_formatter/__main__.py

View check run for this annotation

Codecov / codecov/patch

src/lf_asv_formatter/__main__.py#L10-L12

Added lines #L10 - L12 were not covered by tests
Expand Down
20 changes: 0 additions & 20 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 7 additions & 0 deletions tests/data/simple/expected_output_verbose
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
| Change | Before [a4e3082d] <add-docs~15> | After [8110f9f7] <upgrade-asv> | 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 |
25 changes: 25 additions & 0 deletions tests/data/simple/original_output_verbose
Original file line number Diff line number Diff line change
@@ -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] <add-docs~15> | After [8110f9f7] <upgrade-asv> | 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 |
9 changes: 9 additions & 0 deletions tests/data/tabulate/expected_output_verbose
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
| Before | After | Ratio | Method |
|---------------|---------------|---------|------------------------------------|
| [a4e3082d] | [8110f9f7] | | |
| <add-docs~15> | <upgrade-asv> | | |
| 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 |
23 changes: 23 additions & 0 deletions tests/data/tabulate/original_output_verbose
Original file line number Diff line number Diff line change
@@ -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]
<add-docs~15> <upgrade-asv>
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
54 changes: 40 additions & 14 deletions tests/lf_asv_formatter/test_asv_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 07f6334

Please sign in to comment.