Coverage for core\test_leoGlobals.py : 99%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- coding: utf-8 -*-
2#@+leo-ver=5-thin
3#@+node:ekr.20210902164946.1: * @file ../unittests/core/test_leoGlobals.py
4#@@first
5"""Tests for leo.core.leoGlobals"""
7import os
8import stat
9import sys
10import textwrap
11from leo.core import leoGlobals as g
12from leo.core.leoTest2 import LeoUnitTest
14#@+others
15#@+node:ekr.20210902165045.1: ** class TestGlobals(LeoUnitTest)
16class TestGlobals(LeoUnitTest):
17 #@+others
18 #@+node:ekr.20210901140645.19: *3* TestGlobals.test_getLastTracebackFileAndLineNumber
19 def test_getLastTracebackFileAndLineNumber(self):
20 try:
21 assert False
22 except AssertionError:
23 fn, n = g.getLastTracebackFileAndLineNumber()
24 self.assertEqual(fn.lower(), __file__.lower())
26 #@+node:ekr.20210905203541.4: *3* TestGlobals.test_g_checkVersion
27 def test_g_checkVersion(self):
28 # for condition in ('<','<=','>','>='):
29 for v1, condition, v2 in (
30 ('8.4.12', '>', '8.4.3'),
31 ('1', '==', '1.0'),
32 ('2', '>', '1'),
33 ('1.2', '>', '1'),
34 ('2', '>', '1.2.3'),
35 ('1.2.3', '<', '2'),
36 ('1', '<', '1.1'),
37 ):
38 assert g.CheckVersion(v1, v2, condition=condition, trace=False)
39 #@+node:ekr.20210905203541.5: *3* TestGlobals.test_g_CheckVersionToInt
40 def test_g_CheckVersionToInt(self):
41 self.assertEqual(g.CheckVersionToInt('12'), 12)
42 self.assertEqual(g.CheckVersionToInt('2a5'), 2)
43 self.assertEqual(g.CheckVersionToInt('b2'), 0)
44 #@+node:ekr.20210905203541.6: *3* TestGlobals.test_g_comment_delims_from_extension
45 def test_g_comment_delims_from_extension(self):
46 # New in Leo 4.6, set_delims_from_language returns '' instead of None.
47 table = (
48 ('.c', ('//', '/*', '*/')),
49 ('.html', ('', '<!--', '-->')),
50 ('.py', ('#', '', '')),
51 ('.Globals', ('', '', '')),
52 )
53 for ext, expected in table:
54 result = g.comment_delims_from_extension(ext)
55 self.assertEqual(result, expected, msg=repr(ext))
56 #@+node:ekr.20210905203541.7: *3* TestGlobals.test_g_convertPythonIndexToRowCol
57 def test_g_convertPythonIndexToRowCol(self):
58 s1 = 'abc\n\np\nxy'
59 table1 = (
60 (-1, (0, 0)), # One too small.
61 (0, (0, 0)),
62 (1, (0, 1)),
63 (2, (0, 2)),
64 (3, (0, 3)), # The newline ends a row.
65 (4, (1, 0)),
66 (5, (2, 0)),
67 (6, (2, 1)),
68 (7, (3, 0)),
69 (8, (3, 1)),
70 (9, (3, 2)), # One too many.
71 (10, (3, 2)), # Two too many.
72 )
73 s2 = 'abc\n\np\nxy\n'
74 table2 = (
75 (9, (3, 2)),
76 (10, (4, 0)), # One too many.
77 (11, (4, 0)), # Two too many.
78 )
79 s3 = 'ab' # Test special case. This was the cause of off-by-one problems.
80 table3 = (
81 (-1, (0, 0)), # One too small.
82 (0, (0, 0)),
83 (1, (0, 1)),
84 (2, (0, 2)), # One too many.
85 (3, (0, 2)), # Two too many.
86 )
87 for n, s, table in ((1, s1, table1), (2, s2, table2), (3, s3, table3)):
88 for i, result in table:
89 row, col = g.convertPythonIndexToRowCol(s, i)
90 self.assertEqual(row, result[0], msg=f"n: {n}, i: {i}")
91 self.assertEqual(col, result[1], msg=f"n: {n}, i: {i}")
92 #@+node:ekr.20210905203541.8: *3* TestGlobals.test_g_convertRowColToPythonIndex
93 def test_g_convertRowColToPythonIndex(self):
94 s1 = 'abc\n\np\nxy'
95 s2 = 'abc\n\np\nxy\n'
96 table1 = (
97 (0, (-1, 0)), # One too small.
98 (0, (0, 0)),
99 (1, (0, 1)),
100 (2, (0, 2)),
101 (3, (0, 3)), # The newline ends a row.
102 (4, (1, 0)),
103 (5, (2, 0)),
104 (6, (2, 1)),
105 (7, (3, 0)),
106 (8, (3, 1)),
107 (9, (3, 2)), # One too large.
108 )
109 table2 = (
110 (9, (3, 2)),
111 (10, (4, 0)), # One two many.
112 )
113 for s, table in ((s1, table1), (s2, table2)):
114 for i, data in table:
115 row, col = data
116 result = g.convertRowColToPythonIndex(s, row, col)
117 self.assertEqual(i, result, msg=f"row: {row}, col: {col}, i: {i}")
118 #@+node:ekr.20210905203541.9: *3* TestGlobals.test_g_create_temp_file
119 def test_g_create_temp_file(self):
120 theFile = None
121 try:
122 theFile, fn = g.create_temp_file()
123 assert theFile
124 assert isinstance(fn, str)
125 finally:
126 if theFile:
127 theFile.close()
128 #@+node:ekr.20210905203541.10: *3* TestGlobals.test_g_ensureLeadingNewlines
129 def test_g_ensureLeadingNewlines(self):
130 s = ' \n \n\t\naa bc'
131 s2 = 'aa bc'
132 for i in range(3):
133 result = g.ensureLeadingNewlines(s, i)
134 val = ('\n' * i) + s2
135 self.assertEqual(result, val)
136 #@+node:ekr.20210905203541.11: *3* TestGlobals.test_g_ensureTrailingNewlines
137 def test_g_ensureTrailingNewlines(self):
138 s = 'aa bc \n \n\t\n'
139 s2 = 'aa bc'
140 for i in range(3):
141 result = g.ensureTrailingNewlines(s, i)
142 val = s2 + ('\n' * i)
143 self.assertEqual(result, val)
144 #@+node:ekr.20210905203541.12: *3* TestGlobals.test_g_find_word
145 def test_g_find_word(self):
146 table = (
147 ('abc a bc x', 'bc', 0, 6),
148 ('abc a bc x', 'bc', 1, 6),
149 ('abc a x', 'bc', 0, -1),
150 )
151 for s, word, i, expected in table:
152 actual = g.find_word(s, word, i)
153 self.assertEqual(actual, expected)
154 #@+node:ekr.20210905203541.14: *3* TestGlobals.test_g_fullPath
155 def test_g_fullPath(self):
156 c = self.c
157 child = c.rootPosition().insertAfter()
158 child.h = '@path abc'
159 grand = child.insertAsLastChild()
160 grand.h = 'xyz'
161 path = g.fullPath(c, grand, simulate=True)
162 end = g.os_path_normpath('abc/xyz')
163 assert path.endswith(end), repr(path)
164 #@+node:ekr.20210905203541.16: *3* TestGlobals.test_g_get_directives_dict
165 def test_g_get_directives_dict(self):
166 c = self.c
167 p = c.p
168 p.b = textwrap.dedent("""\
169 @language python
170 @comment a b c
171 # @comment must follow @language.
172 @tabwidth -8
173 @pagewidth 72
174 @encoding utf-8
175 """)
176 d = g.get_directives_dict(p)
177 self.assertEqual(d.get('language'), 'python')
178 self.assertEqual(d.get('tabwidth'), '-8')
179 self.assertEqual(d.get('pagewidth'), '72')
180 self.assertEqual(d.get('encoding'), 'utf-8')
181 self.assertEqual(d.get('comment'), 'a b c')
182 assert not d.get('path'), d.get('path')
183 #@+node:ekr.20210905203541.17: *3* TestGlobals.test_g_getDocString
184 def test_g_getDocString(self):
185 s1 = 'no docstring'
186 s2 = textwrap.dedent('''\
187 # comment
188 """docstring2."""
189 ''')
190 s3 = textwrap.dedent('''\
191 """docstring3."""
192 \'\'\'docstring2.\'\'\'
193 ''')
194 table = (
195 (s1, ''),
196 (s2, 'docstring2.'),
197 (s3, 'docstring3.'),
198 )
199 for s, result in table:
200 s2 = g.getDocString(s)
201 self.assertEqual(s2, result)
202 #@+node:ekr.20210905203541.18: *3* TestGlobals.test_g_getLine
203 def test_g_getLine(self):
204 s = 'a\ncd\n\ne'
205 for i, result in (
206 (-1, (0, 2)), # One too few.
207 (0, (0, 2)), (1, (0, 2)),
208 (2, (2, 5)), (3, (2, 5)), (4, (2, 5)),
209 (5, (5, 6)),
210 (6, (6, 7)),
211 (7, (6, 7)), # One too many.
212 ):
213 j, k = g.getLine(s, i)
214 self.assertEqual((j, k), result, msg=f"i: {i}, j: {j}, k: {k}")
215 #@+node:ekr.20210905203541.20: *3* TestGlobals.test_g_getWord
216 def test_g_getWord(self):
217 s = 'abc xy_z5 pdq'
218 i, j = g.getWord(s, 5)
219 self.assertEqual(s[i:j], 'xy_z5')
220 #@+node:ekr.20210905203541.21: *3* TestGlobals.test_g_guessExternalEditor
221 def test_g_guessExternalEditor(self):
222 c = self.c
223 val = g.guessExternalEditor(c)
224 assert val, 'no val' # This can be different on different platforms.
225 #@+node:ekr.20210905203541.22: *3* TestGlobals.test_g_handleUrl
226 def test_g_handleUrl(self):
227 c = self.c
228 if sys.platform.startswith('win'):
229 file_, http, unl1 = 'file://', 'http://', 'unl://'
230 fn1 = 'LeoDocs.leo#'
231 fn2 = 'doc/LeoDocs.leo#'
232 unl2 = '@settings-->Plugins-->wikiview plugin'
233 unl3 = '@settings-->Plugins-->wikiview%20plugin'
234 table = (
235 (http + 'writemonkey.com/index.php', ['browser']),
236 (file_ + 'x.py', ['os_startfile']),
237 (file_ + fn1, ['g.findUNL']),
238 (file_ + fn2, ['g.findUNL']),
239 (unl1 + fn1 + unl2, ['g.findUNL']),
240 (unl1 + fn1 + unl3, ['g.findUNL']),
241 (unl1 + '#' + unl2, ['g.findUNL']),
242 (unl1 + '#' + unl3, ['g.findUNL']),
243 (unl1 + unl2, ['g.findUNL']),
244 (unl1 + unl3, ['g.findUNL']),
245 )
246 for url, aList in table:
247 g.handleUrl(c=c, p=c.p, url=url)
248 #@+node:ekr.20210905203541.23: *3* TestGlobals.test_g_import_module
249 def test_g_import_module(self):
250 assert g.import_module('leo.core.leoAst')
251 # Top-level .py file.
252 #@+node:ekr.20210905203541.24: *3* TestGlobals.test_g_isDirective
253 def test_g_isDirective(self):
254 table = (
255 (True, '@language python\n'),
256 (True, '@tabwidth -4 #test\n'),
257 (True, '@others\n'),
258 (True, ' @others\n'),
259 (True, '@encoding\n'),
260 (False, '@encoding.setter\n'),
261 (False, '@encoding("abc")\n'),
262 (False, 'encoding = "abc"\n'),
263 )
264 for expected, s in table:
265 result = g.isDirective(s)
266 self.assertEqual(expected, bool(result), msg=s)
267 #@+node:ekr.20210905203541.25: *3* TestGlobals.test_g_match_word
268 def test_g_match_word(self):
269 table = (
270 (True, 0, 'a', 'a'),
271 (False, 0, 'a', 'b'),
272 (True, 0, 'a', 'a b'),
273 (False, 1, 'a', 'aa b'), # Tests bug fixed 2017/06/01.
274 (False, 1, 'a', '_a b'),
275 (False, 0, 'a', 'aw b'),
276 (False, 0, 'a', 'a_'),
277 (True, 2, 'a', 'b a c'),
278 (False, 0, 'a', 'b a c'),
279 )
280 for data in table:
281 expected, i, word, line = data
282 got = g.match_word(line + '\n', i, word)
283 self.assertEqual(expected, got)
284 #@+node:ekr.20210905203541.26: *3* TestGlobals.test_g_os_path_finalize_join_with_thumb_drive
285 def test_g_os_path_finalize_join_with_thumb_drive(self):
286 path1 = r'C:\Python32\Lib\site-packages\leo-editor\leo\core'
287 path2 = r'\N:Home\PTC_Creo\Creo.wmv'
288 path3 = r'N:\Home\PTC_Creo\Creo.wmv'
289 path12 = os.path.join(path1, path2)
290 path13 = os.path.join(path1, path3)
291 if 0:
292 print(path12, g.os.path.abspath(path12))
293 print(path13, g.os.path.abspath(path13))
294 #@+node:ekr.20210905203541.28: *3* TestGlobals.test_g_removeBlankLines
295 def test_g_removeBlankLines(self):
296 for s, expected in (
297 ('a\nb', 'a\nb'),
298 ('\n \n\nb\n', 'b\n'),
299 (' \t \n\n \n c\n\t\n', ' c\n'),
300 ):
301 result = g.removeBlankLines(s)
302 self.assertEqual(result, expected, msg=repr(s))
303 #@+node:ekr.20210905203541.30: *3* TestGlobals.test_g_removeLeadingBlankLines
304 def test_g_removeLeadingBlankLines(self):
305 for s, expected in (
306 ('a\nb', 'a\nb'),
307 ('\n \nb\n', 'b\n'),
308 (' \t \n\n\n c', ' c'),
309 ):
310 result = g.removeLeadingBlankLines(s)
311 self.assertEqual(result, expected, msg=repr(s))
312 #@+node:ekr.20210905203541.31: *3* TestGlobals.test_g_removeTrailing
313 def test_g_removeTrailing(self):
314 s = 'aa bc \n \n\t\n'
315 table = (
316 ('\t\n ', 'aa bc'),
317 ('abc\t\n ', ''),
318 ('c\t\n ', 'aa b'),
319 )
320 for arg, val in table:
321 result = g.removeTrailing(s, arg)
322 self.assertEqual(result, val)
323 #@+node:ekr.20210905203541.32: *3* TestGlobals.test_g_sanitize_filename
324 def test_g_sanitize_filename(self):
325 table = (
326 ('A25&()', 'A'), # Non-alpha characters.
327 ('B\tc', 'B c'), # Tabs.
328 ('"AB"', "'AB'"), # Double quotes.
329 ('\\/:|<>*:.', '_'), # Special characters.
330 ('_____________', '_'), # Combining underscores.
331 ('A' * 200, 'A' * 128), # Maximum length.
332 ('abc.', 'abc_'), # Trailing dots.
333 )
334 for s, expected in table:
335 got = g.sanitize_filename(s)
336 self.assertEqual(got, expected, msg=repr(s))
337 #@+node:ekr.20210905203541.33: *3* TestGlobals.test_g_scanAtHeaderDirectives_header
338 def test_g_scanAtHeaderDirectives_header(self):
339 c = self.c
340 aList = g.get_directives_dict_list(c.p)
341 g.scanAtHeaderDirectives(aList)
342 #@+node:ekr.20210905203541.35: *3* TestGlobals.test_g_scanAtHeaderDirectives_noheader
343 def test_g_scanAtHeaderDirectives_noheader(self):
344 c = self.c
345 aList = g.get_directives_dict_list(c.p)
346 g.scanAtHeaderDirectives(aList)
347 #@+node:ekr.20210905203541.36: *3* TestGlobals.test_g_scanAtLineendingDirectives_cr
348 def test_g_scanAtLineendingDirectives_cr(self):
349 c = self.c
350 p = c.p
351 p.b = '@lineending cr\n'
352 aList = g.get_directives_dict_list(p)
353 s = g.scanAtLineendingDirectives(aList)
354 self.assertEqual(s, '\r')
355 #@+node:ekr.20210905203541.37: *3* TestGlobals.test_g_scanAtLineendingDirectives_crlf
356 def test_g_scanAtLineendingDirectives_crlf(self):
357 c = self.c
358 p = c.p
359 p.b = '@lineending crlf\n'
360 aList = g.get_directives_dict_list(p)
361 s = g.scanAtLineendingDirectives(aList)
362 self.assertEqual(s, '\r\n')
363 #@+node:ekr.20210905203541.38: *3* TestGlobals.test_g_scanAtLineendingDirectives_lf
364 def test_g_scanAtLineendingDirectives_lf(self):
365 c = self.c
366 p = c.p
367 p.b = '@lineending lf\n'
368 aList = g.get_directives_dict_list(p)
369 s = g.scanAtLineendingDirectives(aList)
370 self.assertEqual(s, '\n')
371 #@+node:ekr.20210905203541.39: *3* TestGlobals.test_g_scanAtLineendingDirectives_nl
372 def test_g_scanAtLineendingDirectives_nl(self):
373 c = self.c
374 p = c.p
375 p.b = '@lineending nl\n'
376 aList = g.get_directives_dict_list(p)
377 s = g.scanAtLineendingDirectives(aList)
378 self.assertEqual(s, '\n')
379 #@+node:ekr.20210905203541.40: *3* TestGlobals.test_g_scanAtLineendingDirectives_platform
380 def test_g_scanAtLineendingDirectives_platform(self):
381 c = self.c
382 p = c.p
383 p.b = '@lineending platform\n'
384 aList = g.get_directives_dict_list(p)
385 s = g.scanAtLineendingDirectives(aList)
386 if sys.platform.startswith('win'):
387 self.assertEqual(s, '\r\n')
388 else:
389 self.assertEqual(s, '\n')
390 #@+node:ekr.20210905203541.41: *3* TestGlobals.test_g_scanAtPagewidthDirectives_minus_40
391 def test_g_scanAtPagewidthDirectives_minus_40(self):
392 c = self.c
393 p = c.p
394 p.b = '@pagewidth -40\n'
395 aList = g.get_directives_dict_list(p)
396 n = g.scanAtPagewidthDirectives(aList)
397 # The @pagewidth directive in the parent should control.
398 # Depending on how this test is run, the result could be 80 or None.
399 assert n in (None, 80), repr(n)
400 #@+node:ekr.20210905203541.42: *3* TestGlobals.test_g_scanAtPagewidthDirectives_40
401 def test_g_scanAtPagewidthDirectives_40(self):
402 c = self.c
403 p = c.p
404 p.b = '@pagewidth 40\n'
405 aList = g.get_directives_dict_list(p)
406 n = g.scanAtPagewidthDirectives(aList)
407 self.assertEqual(n, 40)
408 #@+node:ekr.20210905203541.43: *3* TestGlobals.test_g_scanAtTabwidthDirectives_6
409 def test_g_scanAtTabwidthDirectives_6(self):
410 c = self.c
411 p = c.p
412 p.b = '@tabwidth 6\n'
413 aList = g.get_directives_dict_list(p)
414 n = g.scanAtTabwidthDirectives(aList)
415 self.assertEqual(n, 6)
416 #@+node:ekr.20210905203541.44: *3* TestGlobals.test_g_scanAtTabwidthDirectives_minus_6
417 def test_g_scanAtTabwidthDirectives_minus_6(self):
418 c = self.c
419 p = c.p
420 p.b = '@tabwidth -6\n'
421 aList = g.get_directives_dict_list(p)
422 n = g.scanAtTabwidthDirectives(aList)
423 self.assertEqual(n, -6)
424 #@+node:ekr.20210905203541.45: *3* TestGlobals.test_g_scanAtWrapDirectives_nowrap
425 def test_g_scanAtWrapDirectives_nowrap(self):
426 c = self.c
427 p = c.p
428 p.b = '@nowrap\n'
429 aList = g.get_directives_dict_list(p)
430 s = g.scanAtWrapDirectives(aList)
431 assert s is False, repr(s)
432 #@+node:ekr.20210905203541.46: *3* TestGlobals.test_g_scanAtWrapDirectives_wrap_with_wrap_
433 def test_g_scanAtWrapDirectives_wrap_with_wrap_(self):
434 c = self.c
435 p = c.p
436 p.b = '@wrap\n'
437 aList = g.get_directives_dict_list(p)
438 s = g.scanAtWrapDirectives(aList)
439 assert s is True, repr(s)
440 #@+node:ekr.20210905203541.47: *3* TestGlobals.test_g_scanAtWrapDirectives_wrap_without_nowrap_
441 def test_g_scanAtWrapDirectives_wrap_without_nowrap_(self):
442 c = self.c
443 aList = g.get_directives_dict_list(c.p)
444 s = g.scanAtWrapDirectives(aList)
445 assert s is None, repr(s)
446 #@+node:ekr.20210905203541.48: *3* TestGlobals.test_g_set_delims_from_language
447 def test_g_set_delims_from_language(self):
448 table = (
449 ('c', ('//', '/*', '*/')),
450 ('python', ('#', '', '')),
451 ('xxxyyy', ('', '', '')),
452 )
453 for language, expected in table:
454 result = g.set_delims_from_language(language)
455 self.assertEqual(result, expected, msg=language)
456 #@+node:ekr.20210905203541.49: *3* TestGlobals.test_g_set_delims_from_string
457 def test_g_set_delims_from_string(self):
458 table = (
459 ('c', '@comment // /* */', ('//', '/*', '*/')),
460 ('c', '// /* */', ('//', '/*', '*/')),
461 ('python', '@comment #', ('#', '', '')),
462 ('python', '#', ('#', '', '')),
463 ('xxxyyy', '@comment a b c', ('a', 'b', 'c')),
464 ('xxxyyy', 'a b c', ('a', 'b', 'c')),
465 )
466 for language, s, expected in table:
467 result = g.set_delims_from_string(s)
468 self.assertEqual(result, expected, msg=language)
469 #@+node:ekr.20210905203541.50: *3* TestGlobals.test_g_skip_blank_lines
470 def test_g_skip_blank_lines(self):
471 end = g.skip_blank_lines("", 0)
472 self.assertEqual(end, 0)
473 end = g.skip_blank_lines(" ", 0)
474 self.assertEqual(end, 0)
475 end = g.skip_blank_lines("\n", 0)
476 self.assertEqual(end, 1)
477 end = g.skip_blank_lines(" \n", 0)
478 self.assertEqual(end, 2)
479 end = g.skip_blank_lines("\n\na\n", 0)
480 self.assertEqual(end, 2)
481 end = g.skip_blank_lines("\n\n a\n", 0)
482 self.assertEqual(end, 2)
483 #@+node:ekr.20210905203541.51: *3* TestGlobals.test_g_skip_line
484 def test_g_skip_line(self):
485 s = 'a\n\nc'
486 for i, result in (
487 (-1, 2), # One too few.
488 (0, 2), (1, 2),
489 (2, 3),
490 (3, 4),
491 (4, 4), # One too many.
492 ):
493 j = g.skip_line(s, i)
494 self.assertEqual(j, result, msg=i)
495 #@+node:ekr.20210905203541.52: *3* TestGlobals.test_g_skip_to_end_of_line
496 def test_g_skip_to_end_of_line(self):
497 s = 'a\n\nc'
498 for i, result in (
499 (-1, 1), # One too few.
500 (0, 1), (1, 1),
501 (2, 2),
502 (3, 4),
503 (4, 4), # One too many.
504 ):
505 j = g.skip_to_end_of_line(s, i)
506 self.assertEqual(j, result, msg=i)
507 #@+node:ekr.20210905203541.53: *3* TestGlobals.test_g_skip_to_start_of_line
508 def test_g_skip_to_start_of_line(self):
509 s1 = 'a\n\nc'
510 table1 = (
511 (-1, 0), # One too few.
512 (0, 0), (1, 0),
513 (2, 2),
514 (3, 3),
515 (4, 4), # One too many.
516 )
517 s2 = 'a\n'
518 table2 = (
519 (1, 0),
520 (2, 2),
521 ) # A special case at end.
522 for s, table in ((s1, table1), (s2, table2)):
523 for i, result in table:
524 j = g.skip_to_start_of_line(s, i)
525 self.assertEqual(j, result, msg=i)
526 #@+node:ekr.20210905203541.54: *3* TestGlobals.test_g_splitLongFileName
527 def test_g_splitLongFileName(self):
528 table = (
529 r'abcd/xy\pdqabc/aaa.py',
530 )
531 for s in table:
532 g.splitLongFileName(s, limit=3)
533 #@+node:ekr.20210905203541.55: *3* TestGlobals.test_g_stripPathCruft
534 def test_g_stripPathCruft(self):
535 table = (
536 (None, None), # Retain empty paths for warnings.
537 ('', ''),
538 (g.app.loadDir, g.app.loadDir),
539 ('<abc>', 'abc'),
540 ('"abc"', 'abc'),
541 ("'abc'", 'abc'),
542 )
543 for path, expected in table:
544 result = g.stripPathCruft(path)
545 self.assertEqual(result, expected)
546 #@+node:ekr.20210905203541.56: *3* TestGlobals.test_g_warnOnReadOnlyFile
547 def test_g_warnOnReadOnlyFile(self):
548 c = self.c
549 fc = c.fileCommands
550 path = g.os_path_finalize_join(g.app.loadDir, '..', 'test', 'test-read-only.txt')
551 if os.path.exists(path):
552 os.chmod(path, stat.S_IREAD)
553 fc.warnOnReadOnlyFiles(path)
554 assert fc.read_only
555 else:
556 fc.warnOnReadOnlyFiles(path)
557 #@-others
558#@-others
559#@-leo