diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2014-09-16 15:50:04 -0700 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2014-10-22 13:11:55 -0500 |
commit | 5c0b8c2b0229992671e076e74c1256a880381d62 (patch) | |
tree | d112dd9129e8e44fd17633fe13d2a359bdbeebbc /testsuite/Testsrc/Testlib/TestOptions/TestConfigFiles.py | |
parent | 56d2b72b6f8b2e1a27a16dbfdab10f0b83816ceb (diff) | |
download | bcfg2-5c0b8c2b0229992671e076e74c1256a880381d62.tar.gz bcfg2-5c0b8c2b0229992671e076e74c1256a880381d62.tar.bz2 bcfg2-5c0b8c2b0229992671e076e74c1256a880381d62.zip |
testsuite: Added unit tests for new option parsing
Diffstat (limited to 'testsuite/Testsrc/Testlib/TestOptions/TestConfigFiles.py')
-rw-r--r-- | testsuite/Testsrc/Testlib/TestOptions/TestConfigFiles.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/testsuite/Testsrc/Testlib/TestOptions/TestConfigFiles.py b/testsuite/Testsrc/Testlib/TestOptions/TestConfigFiles.py new file mode 100644 index 000000000..aee2ff666 --- /dev/null +++ b/testsuite/Testsrc/Testlib/TestOptions/TestConfigFiles.py @@ -0,0 +1,48 @@ +"""test reading multiple config files.""" + +import argparse + +from Bcfg2.Options import Option, PathOption, ConfigFileAction, get_parser, \ + new_parser + +from testsuite.Testsrc.Testlib.TestOptions import make_config, OptionTestCase + + +class TestConfigFiles(OptionTestCase): + def setUp(self): + self.options = [ + PathOption(cf=("test", "config2"), action=ConfigFileAction), + PathOption(cf=("test", "config3"), action=ConfigFileAction), + Option(cf=("test", "foo")), + Option(cf=("test", "bar")), + Option(cf=("test", "baz"))] + self.results = argparse.Namespace() + new_parser() + self.parser = get_parser(components=[self], namespace=self.results) + + @make_config({"test": {"baz": "baz"}}) + def test_config_files(self, config3): + """read multiple config files.""" + # Because make_config() generates temporary files for the + # configuration, we have to work backwards here. first we + # generate config3, then we generate config2 (which includes a + # reference to config3), then we finally generate the main + # config file, which contains a reference to config2. oh how + # I wish we could use context managers here... + + @make_config({"test": {"bar": "bar", "config3": config3}}) + def inner1(config2): + @make_config({"test": {"foo": "foo", "config2": config2}}) + def inner2(config): + self.parser.parse(["-C", config]) + self.assertEqual(self.results.foo, "foo") + self.assertEqual(self.results.bar, "bar") + self.assertEqual(self.results.baz, "baz") + + inner2() + + inner1() + + def test_no_config_file(self): + """fail to read config file.""" + self.assertRaises(SystemExit, self.parser.parse, []) |