class TestCommandline(unittest.TestCase, TestConfigSourceHelper): # Note: bool is "half-way" supported. Only value-less parameters # are typed as bool (eg "--force", not "--force=True") supported_types = (str, list, bool) simple_cmdline = [ '--home=mydata', '--processes=4', '--force', # note implicit boolean typing '--extra=foo', '--extra=bar', '--expires=2014-10-15', '--lastrun=2014-10-15 14:32:07' ] complex_cmdline = [ '--home=mydata', '--processes=4', '--force=True', '--extra=foo', '--extra=bar', '--mymodule-force=False', '--mymodule-extra=foo', '--mymodule-extra=baz', '--mymodule-expires=2014-10-15', '--mymodule-arbitrary-nesting-depth=works', '--extramodule-unique' ] def setUp(self): super(TestCommandline, self).setUp() # this means we lack typing information self.simple = Commandline(self.simple_cmdline) self.complex = Commandline(self.complex_cmdline) # Overrides of TestHelper.test_get, .test_typed and and due to # limitations of Commandline (carries almost no typeinfo) def test_get(self): self.assertEqual(self.simple.get("home"), "mydata") self.assertEqual(self.simple.get("processes"), "4") self.assertEqual(self.simple.get("force"), True) self.assertEqual(self.simple.get("extra"), ['foo', 'bar']) # note typed! self.assertEqual(self.simple.get("expires"), "2014-10-15") self.assertEqual(self.simple.get("lastrun"), "2014-10-15 14:32:07") def test_typed(self): for key in self.simple.keys(): # these should be typed as bool and list, respectively if key in ("force", "extra"): self.assertTrue(self.simple.typed(key)) else: self.assertFalse(self.simple.typed(key)) def test_config_subsections(self): # this case uses valued parameter for --force et al, which # cannot be reliably converted to bools using only intrinsic # information self.supported_types = (str, list) super(TestCommandline, self).test_config_subsections() def test_set(self): self.simple.set("home", "away from home") self.assertEqual(self.simple.get("home"), "away from home")
class TestCommandline(unittest.TestCase, TestConfigSourceHelper): # Note: bool is "half-way" supported. Only value-less parameters # are typed as bool (eg "--force", not "--force=True") supported_types = (str, list, bool) simple_cmdline = ['--home=mydata', '--processes=4', '--force', # note implicit boolean typing '--extra=foo', '--extra=bar', '--expires=2014-10-15', '--lastrun=2014-10-15 14:32:07'] complex_cmdline = ['--home=mydata', '--processes=4', '--force=True', '--extra=foo', '--extra=bar', '--mymodule-force=False', '--mymodule-extra=foo', '--mymodule-extra=baz', '--mymodule-expires=2014-10-15', '--mymodule-arbitrary-nesting-depth=works', '--extramodule-unique'] def setUp(self): super(TestCommandline, self).setUp() # this means we lack typing information self.simple = Commandline(self.simple_cmdline) self.complex = Commandline(self.complex_cmdline) # Overrides of TestHelper.test_get, .test_typed and and due to # limitations of Commandline (carries almost no typeinfo) def test_get(self): self.assertEqual(self.simple.get("home"), "mydata") self.assertEqual(self.simple.get("processes"), "4") self.assertEqual(self.simple.get("force"), True) self.assertEqual(self.simple.get("extra"), ['foo','bar']) # note typed! self.assertEqual(self.simple.get("expires"), "2014-10-15") self.assertEqual(self.simple.get("lastrun"), "2014-10-15 14:32:07") def test_typed(self): for key in self.simple.keys(): # these should be typed as bool and list, respectively if key in ("force", "extra"): self.assertTrue(self.simple.typed(key)) else: self.assertFalse(self.simple.typed(key)) def test_config_subsections(self): # this case uses valued parameter for --force et al, which # cannot be reliably converted to bools using only intrinsic # information self.supported_types = (str, list) super(TestCommandline, self).test_config_subsections() def test_set(self): self.simple.set("home", "away from home") self.assertEqual(self.simple.get("home"), "away from home")