示例#1
0
class TestGeneralConfig(TestBase):
    """
    A group of unittests to ensure correct functionality of GeneralConfig
    """
    def setUp(self):
        self.config = GeneralConfig()

    def test___init__(self):
        defaults = {'test': '1', 'override_me': 'wrong_value'}
        arg_dict = {'arg_dict': 'some_value', 'override_me': 'expected_value'}
        general_config = GeneralConfig(defaults=defaults, **arg_dict)

        self.assertEqual(getattr(general_config, 'test'), '1')
        self.assertEqual(getattr(general_config, 'arg_dict'), 'some_value')
        self.assertEqual(getattr(general_config, 'override_me'),
                         'expected_value')

    def test___getattr__(self):
        self.config.test = 1
        self.assertTrue(self.config.test, 1)

    def test___setattr__(self):
        self.config.test = 1
        self.assertEqual(self.config.test, 1)

    def test___setattr___Not_Set_Sentinel(self):
        # The general config class should refuse
        # to set attributes to an instance of NotSetSentinel
        self.config.test = NotSetSentinel()
        self.assertEqual(self.config.test, None)

    def test_update(self):
        # The function should perform similarly to a dict's update method
        test_dict = {
            'cool_attribute': 'cool_value',
            'not_set': NotSetSentinel()
        }
        self.config.update(**test_dict)
        self.assertEquals(self.config.cool_attribute, 'cool_value')
        self.assertEquals(self.config.not_set, None)

    def test___getitem__(self):
        self.config.test = 1
        self.assertEqual(self.config['test'], 1)

    def test___setitem__(self):
        self.config['test'] = 1
        self.assertEqual(self.config['test'], 1)

    def test___delitem__(self):
        self.config['test'] = 1
        self.assertEqual(self.config['test'], 1)
        del self.config['test']
        self.assertRaises(KeyError, self.config.__getitem__, 'test')

    def test___contains__(self):
        self.config['test'] = 1
        self.assertTrue('test' in self.config)
        self.assertFalse('not_here' in self.config)
示例#2
0
    def test___init__(self):
        defaults = {'test': '1', 'override_me': 'wrong_value'}
        arg_dict = {'arg_dict': 'some_value', 'override_me': 'expected_value'}
        general_config = GeneralConfig(defaults=defaults, **arg_dict)

        self.assertEqual(getattr(general_config, 'test'), '1')
        self.assertEqual(getattr(general_config, 'arg_dict'), 'some_value')
        self.assertEqual(getattr(general_config, 'override_me'),
                         'expected_value')
示例#3
0
 def setUp(self):
     self.config = GeneralConfig()
示例#4
0
 def setUp(self):
     self.config = GeneralConfig()
示例#5
0
class TestGeneralConfig(TestBase):
    """
    A group of unittests to ensure correct functionality of GeneralConfig
    """
    def setUp(self):
        self.config = GeneralConfig()

    def test___init__(self):
        defaults = {
            'test': '1',
            'override_me': 'wrong_value'
        }
        arg_dict = {
            'arg_dict': 'some_value',
            'override_me': 'expected_value'
        }
        general_config = GeneralConfig(defaults=defaults, **arg_dict)

        self.assertEqual(getattr(general_config, 'test'), '1')
        self.assertEqual(getattr(general_config, 'arg_dict'), 'some_value')
        self.assertEqual(getattr(general_config, 'override_me'), 'expected_value')

    def test___getattr__(self):
        self.config.test = 1
        self.assertTrue(self.config.test, 1)

    def test___setattr__(self):
        self.config.test = 1
        self.assertEqual(self.config.test, 1)

    def test___setattr___Not_Set_Sentinel(self):
        # The general config class should refuse
        # to set attributes to an instance of NotSetSentinel
        self.config.test = NotSetSentinel()
        self.assertEqual(self.config.test, None)

    def test_update(self):
        # The function should perform similarly to a dict's update method
        test_dict = {
            'cool_attribute': 'cool_value',
            'not_set': NotSetSentinel()
        }
        self.config.update(**test_dict)
        self.assertEquals(self.config.cool_attribute, 'cool_value')
        self.assertEquals(self.config.not_set, None)

    def test___getitem__(self):
        self.config.test = 1
        self.assertEqual(self.config['test'], 1)

    def test___setitem__(self):
        self.config['test'] = 1
        self.assertEqual(self.config['test'], 1)

    def test___delitem__(self):
        self.config['test'] = 1
        self.assertEqual(self.config['test'], 1)
        del self.config['test']
        self.assertRaises(KeyError, self.config.__getitem__, 'test')

    def test___contains__(self):
        self.config['test'] = 1
        self.assertTrue('test' in self.config)
        self.assertFalse('not_here' in self.config)