class FileStorageTest(unittest.TestCase): def setUp(self): self.tdir = tempfile.mkdtemp() data = { "int": 1, "float": 1.2, "list": [1, 2, 3], "dict": { "dname": "foo", "dval": 1 }, "listdict": [{ "lname": "foo" }], "str": "string" } self.bare_data = dict(data) data['wmaid'] = wmaHash(data) data['stype'] = 'avroio' self.data = data schema = gen_schema(self.data) sname = os.path.join(self.tdir, 'schema.avsc') with open(sname, 'w') as ostream: ostream.write(json.dumps(schema)) self.mgr = AvroStorage('avroio:%s' % sname) def tearDown(self): "Tear down content of temp dir" for fname in os.listdir(self.tdir): os.remove(os.path.join(self.tdir, fname)) os.rmdir(self.tdir) def test_write(self): "Test write functionality" wmaids = self.mgr.write(self.data) self.assertEqual(len(wmaids), 1) data = self.mgr.read(wmaids[0]) self.assertEqual(data[0], self.bare_data) def test_file_write(self): "Test file_write functionality" fname = os.path.join(self.tdir, 'file.avro') wmaids = self.mgr.file_write(fname, self.data) self.assertEqual(len(wmaids), 1) data = self.mgr.file_read(fname) self.assertEqual(data[0], self.data) def test_file_write_exception(self): "Test file_write functionality with exception" fname = os.path.join( '/etc/file.avro') # we should not have access to /etc self.assertRaises(Exception, self.mgr.file_write, (fname, self.data))
class FileStorageTest(unittest.TestCase): def setUp(self): self.tdir = tempfile.mkdtemp() data = {"int":1, "float":1.2, "list":[1,2,3], "dict":{"dname": "foo", "dval":1}, "listdict":[{"lname":"foo"}], "str":"string"} self.bare_data = dict(data) data['wmaid'] = wmaHash(data) data['stype'] = 'avroio' self.data = data schema = gen_schema(self.data) sname = os.path.join(self.tdir, 'schema.avsc') with open(sname, 'w') as ostream: ostream.write(json.dumps(schema)) self.mgr = AvroStorage('avroio:%s' % sname) def tearDown(self): "Tear down content of temp dir" for fname in os.listdir(self.tdir): os.remove(os.path.join(self.tdir, fname)) os.rmdir(self.tdir) def test_write(self): "Test write functionality" wmaids = self.mgr.write(self.data) self.assertEqual(len(wmaids), 1) data = self.mgr.read(wmaids[0]) self.assertEqual(data[0], self.bare_data) def test_file_write(self): "Test file_write functionality" fname = os.path.join(self.tdir, 'file.avro') wmaids = self.mgr.file_write(fname, self.data) self.assertEqual(len(wmaids), 1) data = self.mgr.file_read(fname) self.assertEqual(data[0], self.data) def test_file_write_exception(self): "Test file_write functionality with exception" fname = os.path.join('/etc/file.avro') # we should not have access to /etc self.assertRaises(Exception, self.mgr.file_write, (fname, self.data))