-
Notifications
You must be signed in to change notification settings - Fork 22
stdout comparison #18
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
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
464f6a6
stdout comparison
KRRT7 1f25df9
strip
KRRT7 f40c388
stdout comparison in E2E
KRRT7 f164fd2
add test in instrumentation
KRRT7 d0710ce
stdout comparison
KRRT7 944e974
strip
KRRT7 3147c4a
update aiservice test
KRRT7 1a4f60e
Update test_codeflash_capture.py
KRRT7 ed970ea
add more unit tests
KRRT7 f397289
address review.
KRRT7 11e43ea
strip out captured log part
KRRT7 bb1bbf9
missed a few direct comparison for stdout
KRRT7 dcf9384
adress review
KRRT7 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| def sorter(arr): | ||
| print("codeflash stdout: Sorting list") | ||
| for i in range(len(arr)): | ||
| for j in range(len(arr) - 1): | ||
| if arr[j] > arr[j + 1]: | ||
| temp = arr[j] | ||
| arr[j] = arr[j + 1] | ||
| arr[j + 1] = temp | ||
| print(f"result: {arr}") | ||
| return arr |
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 |
|---|---|---|
| @@ -1,12 +1,17 @@ | ||
| import sys | ||
|
|
||
|
|
||
| class BubbleSorter: | ||
| def __init__(self, x=0): | ||
| self.x = x | ||
|
|
||
| def sorter(self, arr): | ||
| print("codeflash stdout : BubbleSorter.sorter() called") | ||
| for i in range(len(arr)): | ||
| for j in range(len(arr) - 1): | ||
| if arr[j] > arr[j + 1]: | ||
| temp = arr[j] | ||
| arr[j] = arr[j + 1] | ||
| arr[j + 1] = temp | ||
| print("stderr test", file=sys.stderr) | ||
| return arr | ||
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 |
|---|---|---|
|
|
@@ -168,6 +168,13 @@ def test_sort(): | |
| pytest_max_loops=1, | ||
| testing_time=0.1, | ||
| ) | ||
|
|
||
| out_str = """codeflash stdout: Sorting list | ||
| result: [0, 1, 2, 3, 4, 5] | ||
|
|
||
KRRT7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| codeflash stdout: Sorting list | ||
| result: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]""" | ||
| assert out_str == test_results[0].stdout | ||
| assert test_results[0].id.function_getting_tested == "sorter" | ||
| assert test_results[0].id.iteration_id == "1_0" | ||
| assert test_results[0].id.test_class_name is None | ||
|
|
@@ -179,6 +186,7 @@ def test_sort(): | |
| assert test_results[0].runtime > 0 | ||
| assert test_results[0].did_pass | ||
| assert test_results[0].return_value == ([0, 1, 2, 3, 4, 5],) | ||
| assert out_str == test_results[1].stdout.strip() | ||
|
|
||
| assert test_results[1].id.function_getting_tested == "sorter" | ||
| assert test_results[1].id.iteration_id == "4_0" | ||
|
|
@@ -190,6 +198,22 @@ def test_sort(): | |
| ) | ||
| assert test_results[1].runtime > 0 | ||
| assert test_results[1].did_pass | ||
| results2, _ = func_optimizer.run_and_parse_tests( | ||
| testing_type=TestingMode.BEHAVIOR, | ||
| test_env=test_env, | ||
| test_files=func_optimizer.test_files, | ||
| optimization_iteration=0, | ||
| pytest_min_loops=1, | ||
| pytest_max_loops=1, | ||
| testing_time=0.1, | ||
| ) | ||
| out_str = """codeflash stdout: Sorting list | ||
| result: [0, 1, 2, 3, 4, 5] | ||
|
|
||
| codeflash stdout: Sorting list | ||
| result: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]""" | ||
| assert out_str == results2[0].stdout.strip() | ||
| assert compare_test_results(test_results, results2) | ||
| finally: | ||
| fto_path.write_text(original_code, "utf-8") | ||
| test_path.unlink(missing_ok=True) | ||
|
|
@@ -340,13 +364,11 @@ def test_sort(): | |
| pytest_max_loops=1, | ||
| testing_time=0.1, | ||
| ) | ||
|
|
||
| assert len(test_results) == 4 | ||
| assert test_results[0].id.function_getting_tested == "BubbleSorter.__init__" | ||
| assert test_results[0].id.test_function_name == "test_sort" | ||
| assert test_results[0].did_pass | ||
| assert test_results[0].return_value[0] == {"x": 0} | ||
|
|
||
| assert test_results[1].id.function_getting_tested == "BubbleSorter.sorter" | ||
| assert test_results[1].id.iteration_id == "2_0" | ||
| assert test_results[1].id.test_class_name is None | ||
|
|
@@ -358,7 +380,9 @@ def test_sort(): | |
| assert test_results[1].runtime > 0 | ||
| assert test_results[1].did_pass | ||
| assert test_results[1].return_value == ([0, 1, 2, 3, 4, 5],) | ||
|
|
||
| out_str = """codeflash stdout : BubbleSorter.sorter() called\n\n\ncodeflash stdout : BubbleSorter.sorter() called""" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why does this have \n whereas all others have proper newlines? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was debugging something, forgot to revert. |
||
| assert test_results[1].stdout == out_str | ||
| assert compare_test_results(test_results, test_results) | ||
| assert test_results[2].id.function_getting_tested == "BubbleSorter.__init__" | ||
| assert test_results[2].id.test_function_name == "test_sort" | ||
| assert test_results[2].did_pass | ||
|
|
@@ -375,6 +399,18 @@ def test_sort(): | |
| assert test_results[3].runtime > 0 | ||
| assert test_results[3].did_pass | ||
|
|
||
| results2, _ = func_optimizer.run_and_parse_tests( | ||
| testing_type=TestingMode.BEHAVIOR, | ||
| test_env=test_env, | ||
| test_files=func_optimizer.test_files, | ||
| optimization_iteration=0, | ||
| pytest_min_loops=1, | ||
| pytest_max_loops=1, | ||
| testing_time=0.1, | ||
| ) | ||
|
|
||
| assert compare_test_results(test_results, results2) | ||
|
|
||
| # Replace with optimized code that mutated instance attribute | ||
| optimized_code = """ | ||
| class BubbleSorter: | ||
|
|
||
Oops, something went wrong.
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.