class TestSimpleFileEnv(unittest.TestCase, BaseGobTests): UNICODE_STR = u'Unicode is \U0001F4A9!' def setUp(self): path = clean_data_dir() self.packed = msgpack.packb((1,2,"gigem",self.UNICODE_STR)) self.env = SimpleFileEnv(path) self.gob = Gob(self.env) create_jobs(self.gob) def test_load(self): with open(os.path.join(self.env.path,"stuff.mp"),'w') as f: f.write(self.packed) data = list(self.env.load("stuff")) self.assertEqual(data,[(1,2,"gigem",self.UNICODE_STR)]) self.assertTrue(isinstance(data[0][-1],unicode)) def test_save(self): self.env.save("more_stuff.2",[[1,2,"gigem",self.UNICODE_STR]]) with open(os.path.join(self.env.path,"more_stuff","2.mp")) as f: data = f.read() self.assertEqual(data,self.packed) def test_set_reduce(self): res = set_reduce(1,(2,4,5,2),rereduce=False) self.assertTrue(isinstance(res,tuple)) self.assertEqual(sorted(res),[2,4,5]) # make sure msgpack doesn't raise an exception msgpack.packb(res)
def setUp(self): path = clean_data_dir() self.packed = msgpack.packb((1,2,"gigem",self.UNICODE_STR)) self.env = SimpleFileEnv(path) self.gob = Gob(self.env) create_jobs(self.gob)