def test_jsonvars(self): sh = MockSmartHome() conf = {'type': 'num', 'eval': '2'} item = lib.item.Item(config=conf, parent=sh, smarthome=sh, path='test_item01') item.set('42') self.assertDictEqual(item.jsonvars(),{'attributes': {}, 'value': 42, 'type': 'num', 'children': [], 'id': 'test_item01', 'name': 'test_item01'})
def test_to_json(self): import json sh = MockSmartHome() conf = {'type': 'num', 'eval': '2'} item = lib.item.Item(config=conf, parent=sh, smarthome=sh, path='test_item01') item.set('42') expected = json.dumps({'attributes': {}, 'value': 42, 'type': 'num', 'children': [], 'id': 'test_item01', 'name': 'test_item01'}, sort_keys=True, indent=2) self.assertEqual(item.to_json(), expected)
def test_call(self): if verbose == True: logger.warning('') logger.warning('===== test_call:') sh = MockSmartHome() conf = {'type': 'num', 'autotimer': '5m = 42 = compat_1.2'} item = lib.item.Item(config=conf, parent=sh, smarthome=sh, path='test_item01') item(12) self.assertEqual(12, item._value) self.assertEqual(12, item()) conf = {'type': 'num', 'eval': '2'} item = lib.item.Item(config=conf, parent=sh, smarthome=sh, path='test_item01') item(12) self.assertEqual(0, item()) item.set(12) self.assertEqual(12, item())
def test_call(self): sh = MockSmartHome() conf = {'type': 'num', 'autotimer': '5m = 42 = compat_1.2'} item = lib.item.Item(config=conf, parent=sh, smarthome=sh, path='test_item01') item(12) self.assertEqual(12, item._value) self.assertEqual(12, item()) conf = {'type': 'num', 'eval': '2'} item = lib.item.Item(config=conf, parent=sh, smarthome=sh, path='test_item01') item(12) self.assertEqual(0, item()) item.set(12) self.assertEqual(12, item())
def test_set(self): if verbose == True: logger.warning('') logger.warning('===== test_set:') sh = MockSmartHome() conf = {'type': 'num', 'autotimer': '5m = 42 = compat_1.2'} item = lib.item.Item(config=conf, parent=sh, smarthome=sh, path='test_item01') item.set(12) self.assertEqual(12, item._value) item.set('13') self.assertEqual(13, item._value) self.assertIsNone(item.set('qwe')) self.assertEqual(13, item._value) item.set('14')
def test_set(self): sh = MockSmartHome() conf = {'type': 'num', 'autotimer': '5m = 42 = compat_1.2'} item = lib.item.Item(config=conf, parent=sh, smarthome=sh, path='test_item01') item.set(12) # print(item.type()) # print(item.cast) self.assertEqual(12, item._value) item.set('13') self.assertEqual(13, item._value) self.assertIsNone(item.set('qwe')) self.assertEqual(13, item._value) item.set('14')