From: <fwi...@us...> - 2011-03-12 20:12:01
|
Revision: 7219 http://jython.svn.sourceforge.net/jython/?rev=7219&view=rev Author: fwierzbicki Date: 2011-03-12 20:11:47 +0000 (Sat, 12 Mar 2011) Log Message: ----------- Files changed for new test_support.py Modified Paths: -------------- trunk/jython/Lib/test/test_jy_internals.py trunk/jython/Lib/test/test_optparse.py trunk/jython/Lib/test/test_pulldom.py trunk/jython/Lib/test/test_scope.py trunk/jython/Lib/test/test_select.py trunk/jython/Lib/test/test_select_new.py trunk/jython/Lib/test/test_socket.py trunk/jython/Lib/test/test_support.py Modified: trunk/jython/Lib/test/test_jy_internals.py =================================================================== --- trunk/jython/Lib/test/test_jy_internals.py 2011-03-12 19:36:22 UTC (rev 7218) +++ trunk/jython/Lib/test/test_jy_internals.py 2011-03-12 20:11:47 UTC (rev 7219) @@ -4,7 +4,7 @@ import gc import unittest import time -from test.test_support import run_suite +from test import test_support import java import jarray @@ -287,19 +287,7 @@ self.assertEquals(len(test.__dict__), 4) def test_main(): - test_suite = unittest.TestSuite() - test_loader = unittest.TestLoader() - def suite_add(case): - test_suite.addTest(test_loader.loadTestsFromTestCase(case)) - suite_add(WeakIdentityMapTests) - suite_add(LongAsScaledDoubleValueTests) - suite_add(ExtraMathTests) - suite_add(DatetimeTypeMappingTest) - suite_add(IdTest) - suite_add(FrameTest) - suite_add(ModuleTest) - suite_add(MemoryLeakTests) - run_suite(test_suite) + test_support.run_unittest(__name__) if __name__ == "__main__": test_main() Modified: trunk/jython/Lib/test/test_optparse.py =================================================================== --- trunk/jython/Lib/test/test_optparse.py 2011-03-12 19:36:22 UTC (rev 7218) +++ trunk/jython/Lib/test/test_optparse.py 2011-03-12 20:11:47 UTC (rev 7219) @@ -5,10 +5,9 @@ # (tar...@so...) -- translated from the original Optik # test suite to this PyUnit-based version. # -# $Id: test_optparse.py 50791 2006-07-23 16:05:51Z greg.ward $ +# $Id: test_optparse.py 83540 2010-08-02 18:40:55Z ezio.melotti $ # -import __builtin__ import sys import os import re @@ -17,7 +16,6 @@ import unittest from StringIO import StringIO -from pprint import pprint from test import test_support @@ -28,12 +26,6 @@ from optparse import _match_abbrev from optparse import _parse_num -# Do the right thing with boolean values for all known Python versions. -try: - True, False -except NameError: - (True, False) = (1, 0) - retype = type(re.compile('')) class InterceptedError(Exception): @@ -461,7 +453,7 @@ return int(value) else: return int(value[:-1]) * _time_units[value[-1]] - except ValueError, IndexError: + except (ValueError, IndexError): raise OptionValueError( 'option %s: invalid duration: %r' % (opt, value)) @@ -774,6 +766,11 @@ {'a': "-b3", 'boo': None, 'foo': None}, []) + def test_combined_single_invalid_option(self): + self.parser.add_option("-t", action="store_true") + self.assertParseFail(["-test"], + "no such option: -e") + class TestBool(BaseTest): def setUp(self): options = [make_option("-v", @@ -796,15 +793,13 @@ (options, args) = self.assertParseOK(["-q"], {'verbose': 0}, []) - if hasattr(__builtin__, 'False'): - self.failUnless(options.verbose is False) + self.assertTrue(options.verbose is False) def test_bool_true(self): (options, args) = self.assertParseOK(["-v"], {'verbose': 1}, []) - if hasattr(__builtin__, 'True'): - self.failUnless(options.verbose is True) + self.assertTrue(options.verbose is True) def test_bool_flicker_on_and_off(self): self.assertParseOK(["-qvq", "-q", "-v"], @@ -1466,15 +1461,9 @@ # we must restore its original value -- otherwise, this test # screws things up for other tests when it's part of the Python # test suite. - orig_columns = os.environ.get('COLUMNS') - os.environ['COLUMNS'] = str(columns) - try: + with test_support.EnvironmentVarGuard() as env: + env.set('COLUMNS', str(columns)) return InterceptingOptionParser(option_list=options) - finally: - if orig_columns is None: - del os.environ['COLUMNS'] - else: - os.environ['COLUMNS'] = orig_columns def assertHelpEquals(self, expected_output): if type(expected_output) is types.UnicodeType: @@ -1501,8 +1490,10 @@ self.assertHelpEquals(_expected_help_long_opts_first) def test_help_title_formatter(self): - self.parser.formatter = TitledHelpFormatter() - self.assertHelpEquals(_expected_help_title_formatter) + with test_support.EnvironmentVarGuard() as env: + env.set("COLUMNS", "80") + self.parser.formatter = TitledHelpFormatter() + self.assertHelpEquals(_expected_help_title_formatter) def test_wrap_columns(self): # Ensure that wrapping respects $COLUMNS environment variable. @@ -1624,21 +1615,11 @@ "option -l: invalid long integer value: '0x12x'") -def _testclasses(): - mod = sys.modules[__name__] - return [getattr(mod, name) for name in dir(mod) if name.startswith('Test')] - -def suite(): - if test_support.is_jython: - # XXX: CPython ref count specific test +def test_main(): + is_jython = sys.platform.startswith("java") + if is_jython: del TestOptionParser.test_refleak - suite = unittest.TestSuite() - for testclass in _testclasses(): - suite.addTest(unittest.makeSuite(testclass)) - return suite + test_support.run_unittest(__name__) -def test_main(): - test_support.run_suite(suite()) - if __name__ == '__main__': test_main() Modified: trunk/jython/Lib/test/test_pulldom.py =================================================================== --- trunk/jython/Lib/test/test_pulldom.py 2011-03-12 19:36:22 UTC (rev 7218) +++ trunk/jython/Lib/test/test_pulldom.py 2011-03-12 20:11:47 UTC (rev 7219) @@ -79,11 +79,7 @@ self.fail("Unexpected exception joining comment data pieces: %s" % str(x)) def test_main(): - tests = [ - UnicodeTests, - ] - suites = [unittest.makeSuite(klass, 'test') for klass in tests] - test_support.run_suite(unittest.TestSuite(suites)) + test_support.run_unittest(__name__) if __name__ == "__main__": test_main() Modified: trunk/jython/Lib/test/test_scope.py =================================================================== --- trunk/jython/Lib/test/test_scope.py 2011-03-12 19:36:22 UTC (rev 7218) +++ trunk/jython/Lib/test/test_scope.py 2011-03-12 20:11:47 UTC (rev 7219) @@ -1,4 +1,4 @@ -from test.test_support import verify, TestFailed, check_syntax, vereq, is_jython +from test.test_support import verify, TestFailed, check_syntax_error, vereq, is_jython import warnings warnings.filterwarnings("ignore", r"import \*", SyntaxWarning, "<string>") @@ -180,7 +180,13 @@ print "11. unoptimized namespaces" -check_syntax("""\ +class FakeTestCase(object): + def fail(self): + raise TestFailed + +fake = FakeTestCase() + +check_syntax_error(fake, """\ def unoptimized_clash1(strip): def f(s): from string import * @@ -188,7 +194,7 @@ return f """) -check_syntax("""\ +check_syntax_error(fake, """\ def unoptimized_clash2(): from string import * def f(s): @@ -196,7 +202,7 @@ return f """) -check_syntax("""\ +check_syntax_error(fake, """\ def unoptimized_clash2(): from string import * def g(): @@ -206,7 +212,7 @@ """) # XXX could allow this for exec with const argument, but what's the point -check_syntax("""\ +check_syntax_error(fake, """\ def error(y): exec "a = 1" def f(x): @@ -214,14 +220,14 @@ return f """) -check_syntax("""\ +check_syntax_error(fake, """\ def f(x): def g(): return x del x # can't del name """) -check_syntax("""\ +check_syntax_error(fake, """\ def f(): def g(): from string import * Modified: trunk/jython/Lib/test/test_select.py =================================================================== --- trunk/jython/Lib/test/test_select.py 2011-03-12 19:36:22 UTC (rev 7218) +++ trunk/jython/Lib/test/test_select.py 2011-03-12 20:11:47 UTC (rev 7219) @@ -222,16 +222,10 @@ p.close() def test_main(): - tests = [ - TestSelectInvalidParameters, - TestSelectClientSocket, - TestPollClientSocket, - ThreadedPollClientSocket, - ] - if sys.platform[:4] != 'java': - tests.append(TestPipes) - suites = [unittest.makeSuite(klass, 'test') for klass in tests] - test_support.run_suite(unittest.TestSuite(suites)) + if test_support.is_jython: + del TestPipes.test + test_support.run_unittest(__name__) + if __name__ == "__main__": test_main() Modified: trunk/jython/Lib/test/test_select_new.py =================================================================== --- trunk/jython/Lib/test/test_select_new.py 2011-03-12 19:36:22 UTC (rev 7218) +++ trunk/jython/Lib/test/test_select_new.py 2011-03-12 20:11:47 UTC (rev 7219) @@ -238,9 +238,7 @@ self.handler.verify_only_writable() def test_main(): - tests = [TestSelect, TestSelectOnAccept] - suites = [unittest.makeSuite(klass, 'test') for klass in tests] - test_support.run_suite(unittest.TestSuite(suites)) + test_support.run_unittest(__name__) if __name__ == "__main__": test_main() Modified: trunk/jython/Lib/test/test_socket.py =================================================================== --- trunk/jython/Lib/test/test_socket.py 2011-03-12 19:36:22 UTC (rev 7218) +++ trunk/jython/Lib/test/test_socket.py 2011-03-12 20:11:47 UTC (rev 7219) @@ -1856,7 +1856,7 @@ if False: tests.append(UDPBroadcastTest) suites = [unittest.makeSuite(klass, 'test') for klass in tests] - test_support.run_suite(unittest.TestSuite(suites)) + test_support._run_suite(unittest.TestSuite(suites)) if __name__ == "__main__": test_main() Modified: trunk/jython/Lib/test/test_support.py =================================================================== --- trunk/jython/Lib/test/test_support.py 2011-03-12 19:36:22 UTC (rev 7218) +++ trunk/jython/Lib/test/test_support.py 2011-03-12 20:11:47 UTC (rev 7219) @@ -207,10 +207,6 @@ on Windows), it will be set on the socket. This will prevent anyone else from bind()'ing to our host/port for the duration of the test. """ - - #XXX: This section is probably wrong as I (Frank Wierzbicki) don't really - # understand it, but I needed this to get the asynchat tests running - # again. if is_jython: # Find some random ports that hopefully no one is listening on. # Ideally each test would clean up after itself and not continue @@ -902,9 +898,7 @@ def threading_setup(): import threading - if is_jython: - return len(threading._active), 0 - return len(threading._active), len(threading._limbo) + return len(threading._active), 0 def threading_cleanup(num_active, num_limbo): import threading @@ -916,12 +910,6 @@ count += 1 time.sleep(0.1) - if not is_jython: - count = 0 - while len(threading._limbo) != num_limbo and count < _MAX_COUNT: - count += 1 - time.sleep(0.1) - def reap_children(): """Use this function at the end of test_main() whenever sub-processes are started. This will help ensure that no extra children (zombies) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |