def test_hash(self): obj = [0, 1, 2] p = Proxy(obj) with self.assertRaises(TypeError): hash(p) obj = (0, 1, 2) p = Proxy(obj) hash(p)
def test_text_bool(self): obj = "" p = Proxy(obj) if p: self.fail() else: pass
def test_loads(self): obj = Thing(10) p = Proxy(obj) obj2 = pickle.loads(pickle.dumps(p)) self.assertTrue(isinstance(obj2, Thing)) self.assertFalse(isinstance(obj2, Proxy)) self.assertEqual(obj.value, obj2.value)
def test_bool(self): obj = True p = Proxy(obj) if p: pass else: self.fail()
def test_iand(self): expected = numpy.array([20]) expected &= 10 obj = numpy.array([20]) result = Proxy(obj) result &= 10 self.assertEqual(result, expected)
def test_missing_special_method(self): obj = Thing(10) p = Proxy(obj) self.assertFalse(hasattr(p, "__and__"))
def test_has_special_method(self): obj = Thing(10) p = Proxy(obj) self.assertTrue(hasattr(p, "__getitem__"))
def text_init(self): obj = Thing(10) p = Proxy(obj) self.assertTrue(isinstance(p, Thing)) self.assertTrue(isinstance(p, Proxy))
def __init__(self, obj, value): Proxy.__init__(self, obj) self.value = value + 2
def test_dumps(self): obj = Thing(10) p = Proxy(obj) expected = pickle.dumps(obj) result = pickle.dumps(p) self.assertEqual(result, expected)
def test_lt(self): obj = numpy.array([20]) p = Proxy(obj) expected = obj < obj result = p < p self.assertEqual(result, expected)
def test_getitem(self): obj = Thing(10) p = Proxy(obj) self.assertEqual(p[10], obj[10])
def test_method(self): obj = Thing(10) p = Proxy(obj) self.assertEqual(p.method(10), obj.method(10))
def test_repr(self): obj = Thing(10) p = Proxy(obj) expected = repr(obj) result = repr(p) self.assertEqual(result, expected)
def test_round(self): obj = 20.5 p = Proxy(obj) expected = round(obj) result = round(p) self.assertEqual(result, expected)
def test_neg(self): obj = numpy.array([20]) p = Proxy(obj) expected = -obj result = -p self.assertEqual(result, expected)
def test_rand(self): obj = numpy.array([20]) p = Proxy(obj) expected = 10 & obj result = 10 & p self.assertEqual(result, expected)
def test_add(self): obj = numpy.array([20]) proxy = Proxy(obj) expected = obj + obj result = proxy + proxy self.assertEqual(result, expected)
def test_property(self): obj = Thing(10) p = Proxy(obj) self.assertEqual(p.value, obj.value)
def test_text_repr(self): obj = "a" p = Proxy(obj) expected = repr(obj) result = repr(p) self.assertEqual(result, expected)
def test_setitem(self): obj = numpy.array([10, 20, 30]) p = Proxy(obj) p[0] = 20 self.assertEqual(obj[0], 20)
def test_slice(self): obj = numpy.arange(20) p = Proxy(obj) expected = obj[0:10:2] result = p[0:10:2] self.assertEqual(list(result), list(expected))