def test_certificateOptionsSerialization(self): """ Test that __setstate__(__getstate__()) round-trips properly. """ firstOpts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, method=SSL.SSLv3_METHOD, verify=True, caCerts=[self.sCert], verifyDepth=2, requireCertificate=False, verifyOnce=False, enableSingleUseKeys=False, enableSessions=False, fixBrokenPeers=True) context = firstOpts.getContext() state = firstOpts.__getstate__() # The context shouldn't be in the state to serialize self.failIf(objgrep(state, context, isSame), objgrep(state, context, isSame)) opts = sslverify.OpenSSLCertificateOptions() opts.__setstate__(state) self.assertEqual(opts.privateKey, self.sKey) self.assertEqual(opts.certificate, self.sCert) self.assertEqual(opts.method, SSL.SSLv3_METHOD) self.assertEqual(opts.verify, True) self.assertEqual(opts.caCerts, [self.sCert]) self.assertEqual(opts.verifyDepth, 2) self.assertEqual(opts.requireCertificate, False) self.assertEqual(opts.verifyOnce, False) self.assertEqual(opts.enableSingleUseKeys, False) self.assertEqual(opts.enableSessions, False) self.assertEqual(opts.fixBrokenPeers, True)
def testDictionary(self): o = object() d1 = {None: o} d2 = {o: None} self.assertIn("[None]", reflect.objgrep(d1, o, reflect.isSame)) self.assertIn("{None}", reflect.objgrep(d2, o, reflect.isSame))
def testDepthLimit(self): a = [] b = [a] c = [a, b] d = [a, c] self.assertEquals(['[0]'], reflect.objgrep(d, a, reflect.isSame, maxDepth=1)) self.assertEquals(['[0]', '[1][0]'], reflect.objgrep(d, a, reflect.isSame, maxDepth=2)) self.assertEquals(['[0]', '[1][0]', '[1][1][0]'], reflect.objgrep(d, a, reflect.isSame, maxDepth=3))
def testBoundMethod(self): class Dummy: def dummy(self): pass o = Dummy() m = o.dummy self.assertIn(".im_self", reflect.objgrep(m, m.im_self, reflect.isSame)) self.assertIn(".im_class", reflect.objgrep(m, m.im_class, reflect.isSame)) self.assertIn(".im_func", reflect.objgrep(m, m.im_func, reflect.isSame))
def test_dictionary(self): """ Test references search through a dictionnary, as a key or as a value. """ o = object() d1 = {None: o} d2 = {o: None} self.assertIn("[None]", reflect.objgrep(d1, o, reflect.isSame)) self.assertIn("{None}", reflect.objgrep(d2, o, reflect.isSame))
def test_depthLimit(self): """ Test the depth of references search. """ a = [] b = [a] c = [a, b] d = [a, c] self.assertEqual(['[0]'], reflect.objgrep(d, a, reflect.isSame, maxDepth=1)) self.assertEqual(['[0]', '[1][0]'], reflect.objgrep(d, a, reflect.isSame, maxDepth=2)) self.assertEqual(['[0]', '[1][0]', '[1][1][0]'], reflect.objgrep(d, a, reflect.isSame, maxDepth=3))
def test_boundMethod(self): """ Test references search through method special attributes. """ class Dummy: def dummy(self): pass o = Dummy() m = o.dummy self.assertIn(".im_self", reflect.objgrep(m, m.im_self, reflect.isSame)) self.assertIn(".im_class", reflect.objgrep(m, m.im_class, reflect.isSame)) self.assertIn(".im_func", reflect.objgrep(m, m.im_func, reflect.isSame))
def testWeakref(self): class Dummy: pass o = Dummy() w1 = weakref.ref(o) self.assertIn("()", reflect.objgrep(w1, o, reflect.isSame))
def testInstance(self): class Dummy: pass o = object() d = Dummy() d.o = o self.assertIn(".o", reflect.objgrep(d, o, reflect.isSame))
def test_tuple(self): """ Test references search through a tuple. """ o = object() T = (o, None) self.assertIn("[0]", reflect.objgrep(T, o, reflect.isSame))
def test_list(self): """ Test references search through a list. """ o = object() L = [None, o] self.assertIn("[1]", reflect.objgrep(L, o, reflect.isSame))
def test_boundMethod(self): """ Test references search through method special attributes. """ class Dummy: def dummy(self): pass o = Dummy() m = o.dummy self.assertIn(".__self__", reflect.objgrep(m, m.__self__, reflect.isSame)) self.assertIn( ".__self__.__class__", reflect.objgrep(m, m.__self__.__class__, reflect.isSame), ) self.assertIn(".__func__", reflect.objgrep(m, m.__func__, reflect.isSame))
def test_weakref(self): """ Test references search through a weakref object. """ class Dummy: pass o = Dummy() w1 = weakref.ref(o) self.assertIn("()", reflect.objgrep(w1, o, reflect.isSame))
def test_deque(self): """ Test references search through a deque object. Only for Python > 2.3. """ o = object() D = deque() D.append(None) D.append(o) self.assertIn("[1]", reflect.objgrep(D, o, reflect.isSame))
def test_deque(self): """ Test references search through a deque object. """ o = object() D = deque() D.append(None) D.append(o) self.assertIn("[1]", reflect.objgrep(D, o, reflect.isSame))
def test_instance(self): """ Test references search through an object attribute. """ class Dummy: pass o = object() d = Dummy() d.o = o self.assertIn(".o", reflect.objgrep(d, o, reflect.isSame))
def test_certificateOptionsSerialization(self): """ Test that __setstate__(__getstate__()) round-trips properly. """ firstOpts = sslverify.OpenSSLCertificateOptions( privateKey=self.sKey, certificate=self.sCert, method=SSL.SSLv3_METHOD, verify=True, caCerts=[self.sCert], verifyDepth=2, requireCertificate=False, verifyOnce=False, enableSingleUseKeys=False, enableSessions=False, fixBrokenPeers=True, enableSessionTickets=True) context = firstOpts.getContext() state = firstOpts.__getstate__() # The context shouldn't be in the state to serialize self.failIf(objgrep(state, context, isSame), objgrep(state, context, isSame)) opts = sslverify.OpenSSLCertificateOptions() opts.__setstate__(state) self.assertEqual(opts.privateKey, self.sKey) self.assertEqual(opts.certificate, self.sCert) self.assertEqual(opts.method, SSL.SSLv3_METHOD) self.assertEqual(opts.verify, True) self.assertEqual(opts.caCerts, [self.sCert]) self.assertEqual(opts.verifyDepth, 2) self.assertEqual(opts.requireCertificate, False) self.assertEqual(opts.verifyOnce, False) self.assertEqual(opts.enableSingleUseKeys, False) self.assertEqual(opts.enableSessions, False) self.assertEqual(opts.fixBrokenPeers, True) self.assertEqual(opts.enableSessionTickets, True)
def testEverything(self): class Dummy: def method(self): pass o = Dummy() D1 = {(): "baz", None: "Quux", o: "Foosh"} L = [None, (), D1, 3] T = (L, {}, Dummy()) D2 = {0: "foo", 1: "bar", 2: T} i = Dummy() i.attr = D2 m = i.method w = weakref.ref(m) self.assertIn("().im_self.attr[2][0][2]{'Foosh'}", reflect.objgrep(w, o, reflect.isSame))
def test_everything(self): """ Test references search using complex set of objects. """ class Dummy: def method(self): pass o = Dummy() D1 = {(): "baz", None: "Quux", o: "Foosh"} L = [None, (), D1, 3] T = (L, {}, Dummy()) D2 = {0: "foo", 1: "bar", 2: T} i = Dummy() i.attr = D2 m = i.method w = weakref.ref(m) self.assertIn("().__self__.attr[2][0][2]{'Foosh'}", reflect.objgrep(w, o, reflect.isSame))
def testTuple(self): o = object() T = (o, None) self.assertIn("[0]", reflect.objgrep(T, o, reflect.isSame))
def testList(self): o = object() L = [None, o] self.assertIn("[1]", reflect.objgrep(L, o, reflect.isSame))