def test_to_config(argsdict, argsdict_cfg_str): """ Comments should appear above the option, and the excluded options should not appear. """ cfg_string = export.to_config(cmd_name='Section', argsdict=argsdict) assert cfg_string == argsdict_cfg_str
def test_set_parser_defaults(argsdict, tmpdir): # Build a config parser config = ConfigParser.SafeConfigParser() cfg_file = tmpdir.join("test.cfg") cfg_file.write(export.to_config('test', argsdict)) config.read(str(cfg_file)) # Modify config from the spec defaults config.set("test", "arg2", "3") # Build argparser parser = export.to_argparser('test', argsdict) parser = argutils.set_parser_defaults(parser, config) args = parser.parse_args(["test"]) # Should reflect the modified default assert args.arg2 == 3 # Should warn since it can't find the section parser = export.to_argparser('test2', argsdict) with pytest.warns(UserWarning): argutils.set_parser_defaults(parser, config)
def test_to_config_no_meta(): """If no metadata section included, use the passed description.""" argsdict = OrderedDict({'arg1': {'default': 1}}) cfgstr = export.to_config("test", argsdict, desc="test description") assert cfgstr == """## test description
def test_unordered_warning(argsdict): """Passing unordered argsdicts to to_config should raise an error.""" unordered_args = dict(argsdict) with pytest.raises(ValueError): export.to_config(cmd_name='Section', argsdict=unordered_args)