Passed
Push — master ( 6f7e7a...5b5e86 )
by Steffen
01:26
created

TestInit.setUp()   A

Complexity

Conditions 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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