Skip to content

Commit

Permalink
Added metrics and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
surge119 committed Jul 30, 2024
1 parent 3126ee8 commit 06c0a92
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/fixit/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def visit_hook(name: str) -> Iterator[None]:
violation = replace(violation, diff=diff)

yield violation

self.metrics["ViolationCount.Total"] = count

if metrics_hook:
metrics_hook(self.metrics)

Expand Down
7 changes: 5 additions & 2 deletions src/fixit/tests/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ def test_timing(self) -> None:
rule = NoopRule()
for _ in self.runner.collect_violations([rule], Config()):
pass # exhaust the generator
self.assertIn("NoopRule.visit_Module", self.runner.metrics)
self.assertIn("NoopRule.leave_Module", self.runner.metrics)
self.assertIn("Duration.NoopRule.visit_Module", self.runner.metrics)
self.assertIn("Duration.NoopRule.leave_Module", self.runner.metrics)
self.assertGreaterEqual(self.runner.metrics["NoopRule.visit_Module"], 0)
self.assertIn("ViolationCount.Noop", self.runner.metrics)
self.assertIn("ViolationCountWithReplacement.Noop", self.runner.metrics)
self.assertIn("ViolationCount.Total", self.runner.metrics)

def test_timing_hook(self) -> None:
rule = NoopRule()
Expand Down

0 comments on commit 06c0a92

Please sign in to comment.