Exemple #1
0
 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)
Exemple #2
0
 def test_text_bool(self):
     obj = ""
     p = Proxy(obj)
     if p:
         self.fail()
     else:
         pass
Exemple #3
0
 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)
Exemple #4
0
 def test_bool(self):
     obj = True
     p = Proxy(obj)
     if p:
         pass
     else:
         self.fail()
Exemple #5
0
 def test_iand(self):
     expected = numpy.array([20])
     expected &= 10
     obj = numpy.array([20])
     result = Proxy(obj)
     result &= 10
     self.assertEqual(result, expected)
Exemple #6
0
 def test_missing_special_method(self):
     obj = Thing(10)
     p = Proxy(obj)
     self.assertFalse(hasattr(p, "__and__"))
Exemple #7
0
 def test_has_special_method(self):
     obj = Thing(10)
     p = Proxy(obj)
     self.assertTrue(hasattr(p, "__getitem__"))
Exemple #8
0
 def text_init(self):
     obj = Thing(10)
     p = Proxy(obj)
     self.assertTrue(isinstance(p, Thing))
     self.assertTrue(isinstance(p, Proxy))
Exemple #9
0
 def __init__(self, obj, value):
     Proxy.__init__(self, obj)
     self.value = value + 2
Exemple #10
0
 def test_dumps(self):
     obj = Thing(10)
     p = Proxy(obj)
     expected = pickle.dumps(obj)
     result = pickle.dumps(p)
     self.assertEqual(result, expected)
Exemple #11
0
 def test_lt(self):
     obj = numpy.array([20])
     p = Proxy(obj)
     expected = obj < obj
     result = p < p
     self.assertEqual(result, expected)
Exemple #12
0
 def test_getitem(self):
     obj = Thing(10)
     p = Proxy(obj)
     self.assertEqual(p[10], obj[10])
Exemple #13
0
 def test_method(self):
     obj = Thing(10)
     p = Proxy(obj)
     self.assertEqual(p.method(10), obj.method(10))
Exemple #14
0
 def test_repr(self):
     obj = Thing(10)
     p = Proxy(obj)
     expected = repr(obj)
     result = repr(p)
     self.assertEqual(result, expected)
Exemple #15
0
 def test_round(self):
     obj = 20.5
     p = Proxy(obj)
     expected = round(obj)
     result = round(p)
     self.assertEqual(result, expected)
Exemple #16
0
 def test_neg(self):
     obj = numpy.array([20])
     p = Proxy(obj)
     expected = -obj
     result = -p
     self.assertEqual(result, expected)
Exemple #17
0
 def test_rand(self):
     obj = numpy.array([20])
     p = Proxy(obj)
     expected = 10 & obj
     result = 10 & p
     self.assertEqual(result, expected)
Exemple #18
0
 def test_add(self):
     obj = numpy.array([20])
     proxy = Proxy(obj)
     expected = obj + obj
     result = proxy + proxy
     self.assertEqual(result, expected)
Exemple #19
0
 def test_property(self):
     obj = Thing(10)
     p = Proxy(obj)
     self.assertEqual(p.value, obj.value)
Exemple #20
0
 def test_text_repr(self):
     obj = "a"
     p = Proxy(obj)
     expected = repr(obj)
     result = repr(p)
     self.assertEqual(result, expected)
Exemple #21
0
 def test_setitem(self):
     obj = numpy.array([10, 20, 30])
     p = Proxy(obj)
     p[0] = 20
     self.assertEqual(obj[0], 20)
Exemple #22
0
 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))