-
Notifications
You must be signed in to change notification settings - Fork 205
/
Copy pathstyle.py
116 lines (99 loc) · 4.32 KB
/
style.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
##
# Copyright 2016-2025 Ghent University
#
# This file is part of EasyBuild,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
# with support of Ghent University (http://ugent.be/hpc),
# the Flemish Supercomputer Centre (VSC) (https://vscentrum.be/nl/en),
# Flemish Research Foundation (FWO) (http://www.fwo.be/en)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# https://github.com/easybuilders/easybuild
#
# EasyBuild is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation v2.
#
# EasyBuild is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with EasyBuild. If not, see <http://www.gnu.org/licenses/>.
##
"""
Style tests for easyconfig files.
:author: Ward Poelmans (Ghent University)
"""
import glob
import os
import sys
from test.framework.utilities import EnhancedTestCase, TestLoaderFiltered
from unittest import TextTestRunner
from easybuild.base import fancylogger
from easybuild.framework.easyconfig.style import _eb_check_trailing_whitespace, check_easyconfigs_style
try:
import pycodestyle # noqa
except ImportError:
pass
class StyleTest(EnhancedTestCase):
log = fancylogger.getLogger("StyleTest", fname=False)
def test_style_conformance(self):
"""Check the easyconfigs for style"""
if 'pycodestyle' not in sys.modules:
print("Skipping test_style_conformance pycodestyle is not available")
return
# all available easyconfig files
test_easyconfigs_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs')
specs = glob.glob('%s/*.eb' % test_easyconfigs_path)
specs = sorted(specs)
result = check_easyconfigs_style(specs)
self.assertEqual(result, 0, "No code style errors (and/or warnings) found.")
def test_check_trailing_whitespace(self):
"""Test for trailing whitespace check."""
if 'pycodestyle' not in sys.modules:
print("Skipping test_check_trailing_whitespace is not available")
return
lines = [
"name = 'foo'", # no trailing whitespace
"version = '1.2.3' ", # trailing whitespace
" ", # blank line with whitespace included
'''description = """start of long description, ''', # trailing whitespace, but allowed in description
''' continuation of long description ''', # trailing whitespace, but allowed in continued description
''' end of long description"""''',
'''citing = """start of long citing text, ''', # trailing whitespace, but allowed in citing
''' continuation of long citing text ''', # trailing whitespace, but allowed in continued citing
''' end of long citing text"""''',
'''examples = """start of long examples, ''', # trailing whitespace, but allowed in examples
''' continuation of long examples ''', # trailing whitespace, but allowed in continued examples
''' end of long examples"""''',
"moduleclass = 'tools' ", # trailing whitespace
'',
]
line_numbers = range(1, len(lines) + 1)
state = {}
test_cases = [
None,
(17, "W299 trailing whitespace"),
(0, "W293 blank line contains whitespace"),
None,
None,
None,
None,
None,
None,
None,
None,
None,
(21, "W299 trailing whitespace"),
]
for (line, line_number, expected_result) in zip(lines, line_numbers, test_cases):
result = _eb_check_trailing_whitespace(line, lines, line_number, state)
self.assertEqual(result, expected_result)
def suite():
"""Return all style tests for easyconfigs."""
return TestLoaderFiltered().loadTestsFromTestCase(StyleTest, sys.argv[1:])
if __name__ == '__main__':
res = TextTestRunner(verbosity=1).run(suite())
sys.exit(len(res.failures))