aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bb/tests
diff options
context:
space:
mode:
authorRoss Burton <ross.burton@intel.com>2019-11-07 23:57:32 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-11-14 14:06:29 +0000
commite944d02fe678f7c6b05c62419f8bceb0709f3037 (patch)
treef1e50f39daa73387a03aa2a4bd2c33d93342753d /lib/bb/tests
parent33197db8abf82be240d7c1c5c9d2484a08a90849 (diff)
downloadbitbake-e944d02fe678f7c6b05c62419f8bceb0709f3037.tar.gz
tests: add test for the hashing functions
Add a basic test for bb.utils.md5_file() etc. Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/tests')
-rw-r--r--lib/bb/tests/utils.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/bb/tests/utils.py b/lib/bb/tests/utils.py
index f4adf1d44..5c910b4b8 100644
--- a/lib/bb/tests/utils.py
+++ b/lib/bb/tests/utils.py
@@ -103,6 +103,32 @@ class Path(unittest.TestCase):
result = bb.utils._check_unsafe_delete_path(arg1)
self.assertEqual(result, correctresult, '_check_unsafe_delete_path("%s") != %s' % (arg1, correctresult))
+class Checksum(unittest.TestCase):
+ filler = b"Shiver me timbers square-rigged spike Gold Road galleon bilge water boatswain wherry jack pirate. Mizzenmast rum lad Privateer jack salmagundi hang the jib piracy Pieces of Eight Corsair. Parrel marooned black spot yawl provost quarterdeck cable no prey, no pay spirits lateen sail."
+
+ def test_md5(self):
+ import hashlib
+ with tempfile.NamedTemporaryFile() as f:
+ f.write(self.filler)
+ f.flush()
+ checksum = bb.utils.md5_file(f.name)
+ self.assertEqual(checksum, "bd572cd5de30a785f4efcb6eaf5089e3")
+
+ def test_sha1(self):
+ import hashlib
+ with tempfile.NamedTemporaryFile() as f:
+ f.write(self.filler)
+ f.flush()
+ checksum = bb.utils.sha1_file(f.name)
+ self.assertEqual(checksum, "249eb8fd654732ea836d5e702d7aa567898eca71")
+
+ def test_sha256(self):
+ import hashlib
+ with tempfile.NamedTemporaryFile() as f:
+ f.write(self.filler)
+ f.flush()
+ checksum = bb.utils.sha256_file(f.name)
+ self.assertEqual(checksum, "fcfbae8bf6b721dbb9d2dc6a9334a58f2031a9a9b302999243f99da4d7f12d0f")
class EditMetadataFile(unittest.TestCase):
_origfile = """