Skip to content

Commit

Permalink
Capture printed trace log in test
Browse files Browse the repository at this point in the history
And do not init simulation before TestItem.runtest that will instanciate it with trace options
  • Loading branch information
sandcha committed Nov 26, 2024
1 parent 6a52fb2 commit a5c7620
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions tests/core/tools/test_runner/test_yaml_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def __init__(self, test, **kwargs) -> None:
super().__init__(name="", path="", baseline_tax_benefit_system=TaxBenefitSystem(), test=test, options={}, **kwargs)

self.tax_benefit_system: TaxBenefitSystem = self.baseline_tax_benefit_system
self.simulation = Simulation()


class TestVariable(Variable):
Expand Down Expand Up @@ -206,20 +205,27 @@ def test_performance_tables_option_output() -> None:
clean_performance_files(paths)


def test_trace() -> None:
def test_trace(capsys) -> None:
testFile = TestFile.from_parent(parent=None)
test = {
"input": {"salary": {"2017-01": 2000}},
"output": {"salary": {"2017-01": 2000}},
}
test_item = TestItem.from_parent(parent=testFile, test=test)
test_item.options = {"verbose": True}


# TestItem init should instanciate the TaxBenefitSystem
assert test_item.tax_benefit_system.get_variable("salary") is not None


test_item.options = {"verbose": True}
test_item.runtest()

assert test_item.simulation.trace
captured = capsys.readouterr()

# TestItem.runtest should set the trace attribute from the 'verbose' option
assert test_item.simulation.trace is True
assert test_item

# TestItem.runtest should run print_computation_log
assert captured.out is not ''


def clean_performance_files(paths: list[str]) -> None:
Expand Down

0 comments on commit a5c7620

Please sign in to comment.