From 6712a3e14f04923c3de2e916996874ed2f96f1d1 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 24 Mar 2011 10:51:06 -0700 Subject: Remove test_importable(). Couldn't see how to make this reliable across all platforms. --- Lib/test/test_collections.py | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index 020f4e2..d4cc4a8 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -332,37 +332,12 @@ class TestNamedTuple(unittest.TestCase): # verify that _source can be run through exec() tmp = namedtuple('NTColor', 'red green blue') globals().pop('NTColor', None) # remove artifacts from other tests - self.assertNotIn('NTColor', globals()) exec(tmp._source, globals()) self.assertIn('NTColor', globals()) c = NTColor(10, 20, 30) self.assertEqual((c.red, c.green, c.blue), (10, 20, 30)) self.assertEqual(NTColor._fields, ('red', 'green', 'blue')) globals().pop('NTColor', None) # clean-up after this test - self.assertNotIn('NTColor', globals()) - - def test_source_importable(self): - tmp = namedtuple('Color', 'hue sat val') - - compiled = None - source = TESTFN + '.py' - with open(source, 'w') as f: - print(tmp._source, file=f) - - if TESTFN in sys.modules: - del sys.modules[TESTFN] - try: - mod = __import__(TESTFN) - compiled = mod.__file__ - Color = mod.Color - c = Color(10, 20, 30) - self.assertEqual((c.hue, c.sat, c.val), (10, 20, 30)) - self.assertEqual(Color._fields, ('hue', 'sat', 'val')) - finally: - forget(TESTFN) - if compiled: - unlink(compiled) - unlink(source) ################################################################################ -- cgit v0.12 From 03504fc2fbb7aab41560e761c8ed8e24b4ec6ebe Mon Sep 17 00:00:00 2001 From: R David Murray Date: Thu, 24 Mar 2011 14:35:30 -0400 Subject: #11030: make --coverdir work for relative directories again. --- Lib/test/regrtest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 63268e5..18c86f7 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -315,7 +315,9 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, elif o in ('-T', '--coverage'): trace = True elif o in ('-D', '--coverdir'): - coverdir = os.path.join(os.getcwd(), a) + # CWD is replaced with a temporary dir before calling main(), so we + # need join it with the saved CWD so it goes where the user expects. + coverdir = os.path.join(support.SAVEDCWD, a) elif o in ('-N', '--nocoverdir'): coverdir = None elif o in ('-R', '--huntrleaks'): -- cgit v0.12 From b588f8dd9fcd4881659b1037f92e433d3fb6c29c Mon Sep 17 00:00:00 2001 From: R David Murray Date: Thu, 24 Mar 2011 14:42:58 -0400 Subject: #11031: Add --testdir to specify where to find tests Patch by Sandro Tosi. The main purpose of this option is to allow an alternate set of tests files to be used when running tests of the regrtest tool itself. --- Lib/test/regrtest.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 18c86f7..ca9e9f4 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -42,6 +42,9 @@ Selecting tests -- specify which special resource intensive tests to run -M/--memlimit LIMIT -- run very large memory-consuming tests + --testdir DIR + -- execute test files in the specified directory (instead + of the Python stdlib test suite) Special runs @@ -265,7 +268,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, 'use=', 'threshold=', 'trace', 'coverdir=', 'nocoverdir', 'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=', 'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug', - 'start=', 'nowindows', 'header']) + 'start=', 'nowindows', 'header', 'testdir=']) except getopt.error as msg: usage(msg) @@ -395,6 +398,10 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, print() # Force a newline (just in case) print(json.dumps(result)) sys.exit(0) + elif o == '--testdir': + # CWD is replaced with a temporary dir before calling main(), so we + # join it with the saved CWD so it ends up where the user expects. + testdir = os.path.join(support.SAVEDCWD, a) else: print(("No handler for option {}. Please report this as a bug " "at http://bugs.python.org.").format(o), file=sys.stderr) @@ -469,7 +476,13 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, print("== ", os.getcwd()) print("Testing with flags:", sys.flags) - alltests = findtests(testdir, stdtests, nottests) + # if testdir is set, then we are not running the python tests suite, so + # don't add default tests to be executed or skipped (pass empty values) + if testdir: + alltests = findtests(testdir, list(), set()) + else: + alltests = findtests(testdir, stdtests, nottests) + selected = tests or args or alltests if single: selected = selected[:1] @@ -715,6 +728,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, sys.exit(len(bad) > 0 or interrupted) +# small set of tests to determine if we have a basically functioning interpreter +# (i.e. if any of these fail, then anything else is likely to follow) STDTESTS = [ 'test_grammar', 'test_opcodes', @@ -727,6 +742,7 @@ STDTESTS = [ 'test_doctest2', ] +# set of tests that we don't want to be executed when using regrtest NOTTESTS = { 'test_future1', 'test_future2', -- cgit v0.12 From 576483085c7357130afba7f605db431df255ec74 Mon Sep 17 00:00:00 2001 From: R David Murray Date: Thu, 24 Mar 2011 14:57:05 -0400 Subject: #11093: make NOTTESTS empty by renaming confusingly named files in test dir. Patch by Sandro Tosi. --- Lib/test/future_test1.py | 11 +++++++++++ Lib/test/future_test2.py | 10 ++++++++++ Lib/test/regrtest.py | 5 +---- Lib/test/test_future.py | 12 ++++++------ Lib/test/test_future1.py | 11 ----------- Lib/test/test_future2.py | 10 ---------- 6 files changed, 28 insertions(+), 31 deletions(-) create mode 100644 Lib/test/future_test1.py create mode 100644 Lib/test/future_test2.py delete mode 100644 Lib/test/test_future1.py delete mode 100644 Lib/test/test_future2.py diff --git a/Lib/test/future_test1.py b/Lib/test/future_test1.py new file mode 100644 index 0000000..297c2e0 --- /dev/null +++ b/Lib/test/future_test1.py @@ -0,0 +1,11 @@ +"""This is a test""" + +# Import the name nested_scopes twice to trigger SF bug #407394 (regression). +from __future__ import nested_scopes, nested_scopes + +def f(x): + def g(y): + return x + y + return g + +result = f(2)(4) diff --git a/Lib/test/future_test2.py b/Lib/test/future_test2.py new file mode 100644 index 0000000..3d7fc86 --- /dev/null +++ b/Lib/test/future_test2.py @@ -0,0 +1,10 @@ +"""This is a test""" + +from __future__ import nested_scopes; import site + +def f(x): + def g(y): + return x + y + return g + +result = f(2)(4) diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index ca9e9f4..f6cf0a7 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -743,10 +743,7 @@ STDTESTS = [ ] # set of tests that we don't want to be executed when using regrtest -NOTTESTS = { - 'test_future1', - 'test_future2', -} +NOTTESTS = set() def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS): """Return a list of all applicable test modules.""" diff --git a/Lib/test/test_future.py b/Lib/test/test_future.py index c6689a1..3a25eb1 100644 --- a/Lib/test/test_future.py +++ b/Lib/test/test_future.py @@ -13,14 +13,14 @@ def get_error_location(msg): class FutureTest(unittest.TestCase): def test_future1(self): - support.unload('test_future1') - from test import test_future1 - self.assertEqual(test_future1.result, 6) + support.unload('future_test1') + from test import future_test1 + self.assertEqual(future_test1.result, 6) def test_future2(self): - support.unload('test_future2') - from test import test_future2 - self.assertEqual(test_future2.result, 6) + support.unload('future_test2') + from test import future_test2 + self.assertEqual(future_test2.result, 6) def test_future3(self): support.unload('test_future3') diff --git a/Lib/test/test_future1.py b/Lib/test/test_future1.py deleted file mode 100644 index 297c2e0..0000000 --- a/Lib/test/test_future1.py +++ /dev/null @@ -1,11 +0,0 @@ -"""This is a test""" - -# Import the name nested_scopes twice to trigger SF bug #407394 (regression). -from __future__ import nested_scopes, nested_scopes - -def f(x): - def g(y): - return x + y - return g - -result = f(2)(4) diff --git a/Lib/test/test_future2.py b/Lib/test/test_future2.py deleted file mode 100644 index 3d7fc86..0000000 --- a/Lib/test/test_future2.py +++ /dev/null @@ -1,10 +0,0 @@ -"""This is a test""" - -from __future__ import nested_scopes; import site - -def f(x): - def g(y): - return x + y - return g - -result = f(2)(4) -- cgit v0.12