Total Complexity | 5 |
Total Lines | 58 |
Duplicated Lines | 0 % |
Changes | 0 |
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 |