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_init_version_with_int_value(self): with self.assertRaises(TypeError): Property(name='key', default=1, type=int, config=MemoryConfig(), version=123)
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_init_config_with_int_value(self): with self.assertRaises(TypeError): Property(name='key', default=1, type=int, config=123, version=Version())
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_cast_with_none_value(self): with self.assertRaises(ValueError): Property(name='key', default=1, type=None, config=MemoryConfig(), version=Version())
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_init_name_with_none_value(self): with self.assertRaises(TypeError): Property(name=None, default=1, type=int, config=MemoryConfig(), version=Version())
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_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_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_nonexistent_key(self): prop = Property('key', 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())