tests.test_init   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 32
dl 0
loc 61
rs 10
c 0
b 0
f 0

4 Methods

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