-
Notifications
You must be signed in to change notification settings - Fork 75
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
Fix TypeError on YAML test execution with trace option #1299
Open
sandcha
wants to merge
17
commits into
master
Choose a base branch
from
fix-typeerror-tracer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c63e33c
Start a test_trace and reorder TestItem attributes to avoid missing n…
sandcha 157965d
Also apply from_parent syntax on TestFile parent
sandcha 1ce3420
Fix AssertionError on _imply_path for None fspath
sandcha 3d3f495
Check TestItem init
sandcha 36be1d9
Activate verbose on test_trace and see expected TypeError
sandcha ef2ea1a
Move TestItem init documentation to its class
sandcha e8bdb52
Fix syntax and remove skip on test_performance_tables_option_output
sandcha 08c878a
Fix syntax and remove skip on test_performance_graph_option_output
sandcha d04d7a9
To avoid configuration change inside behaviour do not set log max_dep…
sandcha 6a52fb2
Fix TypeError on YamlItem by setting max_depth on runtest
sandcha a5c7620
Capture printed trace log in test
sandcha 30592d0
fixup! Fix TypeError on YamlItem by setting max_depth on runtest
sandcha bcce36f
Fix FullTracer.print_computation_log by reactivating print in Compura…
sandcha cf954cc
Fix linting and style
sandcha cab2240
Check verbose option printed output on YAML test
sandcha 5512c32
Fix syntax and remove skip on test_variable_not_found
sandcha 3e33e43
Add a test for YamlItem runtest and explicit difference between basel…
sandcha 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 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 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 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 |
---|---|---|
|
@@ -63,11 +63,30 @@ def __init__(self) -> None: | |
|
||
|
||
class TestItem(YamlItem): | ||
def __init__(self, test) -> None: | ||
super().__init__("", TestFile(), TaxBenefitSystem(), test, {}) | ||
|
||
self.tax_benefit_system = self.baseline_tax_benefit_system | ||
self.simulation = Simulation() | ||
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.
|
||
""" | ||
Mock a YamlItem for tests. | ||
|
||
Usage example: | ||
testFile = TestFile.from_parent(parent=None) | ||
test = { | ||
"input": {...}, | ||
"output": {...}, # noqa RST201 | ||
} | ||
test_item = TestItem.from_parent(parent=testFile, test=test) | ||
|
||
where 'from_parent' is inherited from pytest.Item through YamlItem | ||
""" | ||
|
||
def __init__(self, test, **kwargs) -> None: | ||
# get expected 'parent' from kwargs (comes from 'from_parent') | ||
super().__init__( | ||
name="", | ||
path="", | ||
baseline_tax_benefit_system=TaxBenefitSystem(), | ||
test=test, | ||
options={}, | ||
**kwargs, | ||
) | ||
|
||
|
||
class TestVariable(Variable): | ||
|
@@ -82,11 +101,13 @@ def __init__(self) -> None: | |
self.dtype = numpy.float32 | ||
|
||
|
||
@pytest.mark.skip(reason="Deprecated node constructor") | ||
def test_variable_not_found() -> None: | ||
test_file = TestFile.from_parent(parent=None) | ||
test = {"output": {"unknown_variable": 0}} | ||
with pytest.raises(errors.VariableNotFoundError) as excinfo: | ||
test_item = TestItem(test) | ||
test_item = TestItem.from_parent(parent=test_file, test=test) | ||
test_item.tax_benefit_system = test_item.baseline_tax_benefit_system | ||
test_item.simulation = Simulation() | ||
test_item.check_output() | ||
assert excinfo.value.variable_name == "unknown_variable" | ||
|
||
|
@@ -147,13 +168,31 @@ def test_extensions_order() -> None: | |
) # extensions order is ignored in cache | ||
|
||
|
||
@pytest.mark.skip(reason="Deprecated node constructor") | ||
def test_runtest() -> None: | ||
test_file = TestFile.from_parent(parent=None) | ||
test = { | ||
"input": {"salary": {"2017-01": 2000}}, | ||
"output": {"salary": {"2017-01": 2000}}, | ||
} | ||
test_item = TestItem.from_parent(parent=test_file, test=test) | ||
|
||
# TestItem init should instantiate the baseline TaxBenefitSystem | ||
assert test_item.baseline_tax_benefit_system.get_variable("salary") is not None | ||
|
||
test_item.runtest() | ||
|
||
# TestItem.runtest(...) should instantiate the TaxBenefitSystem and the Simulation | ||
assert test_item.tax_benefit_system.get_variable("salary") is not None | ||
assert test_item.simulation is not None | ||
|
||
|
||
def test_performance_graph_option_output() -> None: | ||
test_file = TestFile.from_parent(parent=None) | ||
test = { | ||
"input": {"salary": {"2017-01": 2000}}, | ||
"output": {"salary": {"2017-01": 2000}}, | ||
} | ||
test_item = TestItem(test) | ||
test_item = TestItem.from_parent(parent=test_file, test=test) | ||
test_item.options = {"performance_graph": True} | ||
|
||
paths = ["./performance_graph.html"] | ||
|
@@ -169,13 +208,13 @@ def test_performance_graph_option_output() -> None: | |
clean_performance_files(paths) | ||
|
||
|
||
@pytest.mark.skip(reason="Deprecated node constructor") | ||
def test_performance_tables_option_output() -> None: | ||
test_file = TestFile.from_parent(parent=None) | ||
test = { | ||
"input": {"salary": {"2017-01": 2000}}, | ||
"output": {"salary": {"2017-01": 2000}}, | ||
} | ||
test_item = TestItem(test) | ||
test_item = TestItem.from_parent(parent=test_file, test=test) | ||
test_item.options = {"performance_tables": True} | ||
|
||
paths = ["performance_table.csv", "aggregated_performance_table.csv"] | ||
|
@@ -191,6 +230,33 @@ def test_performance_tables_option_output() -> None: | |
clean_performance_files(paths) | ||
|
||
|
||
def test_verbose_option_output(capsys) -> None: | ||
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.
|
||
test_file = TestFile.from_parent(parent=None) | ||
|
||
expected_output_variable = "salary" | ||
expected_output_date = "2017-01" | ||
expected_output_value = 2000 | ||
test = { | ||
"input": {"salary": {"2017-01": 2000}}, | ||
"output": {expected_output_variable: {expected_output_date: expected_output_value}}, | ||
} | ||
|
||
test_item = TestItem.from_parent(parent=test_file, test=test) | ||
|
||
test_item.options = {"verbose": True} | ||
test_item.runtest() | ||
captured = capsys.readouterr() | ||
|
||
# TestItem.runtest should set the trace attribute from the 'verbose' option | ||
assert test_item.simulation.trace is True | ||
|
||
# TestItem.runtest should run print_computation_log | ||
assert captured.out != "" | ||
assert expected_output_variable in captured.out | ||
assert expected_output_date in captured.out | ||
assert str(expected_output_value) in captured.out | ||
|
||
|
||
def clean_performance_files(paths: list[str]) -> None: | ||
for path in paths: | ||
if os.path.isfile(path): | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.