def test_connect_systems(): '''check the connect_systems routine''' r = sysdiag.System('root') s1 = sysdiag.System('s1', parent=r) s2 = sysdiag.System('s2') # parent is None # add some ports s1.add_port(sysdiag.Port('p1', 'type1')) s2.add_port(sysdiag.Port('p2', 'type1')) p_other = sysdiag.Port('p_other', 'other type') s2.add_port(p_other) # failure if no common parents with assert_raises(ValueError): w1 = sysdiag.connect_systems(s1,s2, 'p1', 'p2') r.add_subsystem(s2) w1 = sysdiag.connect_systems(s1,s2, 'p1', 'p2') assert_equal(len(w1.ports), 2) # failure if wrong types of ports: assert_equal(w1.is_connect_allowed(p_other, 'sibling'), False) with assert_raises(TypeError): w = sysdiag.connect_systems(s1,s2, 'p1', 'p_other') # double connection: no change is performed w2 = sysdiag.connect_systems(s1,s2, 'p1', 'p2') assert_is(w2,w1) assert_equal(len(w1.ports), 2)
def connect_systems(source, dest, s_pname='out', d_pname='in'): '''Connect systems `source` to `dest` using port names `s_pname` (default 'out') and `d_pname` (default 'in') with a SignalWire The wire is created if necessary Returns: the wire ''' # Use the generic function: w = sysdiag.connect_systems(source, dest, s_pname, d_pname, wire_cls=SignalWire) return w