From e509dacc9aba441b592cb33266196caaf2ace1d0 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sun, 5 Jan 2014 19:29:21 +0000 Subject: [PATCH] Add a basic test for the SHA-256 Transaction store. Signed-off-by: brian m. carlson --- test/testfilemanip.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/testfilemanip.py b/test/testfilemanip.py index e7a83ea..07e3fdc 100755 --- a/test/testfilemanip.py +++ b/test/testfilemanip.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 -from newfol.filemanip import Record, FileStorage +from newfol.filemanip import Record, FileStorage, SHA256TransactionStore import tempfile import unittest @@ -53,5 +53,23 @@ class TestRoundTripping(unittest.TestCase): def test_pickle(self): self.run_test("pickle") +class SHA256TransactionTest(unittest.TestCase): + def test_hashing(self): + testcases = { + "": "0:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "abc": "3:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", + "©": "2:0a79b0ca699d37228d3affd3b6d38b7f2731702f12fd1edd6cb9ac42a686e3a3", + "\ufeff": "3:f1945cd6c19e56b3c1c78943ef5ec18116907a4ca1efc40a57d48ab1db7adfc5", + } + tempdir = tempfile.TemporaryDirectory() + temp = tempdir.name + "/test" + for k, v in testcases.items(): + wfp = open(temp, "w") + wfp.write(k) + wfp.close() + self.assertEqual(SHA256TransactionStore._hash_file(temp), + "sha256:" + v) + tempdir = None + if __name__ == '__main__': unittest.main()