1
# This Source Code Form is subject to the terms of the Mozilla Public
2
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
3
# You can obtain one at http://mozilla.org/MPL/2.0/.
8
from StringIO import StringIO
9
from tempfile import NamedTemporaryFile
11
from mozbuild.util import hash_file
14
class TestHashing(unittest.TestCase):
15
def test_hash_file_known_hash(self):
16
"""Ensure a known hash value is recreated."""
17
data = 'The quick brown fox jumps over the lazy cog'
18
expected = 'de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3'
20
temp = NamedTemporaryFile()
24
actual = hash_file(temp.name)
26
self.assertEqual(actual, expected)
28
def test_hash_file_large(self):
29
"""Ensure that hash_file seems to work with a large file."""
32
hasher = hashlib.sha1()
34
expected = hasher.hexdigest()
36
temp = NamedTemporaryFile()
40
actual = hash_file(temp.name)
42
self.assertEqual(actual, expected)