def test_init_config_with_int_value(self): with self.assertRaises(TypeError): Property(name='key', default=1, type=int, config=123, version=Version())
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())
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))
def test_init_name_with_int_value(self): with self.assertRaises(TypeError): Property(name=123, default=1, type=int, config=MemoryConfig(), version=Version())
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())
def test_init_cast_with_none_value(self): with self.assertRaises(ValueError): Property(name='key', default=1, type=None, config=MemoryConfig(), version=Version())
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())
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())
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)
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)
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))
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())
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))
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))
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())
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())
def test_get_number_with_default_value(self): version = Version() self.assertEqual(0, version.number)
def test_init_config_with_int_value(self): with self.assertRaises(TypeError): PropertyContainer(name='key', config=123, version=Version())
def test_init_name_with_int_value(self): with self.assertRaises(TypeError): PropertyContainer(name=123, config=MemoryConfig(), version=Version())
def test_get_for_nonexistent_key(self): prop = Property('key', 1, int, MemoryConfig(), Version()) self.assertEqual(1, prop.get())
def test_get_for_nonexistent_key_with_callable_default_value(self): prop = Property('key', lambda: 1, int, MemoryConfig(), Version()) self.assertEqual(1, prop.get())
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())
def test_str(self): version = Version() self.assertEqual('0', str(version))
def test_as_bool_with_nonexistent_key(self): config = MemoryConfig() container = PropertyContainer('key', config, version=Version()) self.assertEqual(True, container.as_bool(True).get())
def test_repr(self): version = Version() self.assertEqual('Version(0)', repr(version))
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())
def test_get_changed_with_default_value(self): version = Version() self.assertEqual(EventHandler, type(version.changed))
def test_set_number_with_int_value(self): version = Version() version.number = 2 self.assertEqual(2, version.number)