Test Failed
Push — master ( 1967f0...88899d )
by Steffen
04:26
created

tests.test_saucenao   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 30
dl 0
loc 59
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A TestSauceNao.generate_small_jpg() 0 9 1
A TestSauceNao.test_run_application() 0 9 2
A TestSauceNao.setUp() 0 9 1
A TestSauceNao.tearDown() 0 6 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 SauceNao
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
        self.saucenao = SauceNao()
27
28
    def tearDown(self):
29
        """Destructor for unittest classes
30
31
        :return:
32
        """
33
        shutil.rmtree(self.directory)
34
35
    def generate_small_jpg(self):
36
        """Generate a rather small jpg file to upload faster(631 bytes)
37
38
        :return:
39
        """
40
        file_path = os.path.join(self.directory, str(uuid4()) + ".jpg")
41
        im = Image.new("RGB", (self.SAUCENAO_MIN_WIDTH, self.SAUCENAO_MIN_HEIGHT))
42
        im.save(file_path, "JPEG")
43
        return file_path
44
45
    def test_run_application(self):
46
        """Test the run_application function
47
48
        :return:
49
        """
50
        with open(self.generate_small_jpg(), "rb") as test_file:
51
            results = self.saucenao.check_file_object(test_file)
52
            self.assertIsInstance(results, list)
53
            print(results)
54
55
56
if __name__ == '__main__':
57
    suite = unittest.TestLoader().loadTestsFromTestCase(TestSauceNao)
58
    unittest.TextTestRunner(verbosity=2).run(suite)
59