summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_ast.py8
-rw-r--r--Lib/test/test_inspect.py22
-rw-r--r--Lib/test/test_module.py8
-rw-r--r--Lib/test/test_strptime.py15
-rw-r--r--Lib/test/test_tokenize.py18
5 files changed, 63 insertions, 8 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index c22d0d4..7ee16bf 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -140,6 +140,14 @@ class AST_Tests(unittest.TestCase):
self.assertEquals(to_tuple(ast_tree), o)
self._assertTrueorder(ast_tree, (0, 0))
+ def test_base_classes(self):
+ self.assertTrue(issubclass(ast.For, ast.stmt))
+ self.assertTrue(issubclass(ast.Name, ast.expr))
+ self.assertTrue(issubclass(ast.stmt, ast.AST))
+ self.assertTrue(issubclass(ast.expr, ast.AST))
+ self.assertTrue(issubclass(ast.comprehension, ast.AST))
+ self.assertTrue(issubclass(ast.Gt, ast.AST))
+
def test_nodeclasses(self):
x = ast.BinOp(1, 2, 3, lineno=0)
self.assertEquals(x.left, 1)
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index c1df23e..9dba30d 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -120,6 +120,28 @@ class TestPredicates(IsTestBase):
self.assertTrue('a' in members)
self.assertTrue('b' not in members)
+ def test_isabstract(self):
+ from abc import ABCMeta, abstractmethod
+
+ class AbstractClassExample(metaclass=ABCMeta):
+
+ @abstractmethod
+ def foo(self):
+ pass
+
+ class ClassExample(AbstractClassExample):
+ def foo(self):
+ pass
+
+ a = ClassExample()
+
+ # Test general behaviour.
+ self.assertTrue(inspect.isabstract(AbstractClassExample))
+ self.assertFalse(inspect.isabstract(ClassExample))
+ self.assertFalse(inspect.isabstract(a))
+ self.assertFalse(inspect.isabstract(int))
+ self.assertFalse(inspect.isabstract(5))
+
class TestInterpreterStack(IsTestBase):
def __init__(self, *args, **kwargs):
diff --git a/Lib/test/test_module.py b/Lib/test/test_module.py
index 0e56290..21ddc9a 100644
--- a/Lib/test/test_module.py
+++ b/Lib/test/test_module.py
@@ -55,6 +55,14 @@ class ModuleTests(unittest.TestCase):
{"__name__": "foo", "__doc__": "foodoc", "bar": 42})
self.assertTrue(foo.__dict__ is d)
+ def test_dont_clear_dict(self):
+ # See issue 7140.
+ def f():
+ foo = ModuleType("foo")
+ foo.bar = 4
+ return foo
+ self.assertEqual(f().__dict__["bar"], 4)
+
def test_main():
run_unittest(ModuleTests)
diff --git a/Lib/test/test_strptime.py b/Lib/test/test_strptime.py
index fb60ee4..9008717 100644
--- a/Lib/test/test_strptime.py
+++ b/Lib/test/test_strptime.py
@@ -493,9 +493,9 @@ class CacheTests(unittest.TestCase):
_strptime._strptime_time("10", "%d")
_strptime._strptime_time("2005", "%Y")
_strptime._TimeRE_cache.locale_time.lang = "Ni"
- original_time_re = id(_strptime._TimeRE_cache)
+ original_time_re = _strptime._TimeRE_cache
_strptime._strptime_time("10", "%d")
- self.assertNotEqual(original_time_re, id(_strptime._TimeRE_cache))
+ self.assertIsNot(original_time_re, _strptime._TimeRE_cache)
self.assertEqual(len(_strptime._regex_cache), 1)
def test_regex_cleanup(self):
@@ -514,11 +514,10 @@ class CacheTests(unittest.TestCase):
def test_new_localetime(self):
# A new LocaleTime instance should be created when a new TimeRE object
# is created.
- locale_time_id = id(_strptime._TimeRE_cache.locale_time)
+ locale_time_id = _strptime._TimeRE_cache.locale_time
_strptime._TimeRE_cache.locale_time.lang = "Ni"
_strptime._strptime_time("10", "%d")
- self.assertNotEqual(locale_time_id,
- id(_strptime._TimeRE_cache.locale_time))
+ self.assertIsNot(locale_time_id, _strptime._TimeRE_cache.locale_time)
def test_TimeRE_recreation(self):
# The TimeRE instance should be recreated upon changing the locale.
@@ -530,15 +529,15 @@ class CacheTests(unittest.TestCase):
try:
_strptime._strptime_time('10', '%d')
# Get id of current cache object.
- first_time_re_id = id(_strptime._TimeRE_cache)
+ first_time_re = _strptime._TimeRE_cache
try:
# Change the locale and force a recreation of the cache.
locale.setlocale(locale.LC_TIME, ('de_DE', 'UTF8'))
_strptime._strptime_time('10', '%d')
# Get the new cache object's id.
- second_time_re_id = id(_strptime._TimeRE_cache)
+ second_time_re = _strptime._TimeRE_cache
# They should not be equal.
- self.assertNotEqual(first_time_re_id, second_time_re_id)
+ self.assertIsNot(first_time_re, second_time_re)
# Possible test locale is not supported while initial locale is.
# If this is the case just suppress the exception and fall-through
# to the reseting to the original locale.
diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py
index ba705ba..7b91ab2 100644
--- a/Lib/test/test_tokenize.py
+++ b/Lib/test/test_tokenize.py
@@ -531,6 +531,24 @@ pass the '-ucompiler' option to process the full directory.
... break
... else: True
True
+
+Evil tabs
+ >>> dump_tokens("def f():\\n\\tif x\\n \\tpass")
+ ENCODING 'utf-8' (0, 0) (0, 0)
+ NAME 'def' (1, 0) (1, 3)
+ NAME 'f' (1, 4) (1, 5)
+ OP '(' (1, 5) (1, 6)
+ OP ')' (1, 6) (1, 7)
+ OP ':' (1, 7) (1, 8)
+ NEWLINE '\\n' (1, 8) (1, 9)
+ INDENT '\\t' (2, 0) (2, 1)
+ NAME 'if' (2, 1) (2, 3)
+ NAME 'x' (2, 4) (2, 5)
+ NEWLINE '\\n' (2, 5) (2, 6)
+ INDENT ' \\t' (3, 0) (3, 9)
+ NAME 'pass' (3, 9) (3, 13)
+ DEDENT '' (4, 0) (4, 0)
+ DEDENT '' (4, 0) (4, 0)
"""
from test import support