Skip to content

Commit

Permalink
feat: add pytest-benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
jnoortheen committed Jul 20, 2024
1 parent db457db commit ab1d691
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ extend-safe-fixes = ["FA", "TCH", "PT"]
log_file = "pytest.log"
log_file_level = "DEBUG"
log_file_format = "%(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)"
addopts = "--benchmark-skip"

[tool.pdm]
[project.optional-dependencies]
Expand Down
21 changes: 21 additions & 0 deletions tests/test_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ def main():
return XonshParser.parse_string(src_txt, mode="eval")


def large_file():
from pathlib import Path

from peg_parser.parser import XonshParser

file = Path(__file__).parent.parent / "peg_parser" / "parser.py"
print(f"file: {file}")
assert file.exists()
return XonshParser.parse_file(file)


def test_parse_string(benchmark):
# benchmark something
result = benchmark(main)
Expand All @@ -13,3 +24,13 @@ def test_parse_string(benchmark):
# Sometimes you may want to check the result, fast functions
# are no good if they return incorrect results :-)
assert result


def test_parse_file(benchmark):
# benchmark something
result = benchmark(large_file)

# Extra code, to verify that the run completed correctly.
# Sometimes you may want to check the result, fast functions
# are no good if they return incorrect results :-)
assert result

0 comments on commit ab1d691

Please sign in to comment.