-
Notifications
You must be signed in to change notification settings - Fork 26
perf: remove redundant project_root_path.resolve() from hot path #1541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+253
−28
Merged
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b058dee
perf: disable Sentry subprocess instrumentation and tracing
KRRT7 b19e1bd
perf: replace backtracking regexes with character-class patterns in p…
KRRT7 67ee734
perf: remove redundant project_root_path.resolve() from hot path
KRRT7 377083a
style: auto-fix ruff formatting in parse_test_output.py
github-actions[bot] 486f6b8
fix: use disabled_integrations to exclude StdlibIntegration
KRRT7 8995279
style: add return type annotations to test methods
github-actions[bot] 4742585
perf: remove remaining redundant .resolve() calls on pre-resolved paths
KRRT7 27937d4
Merge branch 'narrow-sentry-stdlib-integration' of https://github.com…
KRRT7 dc9c60a
perf: remove remaining redundant .resolve() calls on pre-resolved paths
KRRT7 ac096d9
style: auto-fix line length formatting in functions_to_optimize.py
github-actions[bot] e285908
fix: resolve tests_project_root at inject_profiling entry point
KRRT7 b3fd6bf
fix: resolve both sides of path comparisons for Windows 8.3 name cons…
KRRT7 a726b46
fix: guard against None definition_path from Jedi
KRRT7 5efa1ee
style: remove unused os import in code_context_extractor
github-actions[bot] 74246e6
fix: resolve function_to_optimize.file_path for Windows 8.3 name cons…
github-actions[bot] 3cdf710
fix: use dataclasses.replace() for frozen FunctionToOptimize path res…
github-actions[bot] 8f65c9f
fix: resolve paths in revert_unused_helper_functions for Windows 8.3 …
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| """Tests for the regex patterns and string matching in parse_test_output.py.""" | ||
|
|
||
| from codeflash.verification.parse_test_output import ( | ||
| matches_re_end, | ||
| matches_re_start, | ||
| parse_test_failures_from_stdout, | ||
| ) | ||
|
|
||
|
|
||
| # --- matches_re_start tests --- | ||
|
|
||
|
|
||
| class TestMatchesReStart: | ||
| def test_simple_no_class(self) -> None: | ||
| s = "!$######tests.test_foo:test_bar:target_func:1:abc######$!\n" | ||
| m = matches_re_start.search(s) | ||
| assert m is not None | ||
| assert m.groups() == ("tests.test_foo", "", "test_bar", "target_func", "1", "abc") | ||
|
|
||
| def test_with_class(self) -> None: | ||
| s = "!$######tests.test_foo:MyClass.test_bar:target_func:1:abc######$!\n" | ||
| m = matches_re_start.search(s) | ||
| assert m is not None | ||
| assert m.groups() == ("tests.test_foo", "MyClass.", "test_bar", "target_func", "1", "abc") | ||
|
|
||
| def test_nested_class(self) -> None: | ||
| s = "!$######a.b.c:A.B.test_x:func:3:id123######$!\n" | ||
| m = matches_re_start.search(s) | ||
| assert m is not None | ||
| assert m.groups() == ("a.b.c", "A.B.", "test_x", "func", "3", "id123") | ||
|
|
||
| def test_empty_class_and_function(self) -> None: | ||
| s = "!$######mod::func:0:iter######$!\n" | ||
| m = matches_re_start.search(s) | ||
| assert m is not None | ||
| assert m.groups() == ("mod", "", "", "func", "0", "iter") | ||
|
|
||
| def test_embedded_in_stdout(self) -> None: | ||
| s = "some output\n!$######mod:test_fn:f:1:x######$!\nmore output\n" | ||
| m = matches_re_start.search(s) | ||
| assert m is not None | ||
| assert m.groups() == ("mod", "", "test_fn", "f", "1", "x") | ||
|
|
||
| def test_multiple_matches(self) -> None: | ||
| s = ( | ||
| "!$######m1:C1.fn1:t1:1:a######$!\n" | ||
| "!$######m2:fn2:t2:2:b######$!\n" | ||
| ) | ||
| matches = list(matches_re_start.finditer(s)) | ||
| assert len(matches) == 2 | ||
| assert matches[0].groups() == ("m1", "C1.", "fn1", "t1", "1", "a") | ||
| assert matches[1].groups() == ("m2", "", "fn2", "t2", "2", "b") | ||
|
|
||
| def test_no_match_without_newline(self) -> None: | ||
| s = "!$######mod:test_fn:f:1:x######$!" | ||
| m = matches_re_start.search(s) | ||
| assert m is None | ||
|
|
||
| def test_dots_in_module_path(self) -> None: | ||
| s = "!$######a.b.c.d.e:test_fn:f:1:x######$!\n" | ||
| m = matches_re_start.search(s) | ||
| assert m is not None | ||
| assert m.group(1) == "a.b.c.d.e" | ||
|
|
||
|
|
||
| # --- matches_re_end tests --- | ||
|
|
||
|
|
||
| class TestMatchesReEnd: | ||
| def test_simple_no_class_with_runtime(self) -> None: | ||
| s = "!######tests.test_foo:test_bar:target_func:1:abc:12345######!" | ||
| m = matches_re_end.search(s) | ||
| assert m is not None | ||
| assert m.groups() == ("tests.test_foo", "", "test_bar", "target_func", "1", "abc:12345") | ||
|
|
||
| def test_with_class_no_runtime(self) -> None: | ||
| s = "!######tests.test_foo:MyClass.test_bar:target_func:1:abc######!" | ||
| m = matches_re_end.search(s) | ||
| assert m is not None | ||
| assert m.groups() == ("tests.test_foo", "MyClass.", "test_bar", "target_func", "1", "abc") | ||
|
|
||
| def test_nested_class_with_runtime(self) -> None: | ||
| s = "!######mod:A.B.test_x:func:3:id123:99999######!" | ||
| m = matches_re_end.search(s) | ||
| assert m is not None | ||
| assert m.groups() == ("mod", "A.B.", "test_x", "func", "3", "id123:99999") | ||
|
|
||
| def test_runtime_colon_preserved_in_group6(self) -> None: | ||
| """Group 6 must capture 'iteration_id:runtime' as a single string (colon included).""" | ||
| s = "!######m:fn:f:1:iter42:98765######!" | ||
| m = matches_re_end.search(s) | ||
| assert m is not None | ||
| assert m.group(6) == "iter42:98765" | ||
|
|
||
| def test_embedded_in_stdout(self) -> None: | ||
| s = "captured output\n!######mod:test_fn:f:1:x:500######!\nmore" | ||
| m = matches_re_end.search(s) | ||
| assert m is not None | ||
| assert m.groups() == ("mod", "", "test_fn", "f", "1", "x:500") | ||
|
|
||
|
|
||
| # --- Start/End pairing (simulates parse_test_xml matching logic) --- | ||
|
|
||
|
|
||
| class TestStartEndPairing: | ||
| def test_paired_markers(self) -> None: | ||
| stdout = ( | ||
| "!$######mod:Class.test_fn:func:1:iter1######$!\n" | ||
| "test output here\n" | ||
| "!######mod:Class.test_fn:func:1:iter1:54321######!" | ||
| ) | ||
| starts = list(matches_re_start.finditer(stdout)) | ||
| ends = {} | ||
| for match in matches_re_end.finditer(stdout): | ||
| groups = match.groups() | ||
| g5 = groups[5] | ||
| colon_pos = g5.find(":") | ||
| if colon_pos != -1: | ||
| key = groups[:5] + (g5[:colon_pos],) | ||
| else: | ||
| key = groups | ||
| ends[key] = match | ||
|
|
||
| assert len(starts) == 1 | ||
| assert len(ends) == 1 | ||
| # Start and end should pair on the first 5 groups + iteration_id | ||
| start_groups = starts[0].groups() | ||
| assert start_groups in ends | ||
|
|
||
|
|
||
| # --- parse_test_failures_from_stdout tests --- | ||
|
|
||
|
|
||
| class TestParseTestFailuresHeader: | ||
| def test_standard_pytest_header(self) -> None: | ||
| stdout = ( | ||
| "..F.\n" | ||
| "=================================== FAILURES ===================================\n" | ||
| "_______ test_foo _______\n" | ||
| "\n" | ||
| " def test_foo():\n" | ||
| "> assert False\n" | ||
| "E AssertionError\n" | ||
| "\n" | ||
| "test.py:3: AssertionError\n" | ||
| "=========================== short test summary info ============================\n" | ||
| "FAILED test.py::test_foo\n" | ||
| ) | ||
| result = parse_test_failures_from_stdout(stdout) | ||
| assert "test_foo" in result | ||
|
|
||
| def test_minimal_equals(self) -> None: | ||
| """Even a short '= FAILURES =' header should be detected.""" | ||
| stdout = ( | ||
| "= FAILURES =\n" | ||
| "_______ test_bar _______\n" | ||
| "\n" | ||
| " assert False\n" | ||
| "\n" | ||
| "test.py:1: AssertionError\n" | ||
| "= short test summary info =\n" | ||
| ) | ||
| result = parse_test_failures_from_stdout(stdout) | ||
| assert "test_bar" in result | ||
|
|
||
| def test_no_failures_section(self) -> None: | ||
| stdout = "....\n4 passed in 0.1s\n" | ||
| result = parse_test_failures_from_stdout(stdout) | ||
| assert result == {} | ||
|
|
||
| def test_word_failures_without_equals_is_not_matched(self) -> None: | ||
| """'FAILURES' without surrounding '=' signs should not trigger the header detection.""" | ||
| stdout = ( | ||
| "FAILURES detected in module\n" | ||
| "_______ test_baz _______\n" | ||
| "\n" | ||
| " assert False\n" | ||
| ) | ||
| result = parse_test_failures_from_stdout(stdout) | ||
| assert result == {} | ||
|
|
||
| def test_failures_in_test_output_not_matched(self) -> None: | ||
| """A test printing 'FAILURES' (no = signs) should not trigger header detection.""" | ||
| stdout = ( | ||
| "Testing FAILURES handling\n" | ||
| "All good\n" | ||
| ) | ||
| result = parse_test_failures_from_stdout(stdout) | ||
| assert result == {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.