예제 #1
0
 def test_adding_backend(self):
     FileStorage.register_backend("example", ExampleFile)
     self.assertEqual(FileStorage.BACKENDS["example"], ExampleFile)
     fs = FileStorage("example", "filename")
     recs = fs.load()
     self.assertEqual(len(recs), 1)
     self.assertEqual(recs[0].fields, ["a", "b"])
예제 #2
0
 def test_yaml(self):
     options = {"table-is-field-0": True}
     fmt = "yaml"
     filename = self.tempdir.name + "/" + fmt
     fs = FileStorage(fmt, filename, options=options)
     fs.store(self.data)
     self.check_serialized_data(fs, filename, self.data)
예제 #3
0
 def run_test(self, fmt, lossy=False):
     options = {"table-is-field-0": True}
     filename = self.tempdir.name + "/" + fmt
     fs = FileStorage(fmt, filename, options=options)
     fs.store(self.data)
     m = fs.load()
     self.compare(self.data, m, lossy)
     self.check_serialized_data(fs, filename, m)
예제 #4
0
 def compression_test(self, format):
     tempdir = tempfile.TemporaryDirectory()
     options = {"compression": format}
     magic = self.magic[format]
     filename = tempdir.name + "/dtb"
     fs = FileStorage("json", filename, options=options)
     fs.store(self.data)
     m = fs.load()
     self.compare(self.data, m)
     with open(filename, "rb") as fp:
         header = fp.read(len(magic))
     self.assertEqual(header, magic)
     tempdir.cleanup()
예제 #5
0
 def test_default(self):
     tempdir = tempfile.TemporaryDirectory()
     filename = tempdir.name + "/dtb"
     fs = FileStorage("json", filename)
     fs.store(self.data)
     m = fs.load()
     self.compare(self.data, m)
     with open(filename, "rb") as fp:
         header = fp.read(20)
     for k, v in self.magic.items():
         self.assertNotEqual(header[0 : len(v)], v)
     self.assertEqual(header[0:1], b"[")
     tempdir.cleanup()
예제 #6
0
 def test_autodetection(self):
     for i in ["sha256", "sha384", "sha512"]:
         x = self.create_filestorage_hash(i)
         x.fs.store([Record(["", ""])])
         fs = FileStorage("csv", x.tempfile, "hash")
         recs = fs.load()
         self.assertEqual(len(recs), 1)
         self.assertIsInstance(recs[0], Record)
         self.assertEqual(recs[0].fields[:], ["", ""])
         with open(x.tempfile + ".checksum", "w") as fp:
             # Something other than the correct value.
             fp.write("%s:2:%s\n" % (i, self.WRONG))
         with self.assertRaisesRegex(newfol.exception.FilemanipError, "corrupt"):
             x.fs.load()
         x.tempdir.cleanup()
예제 #7
0
 def test_removing_hook(self):
     FileStorage.register_hook("example", ExampleFile)
     self.assertEqual(FileStorage.HOOKS["example"], ExampleFile)
     FileStorage.unregister_hook("example")
     with self.assertRaises(KeyError):
         FileStorage.HOOKS["example"]
예제 #8
0
 def test_adding_hook(self):
     FileStorage.register_hook("example", ExampleHook)
     self.assertEqual(FileStorage.HOOKS["example"], ExampleHook)
예제 #9
0
 def test_removing_backend(self):
     FileStorage.register_backend("example", ExampleFile)
     self.assertEqual(FileStorage.BACKENDS["example"], ExampleFile)
     FileStorage.unregister_backend("example")
     with self.assertRaises(KeyError):
         FileStorage.BACKENDS["example"]
예제 #10
0
 def test_canonicalization(self):
     for i in ("sha256", "sha384", "sha512"):
         result = FileStorage._canonicalize_transaction_types(["hash", i])
         self.assertEqual(result, [i])
     self.assertEqual(FileStorage._canonicalize_transaction_types(None), None)