summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_bytes.py10
-rw-r--r--Lib/test/test_capi.py35
-rw-r--r--Lib/test/test_imp.py5
-rw-r--r--Lib/test/test_unicode.py8
4 files changed, 55 insertions, 3 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index d074758..5eab8f5 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -303,6 +303,11 @@ class BaseBytesTest(unittest.TestCase):
self.assertTrue(b.startswith(b"h"))
self.assertFalse(b.startswith(b"hellow"))
self.assertFalse(b.startswith(b"ha"))
+ with self.assertRaises(TypeError) as cm:
+ b.startswith([b'h'])
+ exc = str(cm.exception)
+ self.assertIn('bytes', exc)
+ self.assertIn('tuple', exc)
def test_endswith(self):
b = self.type2test(b'hello')
@@ -312,6 +317,11 @@ class BaseBytesTest(unittest.TestCase):
self.assertTrue(b.endswith(b"o"))
self.assertFalse(b.endswith(b"whello"))
self.assertFalse(b.endswith(b"no"))
+ with self.assertRaises(TypeError) as cm:
+ b.endswith([b'o'])
+ exc = str(cm.exception)
+ self.assertIn('bytes', exc)
+ self.assertIn('tuple', exc)
def test_find(self):
b = self.type2test(b'mississippi')
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index f913347..327ac66 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -2,6 +2,7 @@
# these are all functions _testcapi exports whose name begins with 'test_'.
from __future__ import with_statement
+import os
import random
import subprocess
import sys
@@ -141,8 +142,38 @@ class Test6012(unittest.TestCase):
def test(self):
self.assertEqual(_testcapi.argparsing("Hello", "World"), 1)
+
+class EmbeddingTest(unittest.TestCase):
+
+ def test_subinterps(self):
+ # XXX only tested under Unix checkouts
+ basepath = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
+ oldcwd = os.getcwd()
+ # This is needed otherwise we get a fatal error:
+ # "Py_Initialize: Unable to get the locale encoding
+ # LookupError: no codec search functions registered: can't find encoding"
+ os.chdir(basepath)
+ try:
+ exe = os.path.join(basepath, "Modules", "_testembed")
+ if not os.path.exists(exe):
+ self.skipTest("%r doesn't exist" % exe)
+ p = subprocess.Popen([exe],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ (out, err) = p.communicate()
+ self.assertEqual(p.returncode, 0,
+ "bad returncode %d, stderr is %r" %
+ (p.returncode, err))
+ if support.verbose:
+ print()
+ print(out.decode('latin1'))
+ print(err.decode('latin1'))
+ finally:
+ os.chdir(oldcwd)
+
+
def test_main():
- support.run_unittest(CAPITest)
+ support.run_unittest(CAPITest, TestPendingCalls, Test6012, EmbeddingTest)
for name in dir(_testcapi):
if name.startswith('test_'):
@@ -177,8 +208,6 @@ def test_main():
t.start()
t.join()
- support.run_unittest(TestPendingCalls, Test6012)
-
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py
index d745ae9..551ad1b 100644
--- a/Lib/test/test_imp.py
+++ b/Lib/test/test_imp.py
@@ -170,6 +170,11 @@ class ImportTests(unittest.TestCase):
support.unlink(init_file_name + ext)
support.rmtree(test_package_name)
+ def test_issue9319(self):
+ path = os.path.dirname(__file__)
+ self.assertRaises(SyntaxError,
+ imp.find_module, "badsyntax_pep3120", [path])
+
class ReloadTests(unittest.TestCase):
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 65b26c5..97be587 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -819,6 +819,14 @@ class UnicodeTest(string_tests.CommonTest,
self.assertEqual('%f' % INF, 'inf')
self.assertEqual('%F' % INF, 'INF')
+ def test_startswith_endswith_errors(self):
+ for meth in ('foo'.startswith, 'foo'.endswith):
+ with self.assertRaises(TypeError) as cm:
+ meth(['f'])
+ exc = str(cm.exception)
+ self.assertIn('str', exc)
+ self.assertIn('tuple', exc)
+
@support.run_with_locale('LC_ALL', 'de_DE', 'fr_FR')
def test_format_float(self):
# should not format with a comma, but always with C locale