test_fs_cache_dir.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Python 2/3 compatibility
  2. from __future__ import print_function
  3. import numpy as np
  4. import cv2 as cv
  5. import os
  6. import datetime
  7. from tests_common import NewOpenCVTests
  8. class get_cache_dir_test(NewOpenCVTests):
  9. def test_get_cache_dir(self):
  10. #New binding
  11. path = cv.utils.fs.getCacheDirectoryForDownloads()
  12. self.assertTrue(os.path.exists(path))
  13. self.assertTrue(os.path.isdir(path))
  14. def get_cache_dir_imread_interop(self, ext):
  15. path = cv.utils.fs.getCacheDirectoryForDownloads()
  16. gold_image = np.ones((16, 16, 3), np.uint8)
  17. read_from_file = np.zeros((16, 16, 3), np.uint8)
  18. test_file_name = os.path.join(path, "test." + ext)
  19. try:
  20. cv.imwrite(test_file_name, gold_image)
  21. read_from_file = cv.imread(test_file_name)
  22. finally:
  23. os.remove(test_file_name)
  24. self.assertEqual(cv.norm(gold_image, read_from_file), 0)
  25. def test_get_cache_dir_imread_interop_png(self):
  26. self.get_cache_dir_imread_interop("png")
  27. def test_get_cache_dir_imread_interop_jpeg(self):
  28. self.get_cache_dir_imread_interop("jpg")
  29. def test_get_cache_dir_imread_interop_tiff(self):
  30. self.get_cache_dir_imread_interop("tif")
  31. if __name__ == '__main__':
  32. NewOpenCVTests.bootstrap()