def testpickle(self): file = open("test.bin", "wb") output = typedbytes.Output(file) output.write("123") output.write(MyClass()) file.close() file = open("test.bin", "rb") input = typedbytes.Input(file) self.assertEqual("123", input.read()) self.assertEqual(234, input.read().attr) file.close() os.remove("test.bin")
def testio(self): objects = TestIO.objects file = open("test.bin", "wb") output = typedbytes.Output(file) output.writes(objects) file.close() file = open("test.bin", "rb") input = typedbytes.Input(file) for (index, record) in enumerate(input): self.assertEqual(objects[index], record) file.close() os.remove("test.bin")
def testints(self): file = cStringIO.StringIO() output = typedbytes.Output(file) t = time.time() output.writes(xrange(100000)) print time.time() - t file.seek(0) input = typedbytes.Input(file) t = time.time() for record in input: pass print time.time() - t file.close()
if not immutable: f.append(lambda: rand_list(sz / 2, immutable)) f.append(lambda: rand_dict(sz / 2)) return [random.choice(f)() for x in range(sz)] def rand_tuple(sz, immutable=False): return tuple(rand_list(sz, immutable)) def rand_dict(sz): return dict(zip(rand_list(sz, True), rand_list(sz))) with open('gb_single.tb', 'wb') as fp: a = typedbytes.Output(fp) grabbag(a) with open('gb_100k.tb', 'wb') as fp: a = typedbytes.Output(fp) for x in range(100000): grabbag(a) with open('bytes_100_10k.tb', 'wb') as fp: a = typedbytes.Output(fp) for x in range(10000): a.write_bytes(rand_bytes(100)) a.write_bytes(rand_bytes(100)) with open('bytes_1k_10k.tb', 'wb') as fp: a = typedbytes.Output(fp)