tonybaloney / wily

A Python application for tracking, reporting on timing and complexity in Python code
Apache License 2.0
1.21k stars 59 forks source link

Add unit tests for some commands #199

Closed devdanzin closed 1 year ago

devdanzin commented 1 year ago

This PR adds unit tests for index, report, rank, graph and list-metrics. It should help land the JSON output PR (and any others touching output) without any regressions.

It's a bit rough in the edges, but I believe these are good to have. Instead of testing the output it would be possible to mock tabulate, but I feel checking the output works best.

codecov-commenter commented 1 year ago

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (d0ad384) 95.76% compared to head (1a55a05) 95.76%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #199 +/- ## ======================================= Coverage 95.76% 95.76% ======================================= Files 25 25 Lines 1369 1370 +1 Branches 293 293 ======================================= + Hits 1311 1312 +1 Misses 33 33 Partials 25 25 ``` | [Files Changed](https://app.codecov.io/gh/tonybaloney/wily/pull/199?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anthony+Shaw) | Coverage Δ | | |---|---|---| | [src/wily/commands/rank.py](https://app.codecov.io/gh/tonybaloney/wily/pull/199?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anthony+Shaw#diff-c3JjL3dpbHkvY29tbWFuZHMvcmFuay5weQ==) | `96.66% <100.00%> (+0.05%)` | :arrow_up: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

tonybaloney commented 1 year ago

Please rename the files, they don't need to be called x_unit.py they're already in a unit folder

devdanzin commented 1 year ago

Thanks for reviewing this!

Unfortunately, when I renamed the files to avoid using "_unit", pytest threw errors like:

______________________________________ ERROR collecting test/unit/test_graph.py _______________________________________
import file mismatch:
imported module 'test_graph' has this __file__ attribute:
  wily\test\integration\test_graph.py
which is not the same as the test file we want to collect:
  wily\test\unit\test_graph.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules

Not sure whether it comes from pytest or the coverage plugin. I guess that's why we already had a build_unit.py file under test/unit, to avoid this kind of error. So I'm reverting the rename unless you'd prefer that I try to figure out how to support files with the same basenames.

I've addressed your comments, let me know if any of the solutions needs improvement.

tonybaloney commented 1 year ago

Thanks for reviewing this!

Unfortunately, when I renamed the files to avoid using "_unit", pytest threw errors like:

______________________________________ ERROR collecting test/unit/test_graph.py _______________________________________
import file mismatch:
imported module 'test_graph' has this __file__ attribute:
  wily\test\integration\test_graph.py
which is not the same as the test file we want to collect:
  wily\test\unit\test_graph.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules

Not sure whether it comes from pytest or the coverage plugin. I guess that's why we already had a build_unit.py file under test/unit, to avoid this kind of error. So I'm reverting the rename unless you'd prefer that I try to figure out how to support files with the same basenames.

I've addressed your comments, let me know if any of the solutions needs improvement.

ah yes, I forgot about that. Pytest requires that all files have unique names