test_exiv2_parser.py 976 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import subprocess
  2. from .exiv2_parser import Exiv2Parser
  3. class MockPopen(object):
  4. """Mock Popen method"""
  5. def __init__(self, cmd, *, stdout):
  6. pass
  7. def communicate(self):
  8. """Mock communicate method of Popen"""
  9. return b'bash: command not found: exiv2', b''
  10. class MockPopenSuccess(MockPopen):
  11. def __init__(self, cmd, *, stdout):
  12. MockPopen.__init__(self, cmd, stdout=stdout)
  13. def communicate(self):
  14. """Mock communicate method of Popen"""
  15. return b'exiv2 0.26 001a00 (64 bit build)', b''
  16. def test_get_version_fail(mocker, monkeypatch):
  17. monkeypatch.setattr(subprocess, 'Popen', MockPopen)
  18. version_info = Exiv2Parser.get_exiv2_version()
  19. assert version_info is None
  20. def test_get_version_success(mocker, monkeypatch):
  21. monkeypatch.setattr(subprocess, 'Popen', MockPopenSuccess)
  22. version, commit = Exiv2Parser.get_exiv2_version()
  23. assert version == '0.26'
  24. assert commit == '001a00'