From 41fef74e9d75cf26cabda21538d162434bdf69f8 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Wed, 8 Jan 2014 03:26:13 +0000 Subject: [PATCH] Add more tests for SHA256TransactionStore. One of the tests is a known failure because of a bug, so mark it accordingly. Signed-off-by: brian m. carlson --- test/testfilemanip.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/testfilemanip.py b/test/testfilemanip.py index 07e3fdc..00dfbe2 100755 --- a/test/testfilemanip.py +++ b/test/testfilemanip.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 from newfol.filemanip import Record, FileStorage, SHA256TransactionStore +import newfol.exception import tempfile import unittest @@ -70,6 +71,36 @@ class SHA256TransactionTest(unittest.TestCase): self.assertEqual(SHA256TransactionStore._hash_file(temp), "sha256:" + v) tempdir = None + def create_small_database(self, tempdir): + temp = tempdir.name + "/test" + fp = open(temp, "w") + fp.write(":\n") + fp.close() + return temp + def create_filestorage(self, *args): + class Simple: + pass + x = Simple() + x.tempdir = tempfile.TemporaryDirectory() + x.tempfile = self.create_small_database(x.tempdir) + x.fs = FileStorage("csv", x.tempfile, "sha256", *args) + return x + @unittest.expectedFailure + def test_missing_not_forgiving(self): + x = self.create_filestorage({"forgiving": False}) + with self.assertRaisesRegex(newfol.exception.UpgradeNeededError, + 'missing checksum'): + x.fs.load() + x.tempdir.cleanup() + def test_missing_forgiving(self): + x = self.create_filestorage({"forgiving": True}) + x.fs.load() + x.tempdir.cleanup() + def test_missing(self): + x = self.create_filestorage() + x.fs.load() + x.tempdir.cleanup() + if __name__ == '__main__': unittest.main()