Example #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())
Example #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())
Example #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))
Example #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())
Example #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())
Example #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())
Example #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())
Example #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())
Example #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)
Example #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)
Example #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))
Example #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())
Example #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))
Example #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))
Example #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())
Example #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())
Example #17
0
 def test_get_number_with_default_value(self):
     version = Version()
     self.assertEqual(0, version.number)
Example #18
0
 def test_init_config_with_int_value(self):
     with self.assertRaises(TypeError):
         PropertyContainer(name='key', config=123, version=Version())
Example #19
0
 def test_init_name_with_int_value(self):
     with self.assertRaises(TypeError):
         PropertyContainer(name=123,
                           config=MemoryConfig(),
                           version=Version())
Example #20
0
 def test_get_for_nonexistent_key(self):
     prop = Property('key', 1, int, MemoryConfig(), Version())
     self.assertEqual(1, prop.get())
Example #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())
Example #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())
Example #23
0
 def test_str(self):
     version = Version()
     self.assertEqual('0', str(version))
Example #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())
Example #25
0
 def test_repr(self):
     version = Version()
     self.assertEqual('Version(0)', repr(version))
Example #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())
Example #27
0
 def test_get_changed_with_default_value(self):
     version = Version()
     self.assertEqual(EventHandler, type(version.changed))
Example #28
0
 def test_set_number_with_int_value(self):
     version = Version()
     version.number = 2
     self.assertEqual(2, version.number)