-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_1_function_remove_duplicate_extension.py
156 lines (129 loc) · 7.77 KB
/
test_1_function_remove_duplicate_extension.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import unittest
import fix_wrong_image_extensions
class TestRemoveDuplicateExtension(unittest.TestCase): #plyint: disable=C0103,C0114,C0115
def test_remove_duplicate_extension_no_extension_present_but_has_a_valid_type(self):
input_filename = "a"
image_type = "jpg"
expected_result = "a.jpg"
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
def test_remove_duplicate_extension_no_extension_present_and_no_image_type(self):
input_filename = "file_without_extension_and_no_image_type"
image_type = None
expected_result = input_filename
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
def test_remove_duplicate_extension_single_extension(self):
input_filename = "file.jpg"
image_type = "jpg"
expected_result = input_filename
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
def test_remove_duplicate_extension_duplicate_extension(self):
input_filename = "file.jpg.jpg"
image_type = "jpg"
expected_result = "file.jpg"
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
def test_remove_duplicate_extension_multiple_extensions(self):
input_filename = "file.jpg.png.gif.jpg"
image_type = "jpg"
expected_result = "file.jpg"
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
def test_remove_duplicate_extension_multiple_extensions_2(self):
input_filename = "file.jpg.png.milkshake.jpg"
image_type = "jpg"
expected_result = "file.milkshake.jpg"
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
def test_possibly_redundant_chatgpt_inspired_2(self):
input_filename = "file.png.gif.jpg"
image_type = "jpg"
expected_result = "file.jpg"
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
def test_possibly_redundant_chatgpt_inspired_2B(self):
input_filename = "file.png.gif.jpg.jpg"
image_type = "jpg"
expected_result = "file.jpg"
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
def test_possibly_redundant_chatgpt_inspired_2C(self):
input_filename = "file.png.gif.jpg.jpg.gif"
image_type = "jpg"
expected_result = "file.jpg"
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
def test_possibly_redundant_chatgpt_inspired_2D(self):
input_filename = "file.png.gif.jpg.jpg.gif.jpg"
image_type = "jpg"
expected_result = "file.jpg"
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
def test_remove_duplicate_extension_interleaved_extensions(self):
input_filename = "file.jpg.png.jpg.gif"
image_type = "jpg"
expected_result = "file.jpg"
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
def test_remove_duplicate_extension_image_type_not_in_extensions(self):
input_filename = "file.png.png.gif"
image_type = "jpg"
expected_result = "file.jpg"
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
#########################################################################################################################################
############ Finally got the above 12 working, so can finally talke this one -- which actualy worked right the first time yayyyy
#########################################################################################################################################
def test_annoying_outer_case_1(self):
input_filename = "1831450523.jpg.crdownload.jpg"
image_type = "jpg"
expected_result = "1831450523.crdownload.jpg"
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
def test_annoying_outer_case_2(self):
input_filename = "1831450523.jpg.crdownload.jpg.jpg"
image_type = "jpg"
expected_result = "1831450523.crdownload.jpg"
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
def test_annoying_realworld_case_2(self):
input_filename = "2021-06-02 19.23.23.png"
image_type = "png"
expected_result = input_filename
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
def test_repeating_nonimage_ext_at_end_1(self):
input_filename = "something.extension.extension"
image_type = None
expected_result = "something.extension"
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
def test_repeating_nonimage_ext_at_end_2(self):
input_filename = "something.extension.extension"
image_type = "jpg"
expected_result = "something.extension.jpg"
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
def test_repeating_extension_only(self):
input_filename = "jpg.jpg"
image_type = "jpg"
expected_result = "jpg.jpg"
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
def test_unwritten_functionality_1(self):
input_filename = "media_FM6TGSyXsAE4bRp.jpg_name=orig"
image_type = "jpg"
expected_result = "media_FM6TGSyXsAE4bRp.jpg"
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
def test_unwritten_functionality_2(self):
input_filename = "whatever.jpg_large"
image_type = "jpg"
expected_result = "whatever.jpg"
result = fix_wrong_image_extensions.remove_duplicate_extension(input_filename, image_type, testing=True)
self.assertEqual(result, expected_result)
# ^^^^^^^^^^^^^^^ do this before running python-only of this onto porn-main [new already done]
if __name__ == '__main__':
unittest.main()