Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
- Content of --help sections were accumulating
  • Loading branch information
GuillaumeLeclerc committed Apr 7, 2021
1 parent 06d5b39 commit b68a317
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fastargs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def augment_argparse(self, parser):
previous_epilog = ""
while True:
epilog = ""
table_content = [['Name', 'Default', 'Constraint', 'Description']]
for sec_path, entries in self.sections_to_entries.items():
table_content = [['Name', 'Default', 'Constraint', 'Description']]
for path in entries:
param = self.entries[path]
if not param.section.is_enabled(self):
Expand Down
27 changes: 27 additions & 0 deletions tests/test_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,33 @@ def test_flag(self):
self.assertTrue(cfg['a.a'])
self.assertFalse(cfg['a.b'])

def test_duplicate_sections(self):
Section('a').params(
a=Param(int)
)
Section('b').params(
b=Param(int)
)

cfg = get_current_config()
parser = argparse.ArgumentParser(description='Test lib')

def fake_exit(*args, **kwargs):
pass

fakeio = io.StringIO("")

with patch('sys.argv', ['pp', '--help']):
with patch('sys.exit', fake_exit):
with patch('sys.stdout', fakeio):
cfg.augment_argparse(parser)
cfg.collect_argparse_args(parser)

output = fakeio.getvalue()

self.assertEqual(output.count('a.a'), 1)
self.assertEqual(output.count('b.b'), 1)


if __name__ == '__main__':
unittest.main()

0 comments on commit b68a317

Please sign in to comment.