def test_close_handle(self): class Foo: def close(self): self.closed = True handle = Handler(override_type=Foo) handle.close() self.assertTrue(handle._connection.closed) handle = Handler(override_type=object) # Should not error handle.close() with self.assertRaises(AttributeError): handle.other()
def test_handler_autoconnect(self): handle = Handler() # Not connected self.assertNotIn('_connection', handle.__dict__) # Since the default is an int, int has a real property handle.real # Connected self.assertIn('_connection', handle.__dict__) self.assertIsNotNone(handle._connection)
def test_handler_del_attr(self): class Foo: pass handle = Handler(override_type=Foo) handle._connection.foo = 11 handle.bar = 15 del (handle.foo) self.assertFalse(hasattr(handle._connection, 'foo')) del (handle._connection.bar) self.assertFalse(hasattr(handle, 'bar'))
def test_handler_attr(self): class Foo: pass handle = Handler(override_type=Foo) # Set on handle handle.bar = 15 # Debug verify on connection self.assertEqual(handle._connection.bar, 15) # Emulate something in connection changing itself handle._connection.foo = 11 # Verify on handler self.assertEqual(handle.foo, 11)
def test_handler_override(self): class Foo: pass handle = Handler(override_type=Foo) self.assertIsInstance(handle._connection, Foo)
def test_handler_simple(self): handle = Handler() self.assertIs(handle._connection, int(0))