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, pylint, 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 29class TestLint(CAmkESTest): 30 pass 31 32def lint(self, path): 33 disabled = [ 34 'E1101', # prevents usages getters defined with @property being treated as methods 35 ] 36 stdout, stderr = epylint.py_run('%s --errors-only --disable=%s' % (path, ",".join(disabled)), return_std=True) 37 err = [] 38 for line in [x.strip() for x in stdout] + [x.strip() for x in stderr]: 39 if line == 'No config file found, using default configuration': 40 continue 41 if line: 42 err.append(line) 43 if len(err) > 0: 44 self.fail('\n'.join(err)) 45 46srcdir = os.path.join(os.path.dirname(ME), '..') 47regex = re.compile(r'.*\.py$') 48sub = re.compile(r'[^\w]') 49for src in os.listdir(srcdir): 50 if regex.match(src) is None: 51 continue 52 path = os.path.abspath(os.path.join(srcdir, src)) 53 name = 'test_%s' % sub.sub('_', src) 54 setattr(TestLint, name, lambda self, path=path: lint(self, path)) 55 56if __name__ == '__main__': 57 unittest.main() 58