summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_operator.py8
-rw-r--r--Lib/test/test_profilehooks.py17
-rw-r--r--Lib/test/test_pyclbr.py1
-rw-r--r--Lib/test/test_shutil.py14
-rw-r--r--Lib/test/test_trace.py14
-rw-r--r--Lib/test/test_urllib.py7
-rw-r--r--Lib/test/test_urllibnet.py10
7 files changed, 66 insertions, 5 deletions
diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py
index 57f3846..dbb8f9e 100644
--- a/Lib/test/test_operator.py
+++ b/Lib/test/test_operator.py
@@ -364,9 +364,9 @@ class OperatorTestCase(unittest.TestCase):
self.assertRaises(TypeError, operator.attrgetter('x', (), 'y'), record)
class C(object):
- def __getattr(self, name):
+ def __getattr__(self, name):
raise SyntaxError
- self.failUnlessRaises(AttributeError, operator.attrgetter('foo'), C())
+ self.failUnlessRaises(SyntaxError, operator.attrgetter('foo'), C())
def test_itemgetter(self):
a = 'ABCDE'
@@ -376,9 +376,9 @@ class OperatorTestCase(unittest.TestCase):
self.assertRaises(IndexError, f, a)
class C(object):
- def __getitem(self, name):
+ def __getitem__(self, name):
raise SyntaxError
- self.failUnlessRaises(TypeError, operator.itemgetter(42), C())
+ self.failUnlessRaises(SyntaxError, operator.itemgetter(42), C())
f = operator.itemgetter('name')
self.assertRaises(TypeError, f, a)
diff --git a/Lib/test/test_profilehooks.py b/Lib/test/test_profilehooks.py
index 3a17dc7..6d6aa8e 100644
--- a/Lib/test/test_profilehooks.py
+++ b/Lib/test/test_profilehooks.py
@@ -4,6 +4,22 @@ import unittest
from test import test_support
+class TestGetProfile(unittest.TestCase):
+ def setUp(self):
+ sys.setprofile(None)
+
+ def tearDown(self):
+ sys.setprofile(None)
+
+ def test_empty(self):
+ assert sys.getprofile() == None
+
+ def test_setget(self):
+ def fn(*args):
+ pass
+
+ sys.setprofile(fn)
+ assert sys.getprofile() == fn
class HookWatcher:
def __init__(self):
@@ -359,6 +375,7 @@ def show_events(callable):
def test_main():
test_support.run_unittest(
+ TestGetProfile,
ProfileHookTestCase,
ProfileSimulatorTestCase
)
diff --git a/Lib/test/test_pyclbr.py b/Lib/test/test_pyclbr.py
index 5d46db1..f041823 100644
--- a/Lib/test/test_pyclbr.py
+++ b/Lib/test/test_pyclbr.py
@@ -158,6 +158,7 @@ class PyclbrTest(TestCase):
cm('cgi', ignore=('log',)) # set with = in module
cm('mhlib')
cm('urllib', ignore=('getproxies_registry',
+ 'proxy_bypass_registry',
'open_https',
'_https_connection',
'getproxies_internetconfig',)) # not on all platforms
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
index ee15d0e..b63031e 100644
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -149,6 +149,20 @@ class TestShutil(unittest.TestCase):
except OSError:
pass
+ def test_rmtree_on_symlink(self):
+ # bug 1669.
+ os.mkdir(TESTFN)
+ try:
+ src = os.path.join(TESTFN, 'cheese')
+ dst = os.path.join(TESTFN, 'shop')
+ os.mkdir(src)
+ os.symlink(src, dst)
+ self.assertRaises(OSError, shutil.rmtree, dst)
+ finally:
+ shutil.rmtree(TESTFN, ignore_errors=True)
+
+
+
def test_main():
test_support.run_unittest(TestShutil)
diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py
index 3ec00d2..a0f76c6 100644
--- a/Lib/test/test_trace.py
+++ b/Lib/test/test_trace.py
@@ -268,6 +268,20 @@ class TraceTestCase(unittest.TestCase):
self.compare_events(func.__code__.co_firstlineno,
tracer.events, func.events)
+ def set_and_retrieve_none(self):
+ sys.settrace(None)
+ assert sys.gettrace() is None
+
+ def set_and_retrieve_func(self):
+ def fn(*args):
+ pass
+
+ sys.settrace(fn)
+ try:
+ assert sys.gettrace() is fn
+ finally:
+ sys.settrace(None)
+
def test_01_basic(self):
self.run_test(basic)
def test_02_arigo(self):
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index a87ab71..c233e35 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -47,7 +47,7 @@ class urlopen_FileTests(unittest.TestCase):
def test_interface(self):
# Make sure object returned by urlopen() has the specified methods
for attr in ("read", "readline", "readlines", "fileno",
- "close", "info", "geturl", "__iter__"):
+ "close", "info", "geturl", "getcode", "__iter__"):
self.assert_(hasattr(self.returned_obj, attr),
"object returned by urlopen() lacks %s attribute" %
attr)
@@ -87,6 +87,9 @@ class urlopen_FileTests(unittest.TestCase):
def test_geturl(self):
self.assertEqual(self.returned_obj.geturl(), self.pathname)
+ def test_getcode(self):
+ self.assertEqual(self.returned_obj.getcode(), None)
+
def test_iter(self):
# Test iterator
# Don't need to count number of iterations since test would fail the
@@ -123,6 +126,8 @@ class urlopen_HttpTests(unittest.TestCase):
fp = urllib.urlopen("http://python.org/")
self.assertEqual(fp.readline(), b"Hello!")
self.assertEqual(fp.readline(), b"")
+ self.assertEqual(fp.geturl(), 'http://python.org/')
+ self.assertEqual(fp.getcode(), 200)
finally:
self.unfakehttp()
diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py
index ebd9d2d..a7d3805 100644
--- a/Lib/test/test_urllibnet.py
+++ b/Lib/test/test_urllibnet.py
@@ -83,6 +83,16 @@ class urlopenNetworkTests(unittest.TestCase):
open_url.close()
self.assertEqual(gotten_url, URL)
+ def test_getcode(self):
+ # test getcode() with the fancy opener to get 404 error codes
+ URL = "http://www.python.org/XXXinvalidXXX"
+ open_url = urllib.FancyURLopener().open(URL)
+ try:
+ code = open_url.getcode()
+ finally:
+ open_url.close()
+ self.assertEqual(code, 404)
+
def test_fileno(self):
if (sys.platform in ('win32',) or
not hasattr(os, 'fdopen')):