Skip to content
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 regression on YAML tests runner cache for tax benefit systems with reforms or extensions #825

Merged
merged 13 commits into from
Mar 5, 2019

Conversation

sandcha
Copy link
Collaborator

@sandcha sandcha commented Feb 8, 2019

Bug fix

  • Fixes regression introduced by Core v25 on YAML tests runner (tools/test_runner)
    • Updates reforms value type when one reform only is given in yaml test
  • Updates reforms and extensions recognition in yaml tests runner cache

Every known tax benefit system is recognised in the cache by a key built with reforms value.
When we defined one reform only in the tax benefit system, the key was built with a string value instead of list value. This had an unexpected effect: reforms name with same characters (in different order) looked identical.

@sandcha sandcha requested review from fpagnoux and Morendil February 8, 2019 15:22
@sandcha sandcha changed the title Fix regression on yaml tests cache for reforms Fix regression on yaml tests runner cache for tax benefit systems with reforms Feb 8, 2019
@bonjourmauko bonjourmauko added kind:fix Bugs are defects and failure demand. and removed in progress labels Feb 10, 2019
Copy link
Contributor

@Morendil Morendil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly optional feedback (we can add more tests to better document the current behaviour and preserve against regression) that could be left to a future PR, except that I'd prefer to see lines 40-47 in the test removed unless there's a good reason for them that I missed.

assert excinfo.value.variable_name == "unknown_variable"


class reform_ab(Reform):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you find it necessary to have these lines 40-47 in the test? Deleting them, it seems that they are not missed, and that's expected since we mocked out the part that uses actual Python import and class loading… but maybe I'm missing something.

Copy link
Collaborator Author

@sandcha sandcha Feb 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry! I just forgot to remove them. Done.

openfisca_core/tools/test_runner.py Show resolved Hide resolved

ab_tax_benefit_system = _get_tax_benefit_system(baseline, 'ab', extensions)
ba_tax_benefit_system = _get_tax_benefit_system(baseline, 'ba', extensions)
assert ab_tax_benefit_system != ba_tax_benefit_system
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's interesting to see it tested that way, it's not quite what I was expecting - and I can see how it adds value.

As I read this, we're testing only the caching mechanism; the test doesn't show anything about the "string -> list" conversion mechanism that provides some flexibility in how tests are written.

It would be a good idea to have one test showing the list usage and one test showing the string usage.

Similarly, for the cache it would be a good idea to show when two reform/extension specs lead to the same TaxBenefitSsytem object and when they don't.

For instance, the frozenset() implementation implies that

_get_tax_benefit_system(baseline, ['one', 'two'], extensions)

is the same object as

_get_tax_benefit_system(baseline, ['two', 'one'], extensions)

…but do we really want that? Can we say for sure that it doesn't matter in what order we apply two different reforms? If order matters, we should replace frozenset() by tuple() instead.

baseline = TaxBenefitSystem()
extensions = []

ab_tax_benefit_system = _get_tax_benefit_system(baseline, 'ab', extensions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest inlining the extensions value - it draws attention away from what's interesting which is the reforms parameter.

@fpagnoux fpagnoux changed the title Fix regression on yaml tests runner cache for tax benefit systems with reforms Fix regression on YAML tests runner cache for tax benefit systems with reforms Feb 13, 2019
@sandcha sandcha self-assigned this Feb 27, 2019
@Morendil
Copy link
Contributor

Rebased.

assert excinfo.value.variable_name == "unknown_variable"


def test_tax_benefit_systems_with_reform_cache():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these tests say all we want to say, for reforms.

It seems very likely we have a latent bug of the same kind but for extensions. If you have time, it would be good to have the same three tests but for extensions; or if you prefer we can open an issue and leave that for a later PR.

@sandcha sandcha changed the title Fix regression on YAML tests runner cache for tax benefit systems with reforms Fix regression on YAML tests runner cache for tax benefit systems with reforms or extensions Mar 5, 2019
@sandcha sandcha merged commit aa37fc1 into master Mar 5, 2019
@sandcha sandcha deleted the yaml-reform-format branch March 5, 2019 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:fix Bugs are defects and failure demand.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants