From fc8c4d81fd81b66c424480ce5aaa91bcf49809bb Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Mon, 10 Dec 2012 20:04:22 -0600 Subject: testsuite: test for exceptions raised without messages --- testsuite/Testsrc/test_code_checks.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'testsuite/Testsrc/test_code_checks.py') diff --git a/testsuite/Testsrc/test_code_checks.py b/testsuite/Testsrc/test_code_checks.py index d4ab0aa12..f6b7e991a 100644 --- a/testsuite/Testsrc/test_code_checks.py +++ b/testsuite/Testsrc/test_code_checks.py @@ -2,6 +2,7 @@ import os import re import sys import glob +import copy from subprocess import Popen, PIPE, STDOUT # add all parent testsuite directories to sys.path to allow (most) @@ -15,13 +16,14 @@ while _path != '/': _path = os.path.dirname(_path) from common import * +# path to base testsuite directory +testdir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) + # path to Bcfg2 src directory -srcpath = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", - "src")) +srcpath = os.path.abspath(os.path.join(testdir, "..", "src")) # path to pylint rc file -rcfile = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", - "pylintrc.conf")) +rcfile = os.path.join(testdir, "pylintrc.conf") # test for pylint existence try: @@ -140,7 +142,7 @@ def blacklist_filter(filelist, blacklist): class TestPylint(Bcfg2TestCase): pylint_cmd = ["pylint", "--rcfile", rcfile, "--init-hook", - "import sys;sys.path.append('%s')" % + "import sys;sys.path.extend('%s')" % os.path.join(srcpath, "lib")] # regex to find errors and fatal errors @@ -156,6 +158,11 @@ class TestPylint(Bcfg2TestCase): full_blacklist = expand_path_dict(error_checks) + contingent_blacklist + \ blacklist + def get_env(self): + env = copy.copy(os.environ) + env['PYTHONPATH'] = '%s:%s' % (env['PYTHONPATH'], testdir) + return env + @skipIf(not os.path.exists(srcpath), "%s does not exist" % srcpath) @skipIf(not os.path.exists(rcfile), "%s does not exist" % rcfile) @skipUnless(HAS_PYLINT, "pylint not found, skipping") @@ -206,7 +213,7 @@ class TestPylint(Bcfg2TestCase): extra_args = [] args = self.pylint_cmd + extra_args + \ [os.path.join(srcpath, p) for p in paths] - pylint = Popen(args, stdout=PIPE, stderr=STDOUT) + pylint = Popen(args, stdout=PIPE, stderr=STDOUT, env=self.get_env()) print(pylint.communicate()[0]) self.assertEqual(pylint.wait(), 0) @@ -260,7 +267,7 @@ class TestPylint(Bcfg2TestCase): args = self.pylint_cmd + extra_args + \ ["-f", "parseable", "-d", "R0801,E1103"] + \ [os.path.join(srcpath, p) for p in paths] - pylint = Popen(args, stdout=PIPE, stderr=STDOUT) + pylint = Popen(args, stdout=PIPE, stderr=STDOUT, env=self.get_env()) output = pylint.communicate()[0] rv = pylint.wait() -- cgit v1.2.3-1-g7c22