File: test_fs_cache_dir.py

package info (click to toggle)
opencv 4.10.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 282,092 kB
  • sloc: cpp: 1,178,079; xml: 682,621; python: 49,092; lisp: 31,150; java: 25,469; ansic: 11,039; javascript: 6,085; sh: 1,214; cs: 601; perl: 494; objc: 210; makefile: 173
file content (41 lines) | stat: -rw-r--r-- 1,304 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Python 2/3 compatibility
from __future__ import print_function

import numpy as np
import cv2 as cv
import os
import datetime

from tests_common import NewOpenCVTests

class get_cache_dir_test(NewOpenCVTests):
    def test_get_cache_dir(self):
        #New binding
        path = cv.utils.fs.getCacheDirectoryForDownloads()
        self.assertTrue(os.path.exists(path))
        self.assertTrue(os.path.isdir(path))

    def get_cache_dir_imread_interop(self, ext):
        path = cv.utils.fs.getCacheDirectoryForDownloads()
        gold_image = np.ones((16, 16, 3), np.uint8)
        read_from_file = np.zeros((16, 16, 3), np.uint8)
        test_file_name = os.path.join(path, "test." + ext)
        try:
            cv.imwrite(test_file_name, gold_image)
            read_from_file = cv.imread(test_file_name)
        finally:
            os.remove(test_file_name)

        self.assertEqual(cv.norm(gold_image, read_from_file), 0)

    def test_get_cache_dir_imread_interop_png(self):
        self.get_cache_dir_imread_interop("png")

    def test_get_cache_dir_imread_interop_jpeg(self):
        self.get_cache_dir_imread_interop("jpg")

    def test_get_cache_dir_imread_interop_tiff(self):
        self.get_cache_dir_imread_interop("tif")

if __name__ == '__main__':
    NewOpenCVTests.bootstrap()