Test Failed
Push — master ( 8192fe...83ef1f )
by Steffen
02:25
created

tests.files.test_filehandler   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 33
dl 0
loc 68
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A TestFileHandler.setUp() 0 15 2
A TestFileHandler.test_get_files() 0 15 1
A TestFileHandler.test_move_to_category() 0 12 2
A TestFileHandler.tearDown() 0 6 1
1
#!/usr/bin/python
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
# -*- coding: utf-8 -*-
3
import os
4
import shutil
5
import unittest
6
import uuid
7
from time import sleep
8
9
from saucenao import FileHandler, Filter
10
11
12
class TestFileHandler(unittest.TestCase):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
13
    """
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
14
    test cases for the file handler operations
15
    """
16
17
    def setUp(self):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
18
        """Constructor for the unittest
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
19
20
        :return:
21
        """
22
        self.dir = os.path.join(os.getcwd(), str(uuid.uuid4()))
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
23
        os.mkdir(self.dir)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
24
25
        file_name = os.path.join(self.dir, str(uuid.uuid4()))
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
26
        # create a file
27
        with open(file_name, "wb") as _:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
28
            pass
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
29
30
        # wait for file operations to finish
31
        sleep(0.5)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
32
33
    def tearDown(self):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
34
        """Destructor for the unittest
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
35
36
        :return:
37
        """
38
        shutil.rmtree(self.dir)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
39
40
    def test_get_files(self):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
41
        """Test the get_files function of the file handler
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
42
43
        :return:
44
        """
45
        files = FileHandler.get_files(directory=self.dir)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
46
        self.assertEqual(len(list(files)), 1)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
47
48
        file_filter = Filter(assert_is_folder=True)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
49
        files = FileHandler.get_files(directory=self.dir, file_filter=file_filter)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (82/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
50
        self.assertEqual(len(list(files)), 0)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
51
52
        file_filter = Filter(assert_is_file=True)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
53
        files = FileHandler.get_files(directory=self.dir, file_filter=file_filter)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (82/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
54
        self.assertEqual(len(list(files)), 1)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
55
56
    def test_move_to_category(self):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
57
        """Test moving the file to a category folder
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
58
59
        :return:
60
        """
61
        files = list(FileHandler.get_files(directory=self.dir))
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
62
        self.assertEqual(len(files), 1)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
63
        for file in files:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
64
            FileHandler.move_to_category(file, 'Example Category', self.dir)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
65
66
        new_files = FileHandler.get_files(directory=self.dir)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
67
        self.assertEqual(len(list(new_files)), 0)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
68