1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3 4# 5# Copyright 2017, Data61 6# Commonwealth Scientific and Industrial Research Organisation (CSIRO) 7# ABN 41 687 119 230. 8# 9# This software may be distributed and modified according to the terms of 10# the BSD 2-Clause license. Note that NO WARRANTY is provided. 11# See "LICENSE_BSD2.txt" for details. 12# 13# @TAG(DATA61_BSD) 14# 15 16from __future__ import absolute_import, division, print_function, \ 17 unicode_literals 18 19import os, re, sys, unittest 20from pylint import epylint 21 22ME = os.path.abspath(__file__) 23 24# Make CAmkES importable 25sys.path.append(os.path.join(os.path.dirname(ME), '../../..')) 26 27from camkes.internal.tests.utils import CAmkESTest 28 29CAMKES_LINT = os.path.join(os.path.dirname(ME), 30 '../../../tools/camkes_lint.py') 31 32class TestSourceLint(CAmkESTest): 33 pass 34 35def lint(self, path): 36 ret, _, stderr = self.execute([CAMKES_LINT, path]) 37 self.assertEqual(ret, 0, stderr) 38 39srcdir = os.path.join(os.path.dirname(ME), '..') 40regex = re.compile(r'.*\.py$') 41sub = re.compile(r'[^\w]') 42for src in os.listdir(srcdir): 43 if regex.match(src) is None: 44 continue 45 path = os.path.abspath(os.path.join(srcdir, src)) 46 name = 'test_%s' % sub.sub('_', src) 47 setattr(TestSourceLint, name, lambda self, path=path: lint(self, path)) 48 49if __name__ == '__main__': 50 unittest.main() 51