예제 #1
0
    def test_shoulderconfig_validate(self):
        sc = ShoulderConfig()

        sc.add_configuration(Configuration("test_name", "test_value"))
        sc.validate()

        config = Configuration("test_name2", "test_value2")
        config.options = ["test_value2"]
        sc.add_configuration(config)
        sc.validate()

        sc.test_name2 = "val1"
        self.assertRaises(AttributeError, sc.validate)

        sc["test_name2"] = "test_value2"
        sc.validate()
예제 #2
0
    def test_shoulderconfig_add_configuration(self):
        sc = ShoulderConfig()

        sc.add_configuration(Configuration("test_name", "test_value"))
        self.assertTrue(sc._configurations)
        self.assertTrue(sc._configurations["test_name"].name == "test_name")
        self.assertTrue(sc._configurations["test_name"].value == "test_value")

        sc.add_configuration(Configuration("test_name2", "test_value2"))
        self.assertTrue(sc._configurations["test_name"].name == "test_name")
        self.assertTrue(sc._configurations["test_name"].value == "test_value")
        self.assertTrue(sc._configurations["test_name2"].name == "test_name2")
        self.assertTrue(
            sc._configurations["test_name2"].value == "test_value2")

        invalid_config = Configuration(None, None)
        self.assertRaises(AttributeError, sc.add_configuration, invalid_config)
예제 #3
0
    def test_shoulderconfig_getattr(self):
        sc = ShoulderConfig()
        sc.add_configuration(Configuration("test_name", "test_value"))
        value = sc.test_name
        self.assertEqual(value, "test_value")

        try:
            sc.does_not_exist
        except AttributeError as e:
            self.assertTrue(e)
예제 #4
0
    def test_shoulderconfig_getitem(self):
        sc = ShoulderConfig()
        sc.add_configuration(Configuration("test_name", "test_value"))
        value = sc["test_name"]
        self.assertEqual(value, "test_value")

        try:
            sc["does_not_exist"]
        except KeyError as e:
            self.assertTrue(e)
예제 #5
0
 def test_shoulderconfig_help(self):
     with open(os.devnull, 'w') as outfile:
         stdout = sys.stdout
         stderr = sys.stderr
         sys.stdout = outfile
         sys.stderr = outfile
         sc = ShoulderConfig()
         sc.help()
         c = Configuration("test_name", "test_val")
         sc.add_configuration(c)
         sc.help()
         sys.stdout = stdout
         sys.stderr = stderr
예제 #6
0
 def test_configuration_help(self):
     with open(os.devnull, 'w') as outfile:
         stdout = sys.stdout
         stderr = sys.stderr
         sys.stdout = outfile
         sys.stderr = outfile
         c = Configuration("test_name", "test_val")
         c.help()
         c.options = ["test_val", "test_val2"]
         c.help()
         sys.stdout = stdout
         sys.stderr = stderr
예제 #7
0
 def test_shoulderconfig_str(self):
     sc = ShoulderConfig()
     sc.add_configuration(Configuration("test_name", "test_value"))
     self.assertTrue(str(sc))
예제 #8
0
    def test_configuration_validate(self):
        c = Configuration("test_name", "test_val")
        c.validate()

        c.name = None
        self.assertRaises(AttributeError, c.validate)
        c.name = "test_name"

        c.description = None
        self.assertRaises(AttributeError, c.validate)
        c.description = "Description N/A"

        c.options = ["test_option_1", "test_option_2"]
        self.assertRaises(AttributeError, c.validate)

        c.options.append("test_val")
        c.validate()
예제 #9
0
 def test_configuration_str(self):
     c = Configuration("test_name", "test_val")
     self.assertTrue(str(c))
     c.options = ["test_val", "test_val2"]
     self.assertTrue(str(c))
예제 #10
0
 def test_configuration_init(self):
     c = Configuration("test_name", "test_val")
     self.assertIsNotNone(c)
     self.assertEqual(c.name, "test_name")
     self.assertIsNotNone(c.default_value, "test_val")