summaryrefslogtreecommitdiffstats
path: root/testsuite/Testsrc/Testlib/TestOptions/TestWildcards.py
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2014-11-10 19:55:53 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2014-11-10 19:55:53 +0100
commit3f32d999c6e75af57058e389a07d1ab6a62eaebb (patch)
tree6055de1e6a541e2e5e4a721058f414a0e50258b6 /testsuite/Testsrc/Testlib/TestOptions/TestWildcards.py
parentda93fb540c28be3341ec0d37d1fbd90153fb750c (diff)
parent0e133c157755908d05c44c3a36b1dc0668e1d111 (diff)
downloadbcfg2-3f32d999c6e75af57058e389a07d1ab6a62eaebb.tar.gz
bcfg2-3f32d999c6e75af57058e389a07d1ab6a62eaebb.tar.bz2
bcfg2-3f32d999c6e75af57058e389a07d1ab6a62eaebb.zip
Merge branch 'options-unit-tests' of https://github.com/stpierre/bcfg2
* 'options-unit-tests' of https://github.com/stpierre/bcfg2: Options: Fixed non-path database name parsing Options: further command registry fixes Options: gather as much data from config file first Options: fix path canonicalization and file-like objects testsuite: unlink temporary files Options: ensure <repository> macros are always fixed up DBSettings: fix up <repository> in database name testsuite: better debug capturing for options tests call shutdown on subcommand registries fixed some places where plugin loading should fail silently testsuite: Added unit tests for new option parsing testsuite: capture stderr by default Test failure to parse config file when bcfg2.conf exists testsuite: skip nested exclusive option group test on py2.6 testsuite: Added unit tests for new option parsing
Diffstat (limited to 'testsuite/Testsrc/Testlib/TestOptions/TestWildcards.py')
-rw-r--r--testsuite/Testsrc/Testlib/TestOptions/TestWildcards.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/testsuite/Testsrc/Testlib/TestOptions/TestWildcards.py b/testsuite/Testsrc/Testlib/TestOptions/TestWildcards.py
new file mode 100644
index 000000000..da196a912
--- /dev/null
+++ b/testsuite/Testsrc/Testlib/TestOptions/TestWildcards.py
@@ -0,0 +1,47 @@
+"""test wildcard options."""
+
+import argparse
+
+from Bcfg2.Options import Option, Parser
+from testsuite.Testsrc.Testlib.TestOptions import OptionTestCase, make_config
+
+
+class TestWildcardOptions(OptionTestCase):
+ """test parsing wildcard options."""
+ config = {
+ "foo": {
+ "test1": "test1",
+ "test2": "test2",
+ "thing1": "thing1",
+ "thing2": "thing2",
+ "foo": "foo"
+ }
+ }
+
+ def setUp(self):
+ # parsing options can modify the Option objects themselves.
+ # that's probably bad -- and it's definitely bad if we ever
+ # want to do real on-the-fly config changes -- but it's easier
+ # to leave it as is and set the options on each test.
+ self.options = [
+ Option(cf=("foo", "*"), dest="all"),
+ Option(cf=("foo", "test*"), dest="test"),
+ Option(cf=("foo", "bogus*"), dest="unmatched"),
+ Option(cf=("bar", "*"), dest="no_section"),
+ Option(cf=("foo", "foo"))]
+
+ @make_config(config)
+ def test_wildcard_options(self, config_file):
+ """parse wildcard options."""
+ result = argparse.Namespace()
+ parser = Parser(components=[self], namespace=result)
+ parser.parse(argv=["-C", config_file])
+
+ self.assertDictEqual(result.all, {"test1": "test1",
+ "test2": "test2",
+ "thing1": "thing1",
+ "thing2": "thing2"})
+ self.assertDictEqual(result.test, {"test1": "test1",
+ "test2": "test2"})
+ self.assertDictEqual(result.unmatched, {})
+ self.assertDictEqual(result.no_section, {})