How to use marshal method in molecule

Best Python code snippet using molecule_python

buffer_tests.py

Source:buffer_tests.py Github

copy

Full Screen

...5class MixinBytesBufferCommonTests(object):6 """Tests that work for both bytes and buffer objects.7 See PEP 3137.8 """9 def marshal(self, x):10 """Convert x into the appropriate type for these tests."""11 raise RuntimeError('test class must provide a marshal method')12 def test_islower(self):13 self.assertFalse(self.marshal(b'').islower())14 self.assertTrue(self.marshal(b'a').islower())15 self.assertFalse(self.marshal(b'A').islower())16 self.assertFalse(self.marshal(b'\n').islower())17 self.assertTrue(self.marshal(b'abc').islower())18 self.assertFalse(self.marshal(b'aBc').islower())19 self.assertTrue(self.marshal(b'abc\n').islower())20 self.assertRaises(TypeError, self.marshal(b'abc').islower, 42)21 def test_isupper(self):22 self.assertFalse(self.marshal(b'').isupper())23 self.assertFalse(self.marshal(b'a').isupper())24 self.assertTrue(self.marshal(b'A').isupper())25 self.assertFalse(self.marshal(b'\n').isupper())26 self.assertTrue(self.marshal(b'ABC').isupper())27 self.assertFalse(self.marshal(b'AbC').isupper())28 self.assertTrue(self.marshal(b'ABC\n').isupper())29 self.assertRaises(TypeError, self.marshal(b'abc').isupper, 42)30 def test_istitle(self):31 self.assertFalse(self.marshal(b'').istitle())32 self.assertFalse(self.marshal(b'a').istitle())33 self.assertTrue(self.marshal(b'A').istitle())34 self.assertFalse(self.marshal(b'\n').istitle())35 self.assertTrue(self.marshal(b'A Titlecased Line').istitle())36 self.assertTrue(self.marshal(b'A\nTitlecased Line').istitle())37 self.assertTrue(self.marshal(b'A Titlecased, Line').istitle())38 self.assertFalse(self.marshal(b'Not a capitalized String').istitle())39 self.assertFalse(self.marshal(b'Not\ta Titlecase String').istitle())40 self.assertFalse(self.marshal(b'Not--a Titlecase String').istitle())41 self.assertFalse(self.marshal(b'NOT').istitle())42 self.assertRaises(TypeError, self.marshal(b'abc').istitle, 42)43 def test_isspace(self):44 self.assertFalse(self.marshal(b'').isspace())45 self.assertFalse(self.marshal(b'a').isspace())46 self.assertTrue(self.marshal(b' ').isspace())47 self.assertTrue(self.marshal(b'\t').isspace())48 self.assertTrue(self.marshal(b'\r').isspace())49 self.assertTrue(self.marshal(b'\n').isspace())50 self.assertTrue(self.marshal(b' \t\r\n').isspace())51 self.assertFalse(self.marshal(b' \t\r\na').isspace())52 self.assertRaises(TypeError, self.marshal(b'abc').isspace, 42)53 def test_isalpha(self):54 self.assertFalse(self.marshal(b'').isalpha())55 self.assertTrue(self.marshal(b'a').isalpha())56 self.assertTrue(self.marshal(b'A').isalpha())57 self.assertFalse(self.marshal(b'\n').isalpha())58 self.assertTrue(self.marshal(b'abc').isalpha())59 self.assertFalse(self.marshal(b'aBc123').isalpha())60 self.assertFalse(self.marshal(b'abc\n').isalpha())61 self.assertRaises(TypeError, self.marshal(b'abc').isalpha, 42)62 def test_isalnum(self):63 self.assertFalse(self.marshal(b'').isalnum())64 self.assertTrue(self.marshal(b'a').isalnum())65 self.assertTrue(self.marshal(b'A').isalnum())66 self.assertFalse(self.marshal(b'\n').isalnum())67 self.assertTrue(self.marshal(b'123abc456').isalnum())68 self.assertTrue(self.marshal(b'a1b3c').isalnum())69 self.assertFalse(self.marshal(b'aBc000 ').isalnum())70 self.assertFalse(self.marshal(b'abc\n').isalnum())71 self.assertRaises(TypeError, self.marshal(b'abc').isalnum, 42)72 def test_isdigit(self):73 self.assertFalse(self.marshal(b'').isdigit())74 self.assertFalse(self.marshal(b'a').isdigit())75 self.assertTrue(self.marshal(b'0').isdigit())76 self.assertTrue(self.marshal(b'0123456789').isdigit())77 self.assertFalse(self.marshal(b'0123456789a').isdigit())78 self.assertRaises(TypeError, self.marshal(b'abc').isdigit, 42)79 def test_lower(self):80 self.assertEqual(b'hello', self.marshal(b'HeLLo').lower())81 self.assertEqual(b'hello', self.marshal(b'hello').lower())82 self.assertRaises(TypeError, self.marshal(b'hello').lower, 42)83 def test_upper(self):84 self.assertEqual(b'HELLO', self.marshal(b'HeLLo').upper())85 self.assertEqual(b'HELLO', self.marshal(b'HELLO').upper())86 self.assertRaises(TypeError, self.marshal(b'hello').upper, 42)87 def test_capitalize(self):88 self.assertEqual(b' hello ', self.marshal(b' hello ').capitalize())89 self.assertEqual(b'Hello ', self.marshal(b'Hello ').capitalize())90 self.assertEqual(b'Hello ', self.marshal(b'hello ').capitalize())91 self.assertEqual(b'Aaaa', self.marshal(b'aaaa').capitalize())92 self.assertEqual(b'Aaaa', self.marshal(b'AaAa').capitalize())93 self.assertRaises(TypeError, self.marshal(b'hello').capitalize, 42)94 def test_ljust(self):95 self.assertEqual(b'abc ', self.marshal(b'abc').ljust(10))96 self.assertEqual(b'abc ', self.marshal(b'abc').ljust(6))97 self.assertEqual(b'abc', self.marshal(b'abc').ljust(3))98 self.assertEqual(b'abc', self.marshal(b'abc').ljust(2))99 self.assertEqual(b'abc*******', self.marshal(b'abc').ljust(10, '*'))100 self.assertRaises(TypeError, self.marshal(b'abc').ljust)101 def test_rjust(self):102 self.assertEqual(b' abc', self.marshal(b'abc').rjust(10))103 self.assertEqual(b' abc', self.marshal(b'abc').rjust(6))104 self.assertEqual(b'abc', self.marshal(b'abc').rjust(3))105 self.assertEqual(b'abc', self.marshal(b'abc').rjust(2))106 self.assertEqual(b'*******abc', self.marshal(b'abc').rjust(10, '*'))107 self.assertRaises(TypeError, self.marshal(b'abc').rjust)108 def test_center(self):109 self.assertEqual(b' abc ', self.marshal(b'abc').center(10))110 self.assertEqual(b' abc ', self.marshal(b'abc').center(6))111 self.assertEqual(b'abc', self.marshal(b'abc').center(3))112 self.assertEqual(b'abc', self.marshal(b'abc').center(2))113 self.assertEqual(b'***abc****', self.marshal(b'abc').center(10, '*'))114 self.assertRaises(TypeError, self.marshal(b'abc').center)115 def test_swapcase(self):116 self.assertEqual(b'hEllO CoMPuTErS',117 self.marshal(b'HeLLo cOmpUteRs').swapcase())118 self.assertRaises(TypeError, self.marshal(b'hello').swapcase, 42)119 def test_zfill(self):120 self.assertEqual(b'123', self.marshal(b'123').zfill(2))121 self.assertEqual(b'123', self.marshal(b'123').zfill(3))122 self.assertEqual(b'0123', self.marshal(b'123').zfill(4))123 self.assertEqual(b'+123', self.marshal(b'+123').zfill(3))124 self.assertEqual(b'+123', self.marshal(b'+123').zfill(4))125 self.assertEqual(b'+0123', self.marshal(b'+123').zfill(5))126 self.assertEqual(b'-123', self.marshal(b'-123').zfill(3))127 self.assertEqual(b'-123', self.marshal(b'-123').zfill(4))128 self.assertEqual(b'-0123', self.marshal(b'-123').zfill(5))129 self.assertEqual(b'000', self.marshal(b'').zfill(3))130 self.assertEqual(b'34', self.marshal(b'34').zfill(1))131 self.assertEqual(b'0034', self.marshal(b'34').zfill(4))132 self.assertRaises(TypeError, self.marshal(b'123').zfill)133 def test_expandtabs(self):134 self.assertEqual(b'abc\rab def\ng hi',135 self.marshal(b'abc\rab\tdef\ng\thi').expandtabs())136 self.assertEqual(b'abc\rab def\ng hi',137 self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(8))138 self.assertEqual(b'abc\rab def\ng hi',139 self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(4))140 self.assertEqual(b'abc\r\nab def\ng hi',141 self.marshal(b'abc\r\nab\tdef\ng\thi').expandtabs(4))142 self.assertEqual(b'abc\rab def\ng hi',143 self.marshal(b'abc\rab\tdef\ng\thi').expandtabs())144 self.assertEqual(b'abc\rab def\ng hi',145 self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(8))146 self.assertEqual(b'abc\r\nab\r\ndef\ng\r\nhi',147 self.marshal(b'abc\r\nab\r\ndef\ng\r\nhi').expandtabs(4))148 self.assertEqual(b' a\n b', self.marshal(b' \ta\n\tb').expandtabs(1))149 self.assertRaises(TypeError, self.marshal(b'hello').expandtabs, 42, 42)150 # This test is only valid when sizeof(int) == sizeof(void*) == 4.151 if sys.maxint < (1 << 32) and struct.calcsize('P') == 4:152 self.assertRaises(OverflowError,153 self.marshal(b'\ta\n\tb').expandtabs, sys.maxint)154 def test_title(self):155 self.assertEqual(b' Hello ', self.marshal(b' hello ').title())156 self.assertEqual(b'Hello ', self.marshal(b'hello ').title())157 self.assertEqual(b'Hello ', self.marshal(b'Hello ').title())158 self.assertEqual(b'Format This As Title String',159 self.marshal(b'fOrMaT thIs aS titLe String').title())160 self.assertEqual(b'Format,This-As*Title;String',161 self.marshal(b'fOrMaT,thIs-aS*titLe;String').title())162 self.assertEqual(b'Getint', self.marshal(b'getInt').title())163 self.assertRaises(TypeError, self.marshal(b'hello').title, 42)164 def test_splitlines(self):165 self.assertEqual([b'abc', b'def', b'', b'ghi'],166 self.marshal(b'abc\ndef\n\rghi').splitlines())167 self.assertEqual([b'abc', b'def', b'', b'ghi'],168 self.marshal(b'abc\ndef\n\r\nghi').splitlines())169 self.assertEqual([b'abc', b'def', b'ghi'],170 self.marshal(b'abc\ndef\r\nghi').splitlines())171 self.assertEqual([b'abc', b'def', b'ghi'],172 self.marshal(b'abc\ndef\r\nghi\n').splitlines())173 self.assertEqual([b'abc', b'def', b'ghi', b''],174 self.marshal(b'abc\ndef\r\nghi\n\r').splitlines())175 self.assertEqual([b'', b'abc', b'def', b'ghi', b''],176 self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines())177 self.assertEqual([b'\n', b'abc\n', b'def\r\n', b'ghi\n', b'\r'],178 self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(1))...

Full Screen

Full Screen

test_marshal.py

Source:test_marshal.py Github

copy

Full Screen

1from rpython.tool.udir import udir2class AppTestMarshal:3 spaceconfig = {'usemodules': ['array']}4 def setup_class(cls):5 tmpfile = udir.join('AppTestMarshal.tmp')6 cls.w_tmpfile = cls.space.wrap(str(tmpfile))7 def w_marshal_check(self, case):8 import marshal, StringIO9 s = marshal.dumps(case)10 print(repr(s))11 x = marshal.loads(s)12 assert x == case and type(x) is type(case)13 exc = raises(TypeError, marshal.loads, memoryview(s))14 assert str(exc.value) == "must be string or read-only buffer, not memoryview"15 import sys16 if '__pypy__' in sys.builtin_module_names:17 f = StringIO.StringIO()18 marshal.dump(case, f)19 f.seek(0)20 x = marshal.load(f)21 assert x == case and type(x) is type(case)22 return x23 def test_None(self):24 case = None25 self.marshal_check(case)26 def test_False(self):27 case = False28 self.marshal_check(case)29 def test_True(self):30 case = True31 self.marshal_check(case)32 def test_StopIteration(self):33 case = StopIteration34 self.marshal_check(case)35 def test_Ellipsis(self):36 case = Ellipsis37 self.marshal_check(case)38 def test_42(self):39 case = 4240 self.marshal_check(case)41 def test__minus_17(self):42 case = -1743 self.marshal_check(case)44 def test_sys_dot_maxint(self):45 import sys46 case = sys.maxint47 self.marshal_check(case)48 def test__minus_1_dot_25(self):49 case = -1.2550 self.marshal_check(case)51 def test__minus_1_dot_25__2(self):52 case = -1.25 #253 self.marshal_check(case)54 def test_2_plus_5j(self):55 case = 2+5j56 self.marshal_check(case)57 def test_2_plus_5j__2(self):58 case = 2+5j #259 self.marshal_check(case)60 def test_long(self):61 self.marshal_check(42L)62 case = -1234567890123456789012345678901234567890L63 self.marshal_check(case)64 def test_hello_____not_interned(self):65 hello = "he"66 hello += "llo"67 case = hello # not interned68 self.marshal_check(case)69 def test__Quote_hello_Quote_(self):70 case = "hello"71 self.marshal_check(case)72 def test__brace__ecarb_(self):73 case = ()74 self.marshal_check(case)75 def test__brace_1_comma__2_ecarb_(self):76 case = (1, 2)77 self.marshal_check(case)78 def test__list__tsil_(self):79 case = []80 self.marshal_check(case)81 def test__list_3_comma__4_tsil_(self):82 case = [3, 4]83 self.marshal_check(case)84 def test__dict__tcid_(self):85 case = {}86 self.marshal_check(case)87 def test__dict_5_colon__6_comma__7_colon__8_tcid_(self):88 case = {5: 6, 7: 8}89 self.marshal_check(case)90 def test_func_dot_func_code(self):91 def func(x):92 return lambda y: x+y93 case = func.func_code94 self.marshal_check(case)95 def test_scopefunc_dot_func_code(self):96 def func(x):97 return lambda y: x+y98 scopefunc = func(42)99 case = scopefunc.func_code100 self.marshal_check(case)101 def test_u_quote_hello_quote_(self):102 case = u'hello'103 self.marshal_check(case)104 def test_set_brace__ecarb_(self):105 case = set()106 self.marshal_check(case)107 def test_set_brace__list_1_comma__2_tsil__ecarb_(self):108 case = set([1, 2])109 self.marshal_check(case)110 def test_frozenset_brace__ecarb_(self):111 case = frozenset()112 self.marshal_check(case)113 def test_frozenset_brace__list_3_comma__4_tsil__ecarb_(self):114 case = frozenset([3, 4])115 self.marshal_check(case)116 def test_stream_reader_writer(self):117 # for performance, we have a special case when reading/writing real118 # file objects119 import marshal120 obj1 = [4, ("hello", 7.5)]121 obj2 = "foobar"122 f = open(self.tmpfile, 'wb')123 marshal.dump(obj1, f)124 marshal.dump(obj2, f)125 f.write('END')126 f.close()127 f = open(self.tmpfile, 'rb')128 obj1b = marshal.load(f)129 obj2b = marshal.load(f)130 tail = f.read()131 f.close()132 assert obj1b == obj1133 assert obj2b == obj2134 assert tail == 'END'135 def test_unicode(self):136 import marshal, sys137 self.marshal_check(u'\uFFFF')138 self.marshal_check(u'\ud800')139 self.marshal_check(unichr(sys.maxunicode))140 def test_reject_subtypes(self):141 import marshal142 types = (float, complex, int, long, tuple, list, dict, set, frozenset)143 for cls in types:144 print(cls)145 class subtype(cls):146 pass147 exc = raises(ValueError, marshal.dumps, subtype)148 assert str(exc.value) == 'unmarshallable object'149 exc = raises(ValueError, marshal.dumps, subtype())150 assert str(exc.value) == 'unmarshallable object'151 exc = raises(ValueError, marshal.dumps, (subtype(),))152 assert str(exc.value) == 'unmarshallable object'153 def test_valid_subtypes(self):154 import marshal155 from array import array156 class subtype(array):157 pass158 assert marshal.dumps(subtype('c', 'test')) == marshal.dumps(array('c', 'test'))159 def test_bad_typecode(self):160 import marshal161 exc = raises(ValueError, marshal.loads, chr(1))162 assert str(exc.value) == "bad marshal data (unknown type code)"163class AppTestSmallLong(AppTestMarshal):164 spaceconfig = AppTestMarshal.spaceconfig.copy()165 spaceconfig["objspace.std.withsmalllong"] = True166 def test_smalllong(self):167 import __pypy__168 x = -123456789012345L169 assert 'SmallLong' in __pypy__.internal_repr(x)170 y = self.marshal_check(x)171 assert y == x172 # must be unpickled as a small long...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run molecule automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful