aboutsummaryrefslogtreecommitdiff
path: root/run_project_tests.py
diff options
context:
space:
mode:
authorMichael Hirsch, Ph.D <scivision@users.noreply.github.com>2019-07-05 17:52:03 -0400
committerJussi Pakkanen <jpakkane@gmail.com>2019-07-11 22:37:25 +0300
commitcb7d236696c9ba034a60564f9f9439efa5970942 (patch)
treebad6ed6a869cac6afd98c0186fb34b2dd2c1a24a /run_project_tests.py
parent6727e5f5ad763d79548a20ec58ab30f87ba49080 (diff)
downloadmeson-cb7d236696c9ba034a60564f9f9439efa5970942.zip
meson-cb7d236696c9ba034a60564f9f9439efa5970942.tar.gz
meson-cb7d236696c9ba034a60564f9f9439efa5970942.tar.bz2
pythonic file checks
Diffstat (limited to 'run_project_tests.py')
-rwxr-xr-xrun_project_tests.py34
1 files changed, 15 insertions, 19 deletions
diff --git a/run_project_tests.py b/run_project_tests.py
index 154da00..797e1a9 100755
--- a/run_project_tests.py
+++ b/run_project_tests.py
@@ -766,19 +766,14 @@ def _run_tests(all_tests, log_name_base, failfast, extra_args):
ET.ElementTree(element=junit_root).write(xmlname, xml_declaration=True, encoding='UTF-8')
return passing_tests, failing_tests, skipped_tests
-def check_file(fname):
- linenum = 1
- with open(fname, 'rb') as f:
- lines = f.readlines()
+def check_file(file: Path):
+ lines = file.read_bytes().split(b'\n')
tabdetector = re.compile(br' *\t')
- for line in lines:
+ for i, line in enumerate(lines):
if re.match(tabdetector, line):
- print("File %s contains a tab indent on line %d. Only spaces are permitted." % (fname, linenum))
- sys.exit(1)
- if b'\r' in line:
- print("File %s contains DOS line ending on line %d. Only unix-style line endings are permitted." % (fname, linenum))
- sys.exit(1)
- linenum += 1
+ raise SystemExit("File {} contains a tab indent on line {:d}. Only spaces are permitted.".format(file, i + 1))
+ if line.endswith(b'\r'):
+ raise SystemExit("File {} contains DOS line ending on line {:d}. Only unix-style line endings are permitted.".format(file, i + 1))
def check_format():
check_suffixes = {'.c',
@@ -800,20 +795,21 @@ def check_format():
'.build',
'.md',
}
- for (root, _, files) in os.walk('.'):
+ for (root, _, filenames) in os.walk('.'):
if '.dub' in root: # external deps are here
continue
if '.pytest_cache' in root:
continue
if 'meson-logs' in root or 'meson-private' in root:
continue
- for fname in files:
- if os.path.splitext(fname)[1].lower() in check_suffixes:
- bn = os.path.basename(fname)
- if bn == 'sitemap.txt' or bn == 'meson-test-run.txt':
+ if '.eggs' in root or '_cache' in root: # e.g. .mypy_cache
+ continue
+ for fname in filenames:
+ file = Path(fname)
+ if file.suffix.lower() in check_suffixes:
+ if file.name in ('sitemap.txt', 'meson-test-run.txt'):
continue
- fullname = os.path.join(root, fname)
- check_file(fullname)
+ check_file(root / file)
def check_meson_commands_work():
global backend, compile_commands, test_commands, install_commands
@@ -905,4 +901,4 @@ if __name__ == '__main__':
tests = list(g)
if len(tests) != 1:
print('WARNING: The %s suite contains duplicate "%s" tests: "%s"' % (name, k, '", "'.join(tests)))
- sys.exit(failing_tests)
+ raise SystemExit(failing_tests)