Completed
Pull Request — master (#2100)
by Udayan
02:02
created

EnsureFilesPresentTest.setUp()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
1
import unittest
2
from os.path import abspath
3
4
from coalib.results.ResultFilter import ensure_files_present
5
6
7
class EnsureFilesPresentTest(unittest.TestCase):
8
9
    def setUp(self):
10
        self.maxDiff = None
11
12
    def test_removed_file(self):
13
        test_file = ["abc"]
14
        test_file_dict = {"test_file": test_file}
15
        test_mod_file_dict = {}
16
17
        ensure_files_present(test_file_dict, test_mod_file_dict)
18
19
        self.assertEqual(
20
            test_mod_file_dict,
21
            {"test_file": []})
22
23
    def test_added_file(self):
24
        test_file = ["abc"]
25
        test_file_dict = {}
26
        test_mod_file_dict = {"test_file": test_file}
27
28
        ensure_files_present(test_file_dict, test_mod_file_dict)
29
30
        self.assertEqual(
31
            test_file_dict,
32
            {"test_file": []})
33
34
    def test_file_renaming(self):
35
        testfile_1 = ['1\n', '2\n']
36
        testfile_2 = ['3\n', '4\n', '5\n']
37
38
        tf1 = abspath('tf1')
39
        tf2 = abspath('tf2')
40
        tf1_new = abspath('tf1_new')
41
42
        original_file_dict = {tf1: testfile_1, tf2: testfile_2}
43
        modified_file_dict = {tf1_new: testfile_1}
44
45
        renamed_files = ensure_files_present(original_file_dict,
46
                                             modified_file_dict)
47
48
        self.assertEqual({tf1: tf1_new}, renamed_files)
49
50
    def test_file_deletion(self):
51
        testfile_1 = ['1\n', '2\n']
52
        testfile_2 = ['3\n', '4\n', '5\n']
53
54
        tf1 = abspath('tf1')
55
        tf2 = abspath('tf2')
56
57
        original_file_dict = {tf1: testfile_1, tf2: testfile_2}
58
        modified_file_dict = {tf1: testfile_1}
59
60
        renamed_files = ensure_files_present(original_file_dict,
61
                                             modified_file_dict)
62
63
        self.assertEqual({}, renamed_files)
64
65
    def test_file_renaming_changed_file(self):
66
        testfile_1 = ['1\n', '2\n']
67
        testfile_2 = ['3\n', '4\n', '5\n']
68
69
        tf1 = abspath('tf1')
70
        tf2 = abspath('tf2')
71
72
        testfile_2_new = ['6\n', '4\n', '5\n']
73
        tf2_new = abspath('tf2_new')
74
75
        original_file_dict = {tf1: testfile_1, tf2: testfile_2}
76
        modified_file_dict = {tf2_new: testfile_2_new}
77
78
        renamed_files = ensure_files_present(original_file_dict,
79
                                             modified_file_dict)
80
81
        self.assertEqual({tf2: tf2_new}, renamed_files)
82
83
    def test_file_addition_deletion_similar_files(self):
84
        testfile_1 = ['1\n', '2\n']
85
        testfile_2 = ['3\n', '4\n', '5\n']
86
87
        tf1 = abspath('tf1')
88
        tf2 = abspath('tf2')
89
90
        testfile_2_new = ['3\n']
91
        tf2_new = abspath('tf2_new')
92
93
        original_file_dict = {tf1: testfile_1, tf2: testfile_2}
94
        modified_file_dict = {tf2_new: testfile_2_new}
95
96
        renamed_files = ensure_files_present(original_file_dict,
97
                                             modified_file_dict)
98
99
        self.assertEqual({}, renamed_files)
100
101
        testfile_1 = ['1\n', '2\n']
102
        testfile_2 = ['3\n', '4\n', '5\n']
103
104
        tf1 = abspath('tf1')
105
        tf2 = abspath('tf2')
106
107
        testfile_2_new = ['1\n', '2\n', '0\n', '1\n', '2\n', '1\n', '2\n']
108
        tf2_new = abspath('tf2_new')
109
110
        original_file_dict = {tf1: testfile_1, tf2: testfile_2}
111
        modified_file_dict = {tf2_new: testfile_2_new}
112
113
        renamed_files = ensure_files_present(original_file_dict,
114
                                             modified_file_dict)
115
116
        self.assertEqual({}, renamed_files)
117