summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_builtin.py5
-rw-r--r--Lib/test/test_grammar.py2
-rw-r--r--Lib/test/test_mmap.py36
-rw-r--r--Lib/test/test_socket.py1
-rw-r--r--Lib/test/test_ssl.py22
-rw-r--r--Lib/test/test_textwrap.py13
-rw-r--r--Lib/test/test_xmlrpc.py3
7 files changed, 79 insertions, 3 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 4cf5916..2718bbf 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -743,6 +743,11 @@ class BuiltinTest(unittest.TestCase):
self.assertEqual(int('0O123', 8), 83)
self.assertEqual(int('0B100', 2), 4)
+ # Bug 1679: "0x" is not a valid hex literal
+ self.assertRaises(ValueError, int, "0x", 16)
+ self.assertRaises(ValueError, int, "0x", 0)
+
+
# SF bug 1334662: int(string, base) wrong answers
# Various representations of 2**32 evaluated to 0
# rather than 2**32 in previous versions
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index 7ab7557..0777307 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -32,6 +32,8 @@ class TokenTests(unittest.TestCase):
self.assertEquals(0o377, 255)
self.assertEquals(2147483647, 0o17777777777)
self.assertEquals(0b1001, 9)
+ # "0x" is not a valid literal
+ self.assertRaises(SyntaxError, eval, "0x")
from sys import maxsize
if maxsize == 2147483647:
self.assertEquals(-2147483647-1, -0o20000000000)
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index 3d30109..5bf7eb0 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -252,6 +252,42 @@ class MmapTests(unittest.TestCase):
self.assertEqual(m.find(slice + b'x'), -1)
m.close()
+ def test_find_end(self):
+ # test the new 'end' parameter works as expected
+ f = open(TESTFN, 'w+')
+ data = 'one two ones'
+ n = len(data)
+ f.write(data)
+ f.flush()
+ m = mmap.mmap(f.fileno(), n)
+ f.close()
+
+ self.assertEqual(m.find('one'), 0)
+ self.assertEqual(m.find('ones'), 8)
+ self.assertEqual(m.find('one', 0, -1), 0)
+ self.assertEqual(m.find('one', 1), 8)
+ self.assertEqual(m.find('one', 1, -1), 8)
+ self.assertEqual(m.find('one', 1, -2), -1)
+
+
+ def test_rfind(self):
+ # test the new 'end' parameter works as expected
+ f = open(TESTFN, 'w+')
+ data = 'one two ones'
+ n = len(data)
+ f.write(data)
+ f.flush()
+ m = mmap.mmap(f.fileno(), n)
+ f.close()
+
+ self.assertEqual(m.rfind('one'), 8)
+ self.assertEqual(m.rfind('one '), 0)
+ self.assertEqual(m.rfind('one', 0, -1), 8)
+ self.assertEqual(m.rfind('one', 0, -2), 0)
+ self.assertEqual(m.rfind('one', 1, -1), 8)
+ self.assertEqual(m.rfind('one', 1, -2), -1)
+
+
def test_double_close(self):
# make sure a double close doesn't crash on Solaris (Bug# 665913)
f = open(TESTFN, 'wb+')
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 23b7759..d3b870f 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -288,7 +288,6 @@ class GeneralModuleTests(unittest.TestCase):
def testRefCountGetNameInfo(self):
# Testing reference count for getnameinfo
- import sys
if hasattr(sys, "getrefcount"):
try:
# On some versions, this loses a reference
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index 81943a5..34bb31a 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -38,6 +38,27 @@ def handle_error(prefix):
class BasicTests(unittest.TestCase):
+ def testSSLconnect(self):
+ if not test_support.is_resource_enabled('network'):
+ return
+ s = ssl.wrap_socket(socket.socket(socket.AF_INET),
+ cert_reqs=ssl.CERT_NONE)
+ s.connect(("svn.python.org", 443))
+ c = s.getpeercert()
+ if c:
+ raise test_support.TestFailed("Peer cert %s shouldn't be here!")
+ s.close()
+
+ # this should fail because we have no verification certs
+ s = ssl.wrap_socket(socket.socket(socket.AF_INET),
+ cert_reqs=ssl.CERT_REQUIRED)
+ try:
+ s.connect(("svn.python.org", 443))
+ except ssl.SSLError:
+ pass
+ finally:
+ s.close()
+
def testCrucialConstants(self):
ssl.PROTOCOL_SSLv2
ssl.PROTOCOL_SSLv23
@@ -81,7 +102,6 @@ class BasicTests(unittest.TestCase):
class NetworkedTests(unittest.TestCase):
def testConnect(self):
-
s = ssl.wrap_socket(socket.socket(socket.AF_INET),
cert_reqs=ssl.CERT_NONE)
s.connect(("svn.python.org", 443))
diff --git a/Lib/test/test_textwrap.py b/Lib/test/test_textwrap.py
index b226c71..3f2239d 100644
--- a/Lib/test/test_textwrap.py
+++ b/Lib/test/test_textwrap.py
@@ -385,6 +385,19 @@ How *do* you spell that odd word, anyways?
' o'],
subsequent_indent = ' '*15)
+ # bug 1146. Prevent a long word to be wrongly wrapped when the
+ # preceding word is exactly one character shorter than the width
+ self.check_wrap(self.text, 12,
+ ['Did you say ',
+ '"supercalifr',
+ 'agilisticexp',
+ 'ialidocious?',
+ '" How *do*',
+ 'you spell',
+ 'that odd',
+ 'word,',
+ 'anyways?'])
+
def test_nobreak_long(self):
# Test with break_long_words disabled
self.wrapper.break_long_words = 0
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
index ade6f84..16ef798 100644
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -347,7 +347,8 @@ class SimpleServerTestCase(unittest.TestCase):
# protocol error; provide additional information in test output
self.fail("%s\n%s" % (e, e.headers))
- def test_404(self):
+ # [ch] The test 404 is causing lots of false alarms.
+ def XXXtest_404(self):
# send POST with httplib, it should return 404 header and
# 'Not Found' message.
conn = httplib.HTTPConnection('localhost', PORT)