test_archive.py 634 B

1234567891011121314151617181920212223
  1. import hashlib
  2. import io
  3. from os import path
  4. import pytest
  5. import slackviewer
  6. from slackviewer import archive
  7. from slackviewer.utils.six import to_bytes
  8. def test_SHA1_file():
  9. filepath = path.join("tests", "testarchive.zip")
  10. version = to_bytes(slackviewer.__version__)
  11. def SHA1_file(filepath, extra=b''):
  12. """The original unoptimized method (reads whole file instead of chunks)"""
  13. with io.open(filepath, 'rb') as f:
  14. return hashlib.sha1(f.read() + extra).hexdigest()
  15. expected = SHA1_file(filepath, version)
  16. actual = archive.SHA1_file(filepath, version)
  17. assert actual == expected