Exemplo n.º 1
0
    def test_noflag(self):

        self.assertEqual(b"\x04\bI/\att\x00\x06:\x06EF",
                         writes(re.compile("tt")))
        self.assertEqual(b"\x04\bI/\att\x01\x06:\x06EF",
                         writes(re.compile("tt", re.IGNORECASE)))

        self.read_write(re.compile("tt"))
Exemplo n.º 2
0
 def test_gem_spec(self):
     raw_src = (
         b'\x04\x08u:\x17Gem::Specification\x02d\x03\x04\x08[\x18I"\n2.2.2\x06:\x06ETi'
         b'\tI"\x14capistrano-demo\x06;\x00TU:\x11Gem::Version[\x06I"\n0.0.5\x06;\x00TIu:'
         b'\tTime\r\xc0\xdb\x1c\xc0\x00\x00\x00\x00\x06:\tzoneI"\x08UTC\x06;\x00FI"$'
         b"Create demo-host by branch name\x06;\x00TU:\x15Gem::Requirement[\x06[\x06[\x07"
         b'I"\x07>=\x06;\x00TU;\x06[\x06I"\x060\x06;\x00TU;\t[\x06[\x06[\x07I"\x07>=\x06;'
         b'\x00TU;\x06[\x06I"\x060\x06;\x00TI"\truby\x06;\x00T[\to:\x14Gem::Dependency\n:\n'
         b'@nameI"\x0fcapistrano\x06;\x00T:\x11@requirementU;\t[\x06[\x06[\x07I"\x07~>\x06;\x00'
         b'TU;\x06[\x06I"\x083.1\x06;\x00T:\n@type:\x0cruntime:\x10@prereleaseF:\x1a'
         b'@version_requirementsU;\t[\x06[\x06[\x07I"\x07~>\x06;\x00TU;\x06[\x06I"\x083.1\x06;\x00'
         b'To;\n\n;\x0bI"\x0cbundler\x06;\x00T;\x0cU;\t[\x06[\x06[\x07I"\x07~>\x06;\x00TU;\x06[\x06'
         b'I"\x0b1.10.0\x06;\x00T;\r:\x10development;\x0fF;\x10U;\t[\x06[\x06[\x07I"\x07~>\x06;\x00'
         b'TU;\x06[\x06I"\x0b1.10.0\x06;\x00To;\n\n;\x0bI"\trake\x06;\x00T;\x0cU;\t[\x06[\x06[\x07'
         b'I"\x07>=\x06;\x00TU;\x06[\x06I"\x060\x06;\x00T;\r;\x11;\x0fF;\x10U;\t[\x06[\x06[\x07'
         b'I"\x07>=\x06;\x00TU;\x06[\x06I"\x060\x06;\x00To;\n\n;\x0bI"\nrspec\x06;\x00T;\x0cU;\t'
         b'[\x06[\x06[\x07I"\x07~>\x06;\x00TU;\x06[\x06I"\n3.2.0\x06;\x00T;\r;\x11;\x0fF;\x10U;\t'
         b'[\x06[\x06[\x07I"\x07~>\x06;\x00TU;\x06[\x06I"\n3.2.0\x06;\x00T0[\x06I"\x1farthur.shcheg'
         b'[email protected]\x06;\x00T[\x06I"\x1fArthur Shcheglov (fc_arny)\x06;\x00TI"$Create demo-host '
         b'by branch name\x06;\x00TI"\x1chttp://at-consulting.ru\x06;\x00TT@\x1e[\x06I"\x08MIT\x06;\x00T{\x00'
     )
     actual_obj = loads(raw_src)
     raw_dst = writes(actual_obj)
     dst_obj = loads(raw_dst)
     self.assertEqual(actual_obj, dst_obj)
     self.assertEqual(raw_src, raw_dst)
Exemplo n.º 3
0
 def test_subgem_spec(self):
     raw_src = (
         b'\x04\x08[\x18I"\n2.2.2\x06:\x06ETi\tI"\x14capistrano-demo\x06;\x00'
         b'TU:\x11Gem::Version[\x06I"\n0.0.5\x06;\x00TIu:\tTime\r\xc0\xdb\x1c'
         b'\xc0\x00\x00\x00\x00\x06:\tzoneI"\x08UTC\x06;\x00FI"$Create demo-h'
         b"ost by branch name\x06;\x00TU:\x15Gem::Requirement[\x06[\x06[\x07I"
         b'"\x07>=\x06;\x00TU;\x06[\x06I"\x060\x06;\x00TU;\t[\x06[\x06[\x07I"'
         b'\x07>=\x06;\x00TU;\x06[\x06I"\x060\x06;\x00TI"\truby\x06;\x00T[\to'
         b':\x14Gem::Dependency\n:\n@nameI"\x0fcapistrano\x06;\x00T:\x11@requ'
         b'irementU;\t[\x06[\x06[\x07I"\x07~>\x06;\x00TU;\x06[\x06I"\x083.1'
         b"\x06;\x00T:\n@type:\x0cruntime:\x10@prereleaseF:\x1a@version_requi"
         b'rementsU;\t[\x06[\x06[\x07I"\x07~>\x06;\x00TU;\x06[\x06I"\x083.1'
         b'\x06;\x00To;\n\n;\x0bI"\x0cbundler\x06;\x00T;\x0cU;\t[\x06[\x06['
         b'\x07I"\x07~>\x06;\x00TU;\x06[\x06I"\x0b1.10.0\x06;\x00T;\r:\x10dev'
         b'elopment;\x0fF;\x10U;\t[\x06[\x06[\x07I"\x07~>\x06;\x00TU;\x06['
         b'\x06I"\x0b1.10.0\x06;\x00To;\n\n;\x0bI"\trake\x06;\x00T;\x0cU;\t['
         b'\x06[\x06[\x07I"\x07>=\x06;\x00TU;\x06[\x06I"\x060\x06;\x00T;\r;'
         b'\x11;\x0fF;\x10U;\t[\x06[\x06[\x07I"\x07>=\x06;\x00TU;\x06[\x06I"'
         b'\x060\x06;\x00To;\n\n;\x0bI"\nrspec\x06;\x00T;\x0cU;\t[\x06[\x06['
         b'\x07I"\x07~>\x06;\x00TU;\x06[\x06I"\n3.2.0\x06;\x00T;\r;\x11;\x0f'
         b'F;\x10U;\t[\x06[\x06[\x07I"\x07~>\x06;\x00TU;\x06[\x06I"\n3.2.0'
         b'\x06;\x00T0[\x06I"\[email protected]\x06;\x00T[\x06I"'
         b'\x1fArthur Shcheglov (fc_arny)\x06;\x00TI"$Create demo-host by br'
         b'anch name\x06;\x00TI"\x1chttp://at-consulting.ru\x06;\x00TT@\x1e['
         b'\x06I"\x08MIT\x06;\x00T{\x00')
     actual_obj = loads(raw_src)
     raw_dst = writes(actual_obj)
     # print(raw_dst)
     dst_obj = loads(raw_dst)
     self.assertEqual(actual_obj, dst_obj)
     # print(dst_obj, actual_obj == dst_obj)
     # loads(raw_dst)
     self.assertEqual(raw_src, raw_dst)
Exemplo n.º 4
0
 def check(self, a, b):
     b = b.replace(" ", "")
     bytes_array = [4, 8] + [
         int(b[2 * i:2 * i + 2], 16) for i in range(len(b) // 2)
     ]
     byte_text = bytes(bytes_array)
     fd = io.BytesIO(byte_text)
     bytes_to_obj = load(fd, registry=registry)
     self.assertEqual(a, bytes_to_obj)
     # check that there is no data left
     self.assertEqual(b"", fd.read())
     obj_to_bytes = writes(bytes_to_obj)
     self.assertEqual(byte_text, obj_to_bytes)
Exemplo n.º 5
0
 def double_check(self, bytes_value: bytes):
     fd = io.BytesIO(bytes_value)
     bytes_to_obj = load(fd)
     self.assertEqual(b"", fd.read())
     obj_to_bytes = writes(bytes_to_obj)
     self.assertEqual(bytes_value, obj_to_bytes)
Exemplo n.º 6
0
 def test_write_constant(self):
     dumped = writes([Constant("test")], cls=ConstantWriter)
     read_constant = loads(dumped)
     self.assertEqual([Symbol("test")], read_constant)
Exemplo n.º 7
0
 def test_num_nan(self):
     self.assertTrue(math.isnan(loads(writes(float("nan")))))
Exemplo n.º 8
0
 def read_write(self, x):
     self.assertEqual(loads(writes(x)), x)
Exemplo n.º 9
0
 def test_floats(self, x):
     if math.isnan(x):
         self.assertTrue(math.isnan(loads(writes(x))))
     else:
         self.read_write(x)
Exemplo n.º 10
0
 def read_write(self, x):
     self.assertEqual(loads(writes(x)), x)
Exemplo n.º 11
0
    def test_noflag(self):

        self.assertEqual(b"\x04\bI/\att\x00\x06:\x06EF", writes(re.compile('tt')))
        self.assertEqual(b"\x04\bI/\att\x01\x06:\x06EF", writes(re.compile('tt', re.IGNORECASE)))

        self.read_write(re.compile('tt'))
Exemplo n.º 12
0
 def test_num_nan(self):
     self.assertTrue(math.isnan(loads(writes(float('nan')))))
Exemplo n.º 13
0
 def test_floats(self, x):
     if math.isnan(x):
         self.assertTrue(math.isnan(loads(writes(x))))
     else:
         self.read_write(x)