Refactor decision logic into its own object

In dealing with the decision logic in the StyleGuide recently I
recognized that the logic really doesn't belong strictly on the
StyleGuide. A separate object makes perfect sense especially from the
perspective of testability. This is a minor refactor intended solely to
facilitate further testing and perhaps making the logic easier to
understand for others.
This commit is contained in:
Ian Cordasco 2017-06-01 20:36:37 -05:00
parent feec0754bd
commit 7fef0af0f5
No known key found for this signature in database
GPG key ID: 656D3395E4A9791A
2 changed files with 112 additions and 56 deletions

View file

@ -183,22 +183,16 @@ def test_should_report_error(select_list, ignore_list, error_code, expected):
)
def test_decision_for_logic(select, ignore, extend_select, enabled_extensions,
error_code, expected):
"""Verify the complicated logic of StyleGuide._decision_for.
I usually avoid testing private methods, but this one is very important in
our conflict resolution work in Flake8.
"""
guide = style_guide.StyleGuide(
"""Verify the complicated logic of DecisionEngine.decision_for."""
decider = style_guide.DecisionEngine(
create_options(
select=select, ignore=ignore,
extended_default_select=extend_select,
enable_extensions=enabled_extensions,
),
listener_trie=None,
formatter=None,
)
assert guide._decision_for(error_code) is expected
assert decider.decision_for(error_code) is expected
@pytest.mark.parametrize('error_code,physical_line,expected_result', [