def test_005(self): """Non-zero init.""" global _MOCK _MOCK = EthernetRelayMock(num_relays=16, init_state='1010101010101010') with httmock.HTTMock(mock_relay): relay = devices.EthernetRelay() self.assertEqual(sum(relay.state()), 8)
def test_006(self): """Test verify.""" with httmock.HTTMock(mock_relay): relay = devices.EthernetRelay() relay._relays[0] = True # this should be disallowed anyways with self.assertRaises(ValueError): relay.verify()
def test_002(self): """Test all off.""" with httmock.HTTMock(mock_relay): relay = devices.EthernetRelay() relay.all_on() relay.all_off() self.assertFalse(any(relay.state()))
def test_001(self): """Test all on.""" with httmock.HTTMock(mock_relay): relay = devices.EthernetRelay() relay.all_off() relay.all_on() self.assertTrue(all(relay.state()))
def test_007(self): """Test check_index.""" with httmock.HTTMock(mock_relay): relay = devices.EthernetRelay() with self.assertRaises(IndexError): relay.check_index(-1) with self.assertRaises(IndexError): relay.check_index(16)
def test_004(self): """Test toggle.""" with httmock.HTTMock(mock_relay): relay = devices.EthernetRelay() for i in range(len(relay.state())): relay.toggle(i) self.assertTrue(all(relay.state())) for i in range(len(relay.state())): relay.toggle(i) self.assertFalse(any(relay.state()))
def test_003(self): """Test turn on and turn off.""" with httmock.HTTMock(mock_relay): relay = devices.EthernetRelay() for i in range(len(relay.state())): relay.turn_on(i) self.assertTrue(all(relay.state())) for i in range(len(relay.state())): relay.turn_off(i) self.assertFalse(any(relay.state()))
def test_010(self): """Test init with 30001.""" with httmock.HTTMock(mock_relay): relay = devices.EthernetRelay(url_base='http://192.168.1.4/30001') self.assertTrue(len(relay.state()), 16)
def test_009(self): """Test unable to parse content.""" with httmock.HTTMock(mock_relay): with self.assertRaises(RuntimeError): devices.EthernetRelay(url_base='http://192.168.1.4/20000')
def test_008(self): """Test bad status code.""" with httmock.HTTMock(mock_relay): with self.assertRaises(RuntimeError): devices.EthernetRelay(url_base='http://192.168.1.4/40000')
def test_000(self): """Test init with 30000.""" with httmock.HTTMock(mock_relay): devices.EthernetRelay()