def test_store(self, cfgparser_mock): node = dut.DucoNode(111, 222) cfgparser_mock_object = MagicMock(spec=dut.ConfigParser) node._store(cfgparser_mock_object) section = 'Node111' cfgparser_mock_object.add_section.assert_called_once_with(section) cfgparser_mock_object.set.assert_any_call(section, 'number', '111') cfgparser_mock_object.set.assert_any_call(section, 'address', '222') cfgparser_mock_object.set.assert_any_call(section, 'blacklist', False)
def test_load_fail_no_option(self, cfgparser_mock): node = dut.DucoNode(111, 222) cfgparser_mock_object = MagicMock(spec=dut.ConfigParser) cfgparser_mock_object.get.side_effect = NoOptionError( 'blacklist', 'some message for missing config parser option') node._load(cfgparser_mock_object) self.assertEqual(int(node.number), 111) self.assertEqual(int(node.address), 222) self.assertEqual(node.blacklist, False)
def test_load(self, cfgparser_mock): node = dut.DucoNode(111, 222) cfgparser_mock_object = MagicMock(spec=dut.ConfigParser) cfgparser_mock_object.get.side_effect = self.load_test_side_effect cfgparser_mock_object.getboolean.side_effect = self.load_test_side_effect node._load(cfgparser_mock_object) self.assertEqual(node.name, 'mocked device for utest') self.assertEqual(int(node.number), 888) self.assertEqual(int(node.address), 666) self.assertEqual(node.blacklist, True)
def test_store_single_node(self, cfgparser_mock): cfgparser_mock_object = MagicMock(spec=dut.ConfigParser) cfgparser_mock.return_value = cfgparser_mock_object print(cfgparser_mock_object) open_mock = mock_open() itf = dut.DucoInterface(self.MOCK_PORT_NAME, self.MOCK_CFG_FILE) node = dut.DucoNode('11', '22', itf) itf.nodes.append(node) with patch('duco.ducobox.open', open_mock, create=True): itf.store() open_mock.assert_called_once_with(self.MOCK_CFG_FILE, 'w')
def test_sample(self): node = dut.DucoNode(111, 222) node.sample() self.assertEqual(node.get_value(dut.HUMIDITY_STR), None) self.assertEqual(node.get_value(dut.CO2_STR), None) self.assertEqual(node.get_value(dut.TEMPERATURE_STR), None)
def test_no_equality(self): node1 = dut.DucoNode(333, 444) node2 = dut.DucoNode(222, 445) self.assertNotEqual(node1, node2)
def test_creation_float(self): node = dut.DucoNode(333.0, 444.0) self.assertEqual(int(float(node.number)), 333) self.assertEqual(int(float(node.address)), 444)
def test_creation_str(self): node = dut.DucoNode('333', '444') self.assertEqual(int(node.number), 333) self.assertEqual(int(node.address), 444)
def test_creation_int(self): node = dut.DucoNode(333, 444) self.assertEqual(int(node.number), 333) self.assertEqual(int(node.address), 444) self.assertIsNotNone(node.name)
def test_stringify(self): node = dut.DucoNode(111, 222) self.assertTrue('111' in str(node)) self.assertTrue('222' in str(node))