Coverage for test_syntax.py: 100%
33 statements
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 10:21 -0500
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 10:21 -0500
1# -*- coding: utf-8 -*-
2#@+leo-ver=5-thin
3#@+node:ekr.20210901140718.1: * @file ../unittests/test_syntax.py
4#@@first
5"""Syntax tests, including a check that Leo will continue to load!"""
6# pylint: disable=no-member
7import glob
8from leo.core import leoGlobals as g
9from leo.core.leoTest2 import LeoUnitTest
10#@+others
11#@+node:ekr.20210901140855.1: ** class TestSyntax(LeoUnitTest)
12class TestSyntax(LeoUnitTest):
13 """Unit tests checking syntax of Leo files."""
14 #@+others
15 #@+node:ekr.20210901140645.1: *3* TestSyntax.tests...
16 #@+node:ekr.20210910102910.1: *4* TestSyntax.check_syntax
17 def check_syntax(self, fileName, s):
18 """Called by a unit test to check the syntax of a file."""
19 try:
20 s = s.replace('\r', '')
21 tree = compile(s + '\n', fileName, 'exec')
22 del tree # #1454: Suppress -Wd ResourceWarning.
23 return True
24 except SyntaxError: # pragma: no cover
25 raise SyntaxError(fileName) # pylint: disable=raise-missing-from
26 except Exception: # pragma: no cover
27 g.trace("unexpected error in:", fileName)
28 raise
29 #@+node:ekr.20210901140645.21: *4* TestSyntax.test_syntax_of_all_files
30 def test_syntax_of_all_files(self):
31 skip_tuples = (
32 ('extensions', 'asciidoc.py'),
33 ('test', 'scriptFile.py'),
34 )
35 join = g.os_path_finalize_join
36 skip_list = [join(g.app.loadDir, '..', a, b) for a, b in skip_tuples]
37 n = 0
38 for theDir in ('core', 'external', 'extensions', 'modes', 'plugins', 'scripts', 'test'):
39 path = g.os_path_finalize_join(g.app.loadDir, '..', theDir)
40 self.assertTrue(g.os_path_exists(path), msg=path)
41 aList = glob.glob(g.os_path_join(path, '*.py'))
42 if g.isWindows:
43 aList = [z.replace('\\', '/') for z in aList]
44 for z in aList:
45 if z not in skip_list:
46 n += 1
47 fn = g.shortFileName(z)
48 s, e = g.readFileIntoString(z)
49 self.assertTrue(self.check_syntax(fn, s), msg=fn)
50 #@+node:ekr.20210901140645.22: *4* TestSyntax.test_syntax_of_setup_py
51 def test_syntax_of_setup_py(self):
52 fn = g.os_path_finalize_join(g.app.loadDir, '..', '..', 'setup.py')
53 # Only run this test if setup.py exists: it may not in the actual distribution.
54 if not g.os_path_exists(fn):
55 self.skipTest('setup.py not found') # pragma: no cover
56 s, e = g.readFileIntoString(fn)
57 assert self.check_syntax(fn, s)
58 #@-others
59#@-others
60#@-leo