summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-05-14 22:03:55 (GMT)
committerGuido van Rossum <guido@python.org>2007-05-14 22:03:55 (GMT)
commita8add0ec5ef05c26e1641b8310b65ddd75c0fec3 (patch)
tree1626110463ca617ab105990ee1923f6ee65c7476 /Lib/test
parent827b055ffe8060ac229cda8d75eb24176cc697c0 (diff)
downloadcpython-a8add0ec5ef05c26e1641b8310b65ddd75c0fec3.zip
cpython-a8add0ec5ef05c26e1641b8310b65ddd75c0fec3.tar.gz
cpython-a8add0ec5ef05c26e1641b8310b65ddd75c0fec3.tar.bz2
Merged revisions 55270-55324 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55271 | fred.drake | 2007-05-11 10:14:47 -0700 (Fri, 11 May 2007) | 3 lines remove jpeg, panel libraries for SGI; there is more IRIX stuff left over, I guess that should be removed too, but will leave for someone who is sure ........ r55280 | fred.drake | 2007-05-11 19:11:37 -0700 (Fri, 11 May 2007) | 1 line remove mention of file that has been removed ........ r55301 | brett.cannon | 2007-05-13 17:38:05 -0700 (Sun, 13 May 2007) | 4 lines Remove rexec and Bastion from the stdlib. This also eliminates the need for f_restricted on frames. This in turn negates the need for PyEval_GetRestricted() and PyFrame_IsRestricted(). ........ r55303 | brett.cannon | 2007-05-13 19:22:22 -0700 (Sun, 13 May 2007) | 2 lines Remove the md5 and sha modules. ........ r55305 | george.yoshida | 2007-05-13 19:45:55 -0700 (Sun, 13 May 2007) | 2 lines fix markup ........ r55306 | neal.norwitz | 2007-05-13 19:47:57 -0700 (Sun, 13 May 2007) | 1 line Get the doc building again after some removals. ........ r55307 | neal.norwitz | 2007-05-13 19:50:45 -0700 (Sun, 13 May 2007) | 1 line Get test_pyclbr passing again after getstatus was removed from commands. This "test case" was weird since it was just importing a seemingly random module. Remove the import ........ r55322 | brett.cannon | 2007-05-14 14:09:20 -0700 (Mon, 14 May 2007) | 3 lines Remove the compiler package. Will eventually need a mechanism to byte compile an AST. ........
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test___all__.py2
-rw-r--r--Lib/test/test_bastion.py3
-rw-r--r--Lib/test/test_compiler.py265
-rw-r--r--Lib/test/test_descr.py44
-rw-r--r--Lib/test/test_importhooks.py2
-rw-r--r--Lib/test/test_md5.py58
-rw-r--r--Lib/test/test_pep247.py4
-rw-r--r--Lib/test/test_pyclbr.py4
-rw-r--r--Lib/test/test_sha.py52
-rw-r--r--Lib/test/test_sundry.py1
-rw-r--r--Lib/test/test_tarfile.py4
-rw-r--r--Lib/test/test_transformer.py35
12 files changed, 4 insertions, 470 deletions
diff --git a/Lib/test/test___all__.py b/Lib/test/test___all__.py
index 6003733..7a39ca3 100644
--- a/Lib/test/test___all__.py
+++ b/Lib/test/test___all__.py
@@ -35,7 +35,6 @@ class AllTest(unittest.TestCase):
import _socket
self.check_all("BaseHTTPServer")
- self.check_all("Bastion")
self.check_all("CGIHTTPServer")
self.check_all("ConfigParser")
self.check_all("Cookie")
@@ -124,7 +123,6 @@ class AllTest(unittest.TestCase):
self.check_all("random")
self.check_all("re")
self.check_all("repr")
- self.check_all("rexec")
self.check_all("rfc822")
self.check_all("rlcompleter")
self.check_all("robotparser")
diff --git a/Lib/test/test_bastion.py b/Lib/test/test_bastion.py
deleted file mode 100644
index 4760ec8..0000000
--- a/Lib/test/test_bastion.py
+++ /dev/null
@@ -1,3 +0,0 @@
-##import Bastion
-##
-##Bastion._test()
diff --git a/Lib/test/test_compiler.py b/Lib/test/test_compiler.py
deleted file mode 100644
index c55dc0e..0000000
--- a/Lib/test/test_compiler.py
+++ /dev/null
@@ -1,265 +0,0 @@
-import compiler
-from compiler.ast import flatten
-import os, sys, time, unittest
-import test.test_support
-from random import random
-
-# How much time in seconds can pass before we print a 'Still working' message.
-_PRINT_WORKING_MSG_INTERVAL = 5 * 60
-
-class TrivialContext(object):
- def __enter__(self):
- return self
- def __exit__(self, *exc_info):
- pass
-
-class CompilerTest(unittest.TestCase):
-
- def testCompileLibrary(self):
- # A simple but large test. Compile all the code in the
- # standard library and its test suite. This doesn't verify
- # that any of the code is correct, merely the compiler is able
- # to generate some kind of code for it.
-
- next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL
- libdir = os.path.dirname(unittest.__file__)
- testdir = os.path.dirname(test.test_support.__file__)
-
- for dir in [libdir, testdir]:
- for basename in os.listdir(dir):
- # Print still working message since this test can be really slow
- if next_time <= time.time():
- next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL
- print(' testCompileLibrary still working, be patient...', file=sys.__stdout__)
- sys.__stdout__.flush()
-
- if not basename.endswith(".py"):
- continue
- if not TEST_ALL and random() < 0.98:
- continue
- path = os.path.join(dir, basename)
- if test.test_support.verbose:
- print("compiling", path)
- f = open(path, "U")
- buf = f.read()
- f.close()
- if "badsyntax" in basename or "bad_coding" in basename:
- self.assertRaises(SyntaxError, compiler.compile,
- buf, basename, "exec")
- else:
- try:
- compiler.compile(buf, basename, "exec")
- except Exception as e:
- args = list(e.args) or [""]
- args[0] = "%s [in file %s]" % (args[0], basename)
- e.args = tuple(args)
- raise
-
- def testNewClassSyntax(self):
- compiler.compile("class foo():pass\n\n","<string>","exec")
-
- def testYieldExpr(self):
- compiler.compile("def g(): yield\n\n", "<string>", "exec")
-
- def testTryExceptFinally(self):
- # Test that except and finally clauses in one try stmt are recognized
- c = compiler.compile("try:\n 1/0\nexcept:\n e = 1\nfinally:\n f = 1",
- "<string>", "exec")
- dct = {}
- exec(c, dct)
- self.assertEquals(dct.get('e'), 1)
- self.assertEquals(dct.get('f'), 1)
-
- def testDefaultArgs(self):
- self.assertRaises(SyntaxError, compiler.parse, "def foo(a=1, b): pass")
-
- def testDocstrings(self):
- c = compiler.compile('"doc"', '<string>', 'exec')
- self.assert_('__doc__' in c.co_names)
- c = compiler.compile('def f():\n "doc"', '<string>', 'exec')
- g = {}
- exec(c, g)
- self.assertEquals(g['f'].__doc__, "doc")
-
- def testLineNo(self):
- # Test that all nodes except Module have a correct lineno attribute.
- filename = __file__
- if filename.endswith((".pyc", ".pyo")):
- filename = filename[:-1]
- tree = compiler.parseFile(filename)
- self.check_lineno(tree)
-
- def check_lineno(self, node):
- try:
- self._check_lineno(node)
- except AssertionError:
- print(node.__class__, node.lineno)
- raise
-
- def _check_lineno(self, node):
- if not node.__class__ in NOLINENO:
- self.assert_(isinstance(node.lineno, int),
- "lineno=%s on %s" % (node.lineno, node.__class__))
- self.assert_(node.lineno > 0,
- "lineno=%s on %s" % (node.lineno, node.__class__))
- for child in node.getChildNodes():
- self.check_lineno(child)
-
- def testFlatten(self):
- self.assertEquals(flatten([1, [2]]), [1, 2])
- self.assertEquals(flatten((1, (2,))), [1, 2])
-
- def testNestedScope(self):
- c = compiler.compile('def g():\n'
- ' a = 1\n'
- ' def f(): return a + 2\n'
- ' return f()\n'
- 'result = g()',
- '<string>',
- 'exec')
- dct = {}
- exec(c, dct)
- self.assertEquals(dct.get('result'), 3)
- c = compiler.compile('def g(a):\n'
- ' def f(): return a + 2\n'
- ' return f()\n'
- 'result = g(1)',
- '<string>',
- 'exec')
- dct = {}
- exec(c, dct)
- self.assertEquals(dct.get('result'), 3)
- c = compiler.compile('def g((a, b)):\n'
- ' def f(): return a + b\n'
- ' return f()\n'
- 'result = g((1, 2))',
- '<string>',
- 'exec')
- dct = {}
- exec(c, dct)
- self.assertEquals(dct.get('result'), 3)
-
- def testGenExp(self):
- c = compiler.compile('list((i,j) for i in range(3) if i < 3'
- ' for j in range(4) if j > 2)',
- '<string>',
- 'eval')
- self.assertEquals(eval(c), [(0, 3), (1, 3), (2, 3)])
-
- def testFuncAnnotations(self):
- testdata = [
- ('def f(a: 1): pass', {'a': 1}),
- ('''def f(a, (b:1, c:2, d), e:3=4, f=5,
- *g:6, h:7, i=8, j:9=10, **k:11) -> 12: pass
- ''', {'b': 1, 'c': 2, 'e': 3, 'g': 6, 'h': 7, 'j': 9,
- 'k': 11, 'return': 12}),
- ]
- for sourcecode, expected in testdata:
- # avoid IndentationError: unexpected indent from trailing lines
- sourcecode = sourcecode.rstrip()+'\n'
- c = compiler.compile(sourcecode, '<string>', 'exec')
- dct = {}
- exec(c, dct)
- self.assertEquals(dct['f'].__annotations__, expected)
-
- def testWith(self):
- # SF bug 1638243
- c = compiler.compile('from __future__ import with_statement\n'
- 'def f():\n'
- ' with TrivialContext():\n'
- ' return 1\n'
- 'result = f()',
- '<string>',
- 'exec' )
- dct = {'TrivialContext': TrivialContext}
- exec(c, dct)
- self.assertEquals(dct.get('result'), 1)
-
- def testWithAss(self):
- c = compiler.compile('from __future__ import with_statement\n'
- 'def f():\n'
- ' with TrivialContext() as tc:\n'
- ' return 1\n'
- 'result = f()',
- '<string>',
- 'exec' )
- dct = {'TrivialContext': TrivialContext}
- exec(c, dct)
- self.assertEquals(dct.get('result'), 1)
-
- def testBytesLiteral(self):
- c = compiler.compile("b'foo'", '<string>', 'eval')
- b = eval(c)
-
- c = compiler.compile('def f(b=b"foo"):\n'
- ' b[0] += 1\n'
- ' return b\n'
- 'f(); f(); result = f()\n',
- '<string>',
- 'exec')
- dct = {}
- exec(c, dct)
- self.assertEquals(dct.get('result'), b"ioo")
-
- c = compiler.compile('def f():\n'
- ' b = b"foo"\n'
- ' b[0] += 1\n'
- ' return b\n'
- 'f(); f(); result = f()\n',
- '<string>',
- 'exec')
- dct = {}
- exec(c, dct)
- self.assertEquals(dct.get('result'), b"goo")
-
-NOLINENO = (compiler.ast.Module, compiler.ast.Stmt, compiler.ast.Discard)
-
-###############################################################################
-# code below is just used to trigger some possible errors, for the benefit of
-# testLineNo
-###############################################################################
-
-class Toto:
- """docstring"""
- pass
-
-a, b = 2, 3
-[c, d] = 5, 6
-l = [(x, y) for x, y in zip(range(5), range(5,10))]
-l[0]
-l[3:4]
-d = {'a': 2}
-d = {}
-t = ()
-t = (1, 2)
-l = []
-l = [1, 2]
-if l:
- pass
-else:
- a, b = b, a
-
-try:
- print(yo)
-except:
- yo = 3
-else:
- yo += 3
-
-try:
- a += b
-finally:
- b = 0
-
-from math import *
-
-###############################################################################
-
-def test_main(all=False):
- global TEST_ALL
- TEST_ALL = all or test.test_support.is_resource_enabled("compiler")
- test.test_support.run_unittest(CompilerTest)
-
-if __name__ == "__main__":
- import sys
- test_main('all' in sys.argv)
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index efdf9b0..4b6d734 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -2452,49 +2452,6 @@ def keywords():
raise TestFailed("expected TypeError from bogus keyword "
"argument to %r" % constructor)
-def restricted():
- # XXX This test is disabled because rexec is not deemed safe
- return
- import rexec
- if verbose:
- print("Testing interaction with restricted execution ...")
-
- sandbox = rexec.RExec()
-
- code1 = """f = open(%r, 'w')""" % TESTFN
- code2 = """f = open(%r, 'w')""" % TESTFN
- code3 = """\
-f = open(%r)
-t = type(f) # a sneaky way to get the file() constructor
-f.close()
-f = t(%r, 'w') # rexec can't catch this by itself
-""" % (TESTFN, TESTFN)
-
- f = open(TESTFN, 'w') # Create the file so code3 can find it.
- f.close()
-
- try:
- for code in code1, code2, code3:
- try:
- sandbox.r_exec(code)
- except IOError as msg:
- if str(msg).find("restricted") >= 0:
- outcome = "OK"
- else:
- outcome = "got an exception, but not an expected one"
- else:
- outcome = "expected a restricted-execution exception"
-
- if outcome != "OK":
- raise TestFailed("%s, in %r" % (outcome, code))
-
- finally:
- try:
- import os
- os.unlink(TESTFN)
- except:
- pass
-
def str_subclass_as_dict_key():
if verbose:
print("Testing a str subclass used as dict key ..")
@@ -4173,7 +4130,6 @@ def test_main():
supers()
inherits()
keywords()
- restricted()
str_subclass_as_dict_key()
classic_comparisons()
rich_comparisons()
diff --git a/Lib/test/test_importhooks.py b/Lib/test/test_importhooks.py
index 66c9258..02268ab 100644
--- a/Lib/test/test_importhooks.py
+++ b/Lib/test/test_importhooks.py
@@ -251,7 +251,7 @@ class ImportHooksTestCase(ImportHooksBaseTestCase):
i = ImpWrapper()
sys.meta_path.append(i)
sys.path_hooks.append(ImpWrapper)
- mnames = ("colorsys", "urlparse", "distutils.core", "compiler.misc")
+ mnames = ("colorsys", "urlparse", "distutils.core")
for mname in mnames:
parent = mname.split(".")[0]
for n in list(sys.modules.keys()):
diff --git a/Lib/test/test_md5.py b/Lib/test/test_md5.py
deleted file mode 100644
index 1f08568..0000000
--- a/Lib/test/test_md5.py
+++ /dev/null
@@ -1,58 +0,0 @@
-# Testing md5 module
-
-import unittest
-from md5 import md5
-from test import test_support
-
-def hexstr(s):
- import string
- h = string.hexdigits
- r = ''
- for c in s:
- i = ord(c)
- r = r + h[(i >> 4) & 0xF] + h[i & 0xF]
- return r
-
-class MD5_Test(unittest.TestCase):
-
- def md5test(self, s, expected):
- self.assertEqual(hexstr(md5(s).digest()), expected)
- self.assertEqual(md5(s).hexdigest(), expected)
-
- def test_basics(self):
- eq = self.md5test
- eq('', 'd41d8cd98f00b204e9800998ecf8427e')
- eq('a', '0cc175b9c0f1b6a831c399e269772661')
- eq('abc', '900150983cd24fb0d6963f7d28e17f72')
- eq('message digest', 'f96b697d7cb7938d525a2f31aaf161d0')
- eq('abcdefghijklmnopqrstuvwxyz', 'c3fcd3d76192e4007dfb496cca67e13b')
- eq('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
- 'd174ab98d277d9f5a5611c2c9f419d9f')
- eq('12345678901234567890123456789012345678901234567890123456789012345678901234567890',
- '57edf4a22be3c955ac49da2e2107b67a')
-
- def test_hexdigest(self):
- # hexdigest is new with Python 2.0
- m = md5('testing the hexdigest method')
- h = m.hexdigest()
- self.assertEqual(hexstr(m.digest()), h)
-
- def test_large_update(self):
- aas = 'a' * 64
- bees = 'b' * 64
- cees = 'c' * 64
-
- m1 = md5()
- m1.update(aas)
- m1.update(bees)
- m1.update(cees)
-
- m2 = md5()
- m2.update(aas + bees + cees)
- self.assertEqual(m1.digest(), m2.digest())
-
-def test_main():
- test_support.run_unittest(MD5_Test)
-
-if __name__ == '__main__':
- test_main()
diff --git a/Lib/test/test_pep247.py b/Lib/test/test_pep247.py
index cbd071b..4ea747a 100644
--- a/Lib/test/test_pep247.py
+++ b/Lib/test/test_pep247.py
@@ -3,7 +3,7 @@
# hashing algorithms.
#
-import md5, sha, hmac
+import hmac
def check_hash_module(module, key=None):
assert hasattr(module, 'digest_size'), "Must have digest_size"
@@ -45,6 +45,4 @@ def check_hash_module(module, key=None):
if __name__ == '__main__':
- check_hash_module(md5)
- check_hash_module(sha)
check_hash_module(hmac, key='abc')
diff --git a/Lib/test/test_pyclbr.py b/Lib/test/test_pyclbr.py
index 1edda75..749c568 100644
--- a/Lib/test/test_pyclbr.py
+++ b/Lib/test/test_pyclbr.py
@@ -11,10 +11,6 @@ from unittest import TestCase
StaticMethodType = type(staticmethod(lambda: None))
ClassMethodType = type(classmethod(lambda c: None))
-# This next line triggers an error on old versions of pyclbr.
-
-from commands import getstatus
-
# Here we test the python class browser code.
#
# The main function in this suite, 'testModule', compares the output
diff --git a/Lib/test/test_sha.py b/Lib/test/test_sha.py
deleted file mode 100644
index ea224e4..0000000
--- a/Lib/test/test_sha.py
+++ /dev/null
@@ -1,52 +0,0 @@
-# Testing sha module (NIST's Secure Hash Algorithm)
-
-# use the three examples from Federal Information Processing Standards
-# Publication 180-1, Secure Hash Standard, 1995 April 17
-# http://www.itl.nist.gov/div897/pubs/fip180-1.htm
-
-import sha
-import unittest
-from test import test_support
-
-
-class SHATestCase(unittest.TestCase):
- def check(self, data, digest):
- # Check digest matches the expected value
- obj = sha.new(data)
- computed = obj.hexdigest()
- self.assert_(computed == digest)
-
- # Verify that the value doesn't change between two consecutive
- # digest operations.
- computed_again = obj.hexdigest()
- self.assert_(computed == computed_again)
-
- # Check hexdigest() output matches digest()'s output
- digest = obj.digest()
- hexd = ""
- for c in digest:
- hexd += '%02x' % ord(c)
- self.assert_(computed == hexd)
-
- def test_case_1(self):
- self.check("abc",
- "a9993e364706816aba3e25717850c26c9cd0d89d")
-
- def test_case_2(self):
- self.check("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
- "84983e441c3bd26ebaae4aa1f95129e5e54670f1")
-
- def test_case_3(self):
- self.check("a" * 1000000,
- "34aa973cd4c4daa4f61eeb2bdbad27316534016f")
-
- def test_case_4(self):
- self.check(chr(0xAA) * 80,
- '4ca0ef38f1794b28a8f8ee110ee79d48ce13be25')
-
-def test_main():
- test_support.run_unittest(SHATestCase)
-
-
-if __name__ == "__main__":
- test_main()
diff --git a/Lib/test/test_sundry.py b/Lib/test/test_sundry.py
index ebbe915..a37aad1 100644
--- a/Lib/test/test_sundry.py
+++ b/Lib/test/test_sundry.py
@@ -49,7 +49,6 @@ import posixfile
import pstats
import py_compile
import pydoc
-import rexec
import rlcompleter
import sched
import smtplib
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index 08c7a88..312050b 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -5,7 +5,7 @@ import os
import shutil
import tempfile
import StringIO
-import md5
+from hashlib import md5
import errno
import unittest
@@ -25,7 +25,7 @@ except ImportError:
bz2 = None
def md5sum(data):
- return md5.new(data).hexdigest()
+ return md5(data).hexdigest()
def path(path):
return test_support.findfile(path)
diff --git a/Lib/test/test_transformer.py b/Lib/test/test_transformer.py
deleted file mode 100644
index 6f1c4f9..0000000
--- a/Lib/test/test_transformer.py
+++ /dev/null
@@ -1,35 +0,0 @@
-import unittest
-from test import test_support
-from compiler import transformer, ast
-from compiler import compile
-
-class Tests(unittest.TestCase):
-
- def testMultipleLHS(self):
- """ Test multiple targets on the left hand side. """
-
- snippets = ['a, b = 1, 2',
- '(a, b) = 1, 2',
- '((a, b), c) = (1, 2), 3']
-
- for s in snippets:
- a = transformer.parse(s)
- assert isinstance(a, ast.Module)
- child1 = a.getChildNodes()[0]
- assert isinstance(child1, ast.Stmt)
- child2 = child1.getChildNodes()[0]
- assert isinstance(child2, ast.Assign)
-
- # This actually tests the compiler, but it's a way to assure the ast
- # is correct
- c = compile(s, '<string>', 'single')
- vals = {}
- exec(c, vals)
- assert vals['a'] == 1
- assert vals['b'] == 2
-
-def test_main():
- test_support.run_unittest(Tests)
-
-if __name__ == "__main__":
- test_main()