Test Failed
Push — master ( 4fe9a7...21a58b )
by Steffen
04:43
created

TestSauceNao.generate_small_jpg()   A

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 1
nop 1
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
4
import os
5
import shutil
6
import unittest
7
from uuid import uuid4
8
9
from PIL import Image
10
11
from saucenao import Worker
12
13
14
class TestSauceNao(unittest.TestCase):
15
    SAUCENAO_MIN_WIDTH = 3
16
    SAUCENAO_MIN_HEIGHT = 3
17
18
    def setUp(self):
19
        """Constructor for unittest classes
20
21
        :return:
22
        """
23
        directory = str(uuid4())
24
        os.mkdir(directory)
25
        self.directory = os.path.abspath(directory)
26
27
    def tearDown(self):
28
        """Destructor for unittest classes
29
30
        :return:
31
        """
32
        shutil.rmtree(self.directory)
33
34
    def generate_small_jpg(self):
35
        """Generate a rather small jpg file to upload faster(631 bytes)
36
37
        :return:
38
        """
39
        file_path = os.path.join(self.directory, str(uuid4()) + ".jpg")
40
        im = Image.new("RGB", (self.SAUCENAO_MIN_WIDTH, self.SAUCENAO_MIN_HEIGHT))
41
        im.save(file_path, "JPEG")
42
        return file_path
43
44
    def test_run_worker(self):
45
        """Test the run_application function
46
47
        :return:
48
        """
49
        with open(self.generate_small_jpg(), "rb") as test_file:
50
            # test with file object and file path
51
            worker = Worker(files=(test_file, self.generate_small_jpg()))
52
            worker.run()
53
54
55
if __name__ == '__main__':
56
    suite = unittest.TestLoader().loadTestsFromTestCase(TestSauceNao)
57
    unittest.TextTestRunner(verbosity=2).run(suite)
58