-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
295 lines (199 loc) · 7.97 KB
/
tests.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
import unittest
import os
test_directory = './tests'
class TestIxParsing(unittest.TestCase):
def test_find_ix(self):
import ix
from ix import Parser
ix.root_path = test_directory
files = Parser.find_ix(test_directory + '/simple')
self.assertEqual(len(files), 1)
def test_read_config(self):
import ix
from ix import Parser
ix.root_path = test_directory
config = ix.read_config('./tests/test_read_config/ixrc')
self.assertTrue(config['data'] is not None)
def test_prefix(self):
'''
Test that the prefix configuration field does the following:
1. Replaces the original prefix
2. Does not replace variables that are included with the old prefix
3. Does replace variables that are included with the new prefix
'''
import ix
from ix import Parser
ix.root_path = test_directory
ix.config = ix.read_config('./tests/with_prefix/ixrc')
files = Parser.find_ix(test_directory + '/with_prefix')
file = files[0]
self.assertEqual(file.prefix, '$')
with open(file.original_path) as f:
opened = f.read()
self.assertTrue(opened.count('${{') == 3)
self.assertTrue(opened.count('#{{') == 3)
f.close()
parsed = file.parse()
self.assertTrue(parsed.count('${{') == 0)
self.assertTrue(parsed.count('#{{') == 3)
def test_output_directory(self):
'''
Test that the output configuration field does the following:
1. Replaces bash environment variables
2. Replaces ix variables
3. When no name is specified, it will store the file under the same name
'''
import ix
from ix import Parser
ix.root_path = test_directory
ix.config = ix.read_config('./tests/no_as/ixrc')
files = Parser.find_ix(test_directory + '/no_as')
file = files[0] # The only one
self.assertTrue(file.get_output_path() != '')
self.assertTrue('$HOME' not in file.get_output_path())
self.assertFalse(any(x in file.get_output_path() for x in ['#{{', '}}', '#']))
self.assertTrue('palace' in file.get_output_path())
self.assertTrue(file.get_output_path().endswith('to'))
def test_output_filename(self):
'''
Test that the filename configuration field does the following:
1. Updates the original file name to the new one
2. That new filename gets appended to the directory of the file
'''
import ix
from ix import Parser
ix.root_path = test_directory
ix.config = ix.read_config('./tests/filename/ixrc')
files = Parser.find_ix(test_directory + '/with_filename')
file = files[0]
name = file.name
test_name = 'testName'
self.assertEqual(name, test_name)
self.assertEqual(file.get_output_path(), file.to + '/testName')
def test_file_permissions(self):
'''
Test that the access configuration field updates the final file
permissions
'''
import ix
from ix import Parser
ix.root_path = test_directory
files = Parser.find_ix(test_directory + '/with_access')
file = files[0]
self.assertEqual(file.access, int('777', 8))
output_path = file.get_output_path()
Parser.process_file(file)
self.assertTrue(os.access(output_path, os.X_OK))
def test_ix_extension_when_in_the_same_directory(self):
'''
Make sure that the processed file gets saved with an '.ix'
extension when no custom directory or filename is provided
as to not overwrite anything in the current one.
'''
import ix
from ix import Parser
ix.root_path = test_directory
ix.config = ix.read_config('./tests/no_to/ixrc')
files = Parser.find_ix(test_directory + '/no_to')
file = files[0]
print(file.name)
self.assertTrue(file.get_output_path().endswith('.ix'))
def test_file_variable_expansion(self):
'''
Make sure ix variables get replaced throughout the
entire file.
'''
import ix
from ix import Parser
ix.root_path = test_directory
ix.config = ix.read_config('./tests/with_variables/ixrc')
files = Parser.find_ix(test_directory + '/with_variables')
file = files[0]
# Check that there are variables within the file
with open(file.original_path) as f:
opened = f.read()
self.assertTrue(opened.count('@{{') == 3)
f.close()
# Parse the file
parsed = file.parse()
# Check that there are no more variables within the file
self.assertTrue(parsed.count('@{{') == 0)
def test_helper_file_inclusion(self):
import ix
from ix import Parser
ix.root_path = test_directory + '/helpers_inclusion'
ix.config = ix.read_config(ix.root_path + '/ixrc')
file = Parser.find_ix(ix.root_path).pop()
parsed = file.parse()
self.assertTrue('UNIQUE{ TEMPLATE_CONTENT }' in parsed)
def test_helper_casing(self):
import ix
from ix import Parser
ix.root_path = test_directory + '/helpers_casing'
ix.config = ix.read_config(ix.root_path + '/ixrc')
file = Parser.find_ix(ix.root_path).pop()
parsed = file.parse()
self.assertTrue('UPPERCASE' in parsed)
self.assertTrue('lowercase' in parsed)
self.assertTrue('#[[' not in parsed)
def test_helper_colors(self):
import ix
from ix import Parser
ix.root_path = test_directory + '/helpers_colors'
ix.config = ix.read_config(ix.root_path + '/ixrc')
file = Parser.find_ix(ix.root_path).pop()
parsed = file.parse()
# rgb
self.assertTrue('rgb(24, 27, 33)' in parsed)
# just rgb
self.assertTrue('rgb(123, 123, 123)' in parsed)
# just rgb override opacity
self.assertTrue('rgba(123, 123, 123, 0.3)' in parsed)
# rgba
self.assertTrue('rgba(24, 27, 33, 0.5)' in parsed)
# rgba from hexa
self.assertTrue('rgba(24, 27, 33, 0.47' in parsed)
# rgb from variable
self.assertTrue('rgb(0, 0, 0)' in parsed)
# rgb from variable with opacity
self.assertTrue('rgba(0, 0, 0, 0.5)' in parsed)
# rgb from hex alpha variable
self.assertTrue('rgba(0, 0, 0, 0.3)' in parsed)
# rgb hex alpha variable override
self.assertTrue('rgba(0, 0, 0, 0.8)' in parsed)
# hex
self.assertTrue('#ffffff' in parsed)
# just hex
self.assertTrue('#7289da' in parsed)
# just hex override opacity
self.assertTrue('#7289da4c' in parsed)
# hex with alpha
self.assertTrue('#ffffffe6' in parsed)
# hex with alpha from rgba
self.assertTrue('#ffffff4c' in parsed)
# hex from variable
self.assertTrue('#f2f2f2' in parsed)
# hex from variable with opacity
self.assertTrue('#f2f2f280' in parsed)
# hex from rgba variable
self.assertTrue('#f2f2f24c' in parsed)
# hex rgba variable override
self.assertTrue('#f2f2f266' in parsed)
# hex rgb to argb
self.assertTrue('#66f2f2f2' in parsed)
# hex rgba to argb
self.assertTrue('#66000000' in parsed)
def test_helper_variable_format(self):
import ix
from ix import Parser
ix.root_path = test_directory + '/helpers'
ix.config = ix.read_config(ix.root_path + '/ixrc')
file = Parser.find_ix(ix.root_path).pop()
parsed = file.parse()
self.assertTrue('COOLVALUE' in parsed)
self.assertTrue('coolvalue' in parsed)
if __name__ == '__main__':
# Windows handles colors weirdly by default
if os.name == 'nt':
os.system('color')
unittest.main()