Skip to content

Commit

Permalink
fix instance freshness problem in test_incomplete_count
Browse files Browse the repository at this point in the history
  • Loading branch information
nihlaeth committed Feb 25, 2017
1 parent 290eb9b commit 472b701
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
15 changes: 5 additions & 10 deletions tests/test_config_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,26 +286,25 @@ class MySection(Section):
assert optional_section.incomplete_count == 1

# missing required value, optional value provided
optional_section = MySection(required=False)
optional_section.element_name = "section"
arguments = vars(parser.parse_args(['--two', '42']))
optional_section.extract_data_from_parser(arguments)
optional_section.validate_data()
assert optional_section.incomplete_count == 1

# required value provided
optional_section = MySection(required=False)
optional_section.element_name = "section"
arguments = vars(parser.parse_args(['--one', '5']))
optional_section.extract_data_from_parser(arguments)
optional_section.validate_data()
assert optional_section.incomplete_count == 0

# test required section
# refresh element instances, since their values are shared across
# section instances
class MySection(Section):
one = IntegerOption()
two = IntegerOption(required=False)
required_section = MySection(required=True)
required_section.element_name = "section"
parser = argparse.ArgumentParser(prog="test application")
required_section.construct_parser(parser)

# missing required value
arguments = vars(parser.parse_args([]))
Expand All @@ -315,17 +314,13 @@ class MySection(Section):
assert required_section.incomplete_count == 0

# missing required value, optional value provided
required_section = MySection(required=True)
required_section.element_name = "section"
arguments = vars(parser.parse_args(['--two', '42']))
required_section.extract_data_from_parser(arguments)
with pytest.raises(MissingData):
required_section.validate_data()
assert required_section.incomplete_count == 0

# required value provided
required_section = MySection(required=True)
required_section.element_name = "section"
arguments = vars(parser.parse_args(['--one', '5']))
required_section.extract_data_from_parser(arguments)
required_section.validate_data()
Expand Down
1 change: 1 addition & 0 deletions user_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ def validate_data(self):
try:
self._elements[element].validate_data()
except MissingData:
print(self.required)
if not self.required:
self.incomplete_count += 1
else:
Expand Down

0 comments on commit 472b701

Please sign in to comment.