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