Exemplo n.º 1
0
 def test_disconnect(self):
     c = WrapperBaseConnector()
     c2 = BaseConnector()
     c._get_channels()[0].connect(ExportChannel(Measure.pressureCurrent, lambda: 0))
     c._get_channels()[1].connect(ExportChannel(Measure.pressureLast, lambda: 0))
     c._link = c2
     c2._link = c
     self.assertEqual(True, c._get_channels()[0].connected)
     self.assertEqual(True, c._get_channels()[1].connected)
     c.disconnect()
     self.assertEqual(None, c._link)
     self.assertEqual(None, c2._link)
     self.assertEqual(False, c._get_channels()[0].connected)
     self.assertEqual(False, c._get_channels()[1].connected)
Exemplo n.º 2
0
 def test__add_connector(self):
     c = Component()
     with self.assertRaises(TypeError):
         c._add_connector(123)
     c1 = BaseConnector()
     c2 = BaseConnector()
     c._connectors = [c1, c2]
     c._add_connector(c1)
     self.assertCountEqual([c1, c2], c._connectors)
     c._connectors = [c1]
     c._add_connector(c1)
     self.assertCountEqual([c1], c._connectors)
     c._connectors = [c1]
     c._add_connector(c2)
     self.assertCountEqual([c1, c2], c._connectors)
Exemplo n.º 3
0
 def test_connected(self):
     c = WrapperBaseConnector()
     self.assertEqual(False, c.connected)
     c._get_channels()[0].connect(ExportChannel(Measure.pressureCurrent, lambda: 0))
     with self.assertRaises(ValueError):
         c.connected
     c._get_channels()[1].connect(ExportChannel(Measure.pressureLast, lambda: 0))
     self.assertEqual(True, c.connected)
     c = BaseConnector()
     c._link = c
     self.assertEqual(True, c.connected)
     c = WrapperBaseConnector()
     c._link = c
     with self.assertRaises(ValueError):
         c.connected
Exemplo n.º 4
0
 def test_channels(self):
     c = BaseConnector()
     self.assertEqual([], c.channels)
     c = WrapperGetChannels()
     self.assertCountEqual([1, 2, 3], c.channels)
Exemplo n.º 5
0
 def test_link(self):
     c = BaseConnector()
     self.assertEqual(None, c.link)
     c._link = c
     self.assertEqual(c, c.link)
Exemplo n.º 6
0
 def test_delegate(self):
     c = BaseConnector()
     d = DummyConnector()
     self.assertEqual(None, c._delegate)
     c._delegate = d
     with self.assertRaises(DelegateError):
         c.link
     with self.assertRaises(DelegateError):
         c.connected
     with self.assertRaises(DelegateError):
         c.channels
     with self.assertRaises(DelegateError):
         c.components
     with self.assertRaises(DelegateError):
         c.imports
     with self.assertRaises(DelegateError):
         c.exports
     with self.assertRaises(DelegateError):
         c.optionals
     with self.assertRaises(DelegateError):
         c.connectable(c)
     with self.assertRaises(DelegateError):
         c.disconnect()
     with self.assertRaises(DelegateError):
         c.connect(c)
     with self.assertRaises(DelegateError):
         c.value(Measure.pressureLast)
Exemplo n.º 7
0
 def test___init__(self):
     c = BaseConnector()
     self.assertEqual(None, c._delegate)
     self.assertEqual(None, c._link)
Exemplo n.º 8
0
 def test_connect(self):
     # Invalid parameter tests
     c = BaseConnector()
     with self.assertRaises(TypeError):
         c.connect(123)
     c2 = BaseConnector()
     c2._delegate = c2
     with self.assertRaises(AssertionError):
         c.connect(c2)
     c2._delegate = None
     c2._link = c
     with self.assertRaises(AssertionError):
         c.connect(c2)
     c = WrapperBaseConnector()
     c2 = WrapperBaseConnector()
     with self.assertRaises(TypeError):
         c.connect(c2)
     # Valid type tests
     c = BaseConnector()
     c2 = BaseConnector()
     c.connect(c2)
     self.assertEqual(True, c.connected)
     self.assertEqual(c2, c._link)
     self.assertEqual(c, c2._link)
     # Test channel linking
     c = WrapperBaseConnector()
     c._channels.append(ExportChannel(Measure.pressureCurrent, lambda: 99))
     c._channels.append(ExportChannel(Measure.pressureLast, lambda: 88))
     c2 = WrapperBaseConnector()
     c2._channels.append(ExportChannel(Measure.pressureCurrent, lambda: 77))
     c2._channels.append(ExportChannel(Measure.pressureLast, lambda: 66))
     c2._channels.append(ExportChannel(Measure.deltaX, lambda: 55))
     c.connect(c2)
     self.assertEqual(77, c._channels[0].import_value())
     self.assertEqual(66, c._channels[1].import_value())
     self.assertEqual(55, c._channels[2].import_value())
     self.assertEqual(99, c2._channels[0].import_value())
     self.assertEqual(88, c2._channels[1].import_value())
     self.assertEqual(None, c2._channels[2].import_value())
Exemplo n.º 9
0
 def test_connectable(self):
     c = BaseConnector()
     c2 = BaseConnector()
     with self.assertRaises(TypeError):
         c.connectable(123)
     self.assertEqual(True, c.connectable(c2))
     c = WrapperBaseConnector()
     c2 = WrapperBaseConnector()
     self.assertEqual(False, c.connectable(c2))
     c._channels.append(ExportChannel(Measure.pressureCurrent, lambda: 0))
     c._channels.append(ExportChannel(Measure.pressureLast, lambda: 0))
     self.assertEqual(False, c.connectable(c2))
     c2._channels.append(ExportChannel(Measure.pressureCurrent, lambda: 0))
     c2._channels.append(ExportChannel(Measure.pressureLast, lambda: 0))
     self.assertEqual(True, c.connectable(c2))
     c._get_channels()[0].connect(ExportChannel(Measure.pressureCurrent, lambda: 0))
     c._get_channels()[1].connect(ExportChannel(Measure.pressureLast, lambda: 0))
     self.assertEqual(False, c.connectable(c2))
Exemplo n.º 10
0
 def test_exports(self):
     c = BaseConnector()
     self.assertEqual(set(), c.exports)
     c = WrapperBaseConnector()
     self.assertEqual({Measure.diameter}, c.exports)
Exemplo n.º 11
0
 def test_optionals(self):
     c = BaseConnector()
     self.assertEqual(set(), c.optionals)
     c = WrapperBaseConnector()
     self.assertEqual({Measure.deltaX}, c.optionals)
Exemplo n.º 12
0
 def test_imports(self):
     c = BaseConnector()
     self.assertEqual(set(), c.imports)
     c = WrapperBaseConnector()
     self.assertEqual({Measure.pressureCurrent, Measure.pressureLast}, c.imports)
Exemplo n.º 13
0
 def test__get_components(self):
     c = BaseConnector()
     self.assertEqual([], c._get_components())
Exemplo n.º 14
0
 def test_components(self):
     c = BaseConnector()
     self.assertEqual([], c.components)
     c = WrapperGetChannels()
     self.assertCountEqual([4, 5, 6], c.components)
Exemplo n.º 15
0
 def test__get_channels(self):
     c = BaseConnector()
     self.assertEqual([], c._get_channels())