summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_complex.py14
-rw-r--r--Lib/test/test_descr.py17
-rw-r--r--Lib/test/test_gc.py22
-rw-r--r--Lib/test/test_mmap.py7
4 files changed, 55 insertions, 5 deletions
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py
index 42dc3cf..fbed4f2 100644
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -4,6 +4,8 @@ from test import test_support
from random import random
from math import atan2
+INF = float("inf")
+NAN = float("nan")
# These tests ensure that complex math does the right thing
class ComplexTest(unittest.TestCase):
@@ -316,6 +318,18 @@ class ComplexTest(unittest.TestCase):
self.assertEqual(-6j,complex(repr(-6j)))
self.assertEqual(6j,complex(repr(6j)))
+ self.assertEqual(repr(complex(1., INF)), "(1+inf*j)")
+ self.assertEqual(repr(complex(1., -INF)), "(1-inf*j)")
+ self.assertEqual(repr(complex(INF, 1)), "(inf+1j)")
+ self.assertEqual(repr(complex(-INF, INF)), "(-inf+inf*j)")
+ self.assertEqual(repr(complex(NAN, 1)), "(nan+1j)")
+ self.assertEqual(repr(complex(1, NAN)), "(1+nan*j)")
+ self.assertEqual(repr(complex(NAN, NAN)), "(nan+nan*j)")
+
+ self.assertEqual(repr(complex(0, INF)), "inf*j")
+ self.assertEqual(repr(complex(0, -INF)), "-inf*j")
+ self.assertEqual(repr(complex(0, NAN)), "nan*j")
+
def test_neg(self):
self.assertEqual(-(1+6j), -1-6j)
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index d28a84a..288afd4 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1067,6 +1067,23 @@ order (MRO) for bases """
a.foo = 42
self.assertEqual(a.__dict__, {"foo": 42})
+ def test_slots_descriptor(self):
+ # Issue2115: slot descriptors did not correctly check
+ # the type of the given object
+ import abc
+ class MyABC(metaclass=abc.ABCMeta):
+ __slots__ = "a"
+
+ class Unrelated(object):
+ pass
+ MyABC.register(Unrelated)
+
+ u = Unrelated()
+ self.assert_(isinstance(u, MyABC))
+
+ # This used to crash
+ self.assertRaises(TypeError, MyABC.a.__set__, u, 3)
+
def test_dynamics(self):
# Testing class attribute propagation...
class D(object):
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py
index bae0038..9d5e0ea 100644
--- a/Lib/test/test_gc.py
+++ b/Lib/test/test_gc.py
@@ -236,21 +236,33 @@ class GCTests(unittest.TestCase):
gc.disable()
gc.set_threshold(*thresholds)
+ # The following two tests are fragile:
+ # They precisely count the number of allocations,
+ # which is highly implementation-dependent.
+ # For example:
+ # - disposed tuples are not freed, but reused
+ # - the call to assertEqual somehow avoids building its args tuple
def test_get_count(self):
+ # Avoid future allocation of method object
+ assertEqual = self.assertEqual
gc.collect()
- self.assertEqual(gc.get_count(), (0, 0, 0))
+ assertEqual(gc.get_count(), (0, 0, 0))
a = dict()
- self.assertEqual(gc.get_count(), (1, 0, 0))
+ # since gc.collect(), we created two objects:
+ # the dict, and the tuple returned by get_count()
+ assertEqual(gc.get_count(), (2, 0, 0))
def test_collect_generations(self):
+ # Avoid future allocation of method object
+ assertEqual = self.assertEqual
gc.collect()
a = dict()
gc.collect(0)
- self.assertEqual(gc.get_count(), (0, 1, 0))
+ assertEqual(gc.get_count(), (0, 1, 0))
gc.collect(1)
- self.assertEqual(gc.get_count(), (0, 0, 1))
+ assertEqual(gc.get_count(), (0, 0, 1))
gc.collect(2)
- self.assertEqual(gc.get_count(), (0, 0, 0))
+ assertEqual(gc.get_count(), (0, 0, 0))
def test_trashcan(self):
class Ouch:
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index f6ee371..c3f7dbb 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -425,6 +425,13 @@ class MmapTests(unittest.TestCase):
return mmap.mmap.__new__(klass, -1, *args, **kwargs)
anon_mmap(PAGESIZE)
+ def test_prot_readonly(self):
+ mapsize = 10
+ open(TESTFN, "wb").write(b"a"*mapsize)
+ f = open(TESTFN, "rb")
+ m = mmap.mmap(f.fileno(), mapsize, prot=mmap.PROT_READ)
+ self.assertRaises(TypeError, m.write, "foo")
+
def test_main():
run_unittest(MmapTests)