예제 #1
0
 def test_init_config_with_int_value(self):
     with self.assertRaises(TypeError):
         Property(name='key',
                  default=1,
                  type=int,
                  config=123,
                  version=Version())
예제 #2
0
    def test_as_float_with_existent_key(self):
        config = MemoryConfig()
        config.set('key', '2')

        container = PropertyContainer('key', config, version=Version())
        self.assertIsInstance(container.as_float(1.0).get(), float)
        self.assertEqual(2, container.as_float(1.0).get())
예제 #3
0
    def test_as_type_for_same_existent_key(self):
        config = MemoryConfig()
        config.set('key', '2')

        container = PropertyContainer('key', config, version=Version())

        self.assertEqual(container.as_type(int, 1), container.as_type(int, 1))
예제 #4
0
 def test_init_name_with_int_value(self):
     with self.assertRaises(TypeError):
         Property(name=123,
                  default=1,
                  type=int,
                  config=MemoryConfig(),
                  version=Version())
예제 #5
0
    def test_as_list_with_existent_key(self):
        config = MemoryConfig()
        config.set('key', ['value'])

        container = PropertyContainer('key', config, version=Version())
        self.assertIsInstance(container.as_list([]).get(), list)
        self.assertEqual(['value'], container.as_list([]).get())
예제 #6
0
 def test_init_cast_with_none_value(self):
     with self.assertRaises(ValueError):
         Property(name='key',
                  default=1,
                  type=None,
                  config=MemoryConfig(),
                  version=Version())
예제 #7
0
    def test_as_dict_with_existent_key(self):
        config = MemoryConfig()
        config.set('key', {'key': 'value'})

        container = PropertyContainer('key', config, version=Version())
        self.assertIsInstance(container.as_dict({}).get(), MutableMapping)
        self.assertEqual({'key': 'value'}, container.as_dict({}).get())
예제 #8
0
 def test_as_str_with_nonexistent_key(self):
     config = MemoryConfig()
     container = PropertyContainer('key', config, version=Version())
     self.assertIsInstance(
         container.as_str('default value').get(), string_types)
     self.assertEqual('default value',
                      container.as_str('default value').get())
예제 #9
0
 def test_init_cast_with_int_value(self):
     prop = Property(name='key',
                     default=1,
                     type=int,
                     config=MemoryConfig(),
                     version=Version())
     self.assertEqual(int, prop.type)
예제 #10
0
 def test_init_name_with_str_value(self):
     prop = Property(name='name',
                     default=1,
                     type=int,
                     config=MemoryConfig(),
                     version=Version())
     self.assertEqual('name', prop.name)
예제 #11
0
 def test_get_updated_with_default_value(self):
     prop = Property(name='key',
                     default=1,
                     type=int,
                     config=MemoryConfig(),
                     version=Version())
     self.assertEqual(EventHandler, type(prop.updated))
예제 #12
0
    def test_as_bool_with_existent_key(self):
        config = MemoryConfig()
        config.set('key', '0')

        container = PropertyContainer('key', config, version=Version())

        self.assertIsInstance(container.as_bool(True).get(), bool)
        self.assertEqual(False, container.as_bool(True).get())
예제 #13
0
    def test_str(self):
        config = MemoryConfig()
        config.set('key', '2')

        prop = Property(name='key',
                        default=1,
                        type=int,
                        config=config,
                        version=Version())
        self.assertEqual('2', str(prop))
예제 #14
0
    def test_on_updated_with_func_value(self):
        prop = Property(name='key',
                        default=1,
                        type=int,
                        config=MemoryConfig(),
                        version=Version())

        def dummy():
            pass

        prop.on_updated(dummy)

        self.assertEqual(1, len(prop.updated))
예제 #15
0
    def test_get_for_invalidated_key(self):
        config = MemoryConfig()
        config.set('key', '2')

        version = Version()

        prop = Property('key', 1, int, config, version)

        self.assertEqual(2, prop.get())

        config.set('key', '3')

        version.number += 1

        self.assertEqual(3, prop.get())
예제 #16
0
    def test_add_updated_with_func_value(self):
        config = MemoryConfig()
        version = Version()
        ev = Event()

        prop = Property(name='key',
                        default=1,
                        type=int,
                        config=config,
                        version=version)

        def dummy(v):
            ev.set()

        prop.updated.add(dummy)

        version.number += 1

        self.assertTrue(ev.is_set())
예제 #17
0
 def test_get_number_with_default_value(self):
     version = Version()
     self.assertEqual(0, version.number)
예제 #18
0
 def test_init_config_with_int_value(self):
     with self.assertRaises(TypeError):
         PropertyContainer(name='key', config=123, version=Version())
예제 #19
0
 def test_init_name_with_int_value(self):
     with self.assertRaises(TypeError):
         PropertyContainer(name=123,
                           config=MemoryConfig(),
                           version=Version())
예제 #20
0
 def test_get_for_nonexistent_key(self):
     prop = Property('key', 1, int, MemoryConfig(), Version())
     self.assertEqual(1, prop.get())
예제 #21
0
 def test_get_for_nonexistent_key_with_callable_default_value(self):
     prop = Property('key', lambda: 1, int, MemoryConfig(), Version())
     self.assertEqual(1, prop.get())
예제 #22
0
    def test_get_for_existent_key(self):
        config = MemoryConfig()
        config.set('key', '2')

        prop = Property('key', 1, int, config, Version())
        self.assertEqual(2, prop.get())
예제 #23
0
 def test_str(self):
     version = Version()
     self.assertEqual('0', str(version))
예제 #24
0
 def test_as_bool_with_nonexistent_key(self):
     config = MemoryConfig()
     container = PropertyContainer('key', config, version=Version())
     self.assertEqual(True, container.as_bool(True).get())
예제 #25
0
 def test_repr(self):
     version = Version()
     self.assertEqual('Version(0)', repr(version))
예제 #26
0
 def test_as_type_with_nonexistent_key(self):
     config = MemoryConfig()
     container = PropertyContainer('key', config, version=Version())
     self.assertIsInstance(container.as_type(int, 1).get(), int)
     self.assertEqual(1, container.as_type(int, 1).get())
예제 #27
0
 def test_get_changed_with_default_value(self):
     version = Version()
     self.assertEqual(EventHandler, type(version.changed))
예제 #28
0
 def test_set_number_with_int_value(self):
     version = Version()
     version.number = 2
     self.assertEqual(2, version.number)