diff options
Diffstat (limited to 'Lib/test')
-rwxr-xr-x | Lib/test/regrtest.py | 7 | ||||
-rw-r--r-- | Lib/test/test_descr.py | 65 | ||||
-rw-r--r-- | Lib/test/test_dict.py | 4 | ||||
-rw-r--r-- | Lib/test/test_marshal.py | 11 | ||||
-rw-r--r-- | Lib/test/test_set.py | 49 |
5 files changed, 130 insertions, 6 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index cd92511..3a24b22 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -588,10 +588,9 @@ def runtest_inner(test, generate, verbose, quiet, abstest = 'test.' + test the_package = __import__(abstest, globals(), locals(), []) the_module = getattr(the_package, test) - # Most tests run to completion simply as a side-effect of - # being imported. For the benefit of tests that can't run - # that way (like test_threaded_import), explicitly invoke - # their test_main() function (if it exists). + # Old tests run to completion simply as a side-effect of + # being imported. For tests based on unittest or doctest, + # explicitly invoke their test_main() function (if it exists). indirect_test = getattr(the_module, "test_main", None) if indirect_test is not None: indirect_test() diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 961369f..1ea93bb 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -1984,6 +1984,71 @@ def properties(): p = property(_testcapi.test_with_docstring) +def properties_plus(): + class C: + foo = property(doc="hello") + @foo.getter + def foo(self): + return self._foo + @foo.setter + def foo(self, value): + self._foo = abs(value) + @foo.deleter + def foo(self): + del self._foo + c = C() + assert C.foo.__doc__ == "hello" + assert not hasattr(c, "foo") + c.foo = -42 + assert c.foo == 42 + del c.foo + assert not hasattr(c, "foo") + + class D(C): + @C.foo.deleter + def foo(self): + try: + del self._foo + except AttributeError: + pass + d = D() + d.foo = 24 + assert d.foo == 24 + del d.foo + del d.foo + + class E: + @property + def foo(self): + return self._foo + @foo.setter + def foo (self, value): + raise RuntimeError + @foo.setter + @foo.deleter + def foo(self, value=None): + if value is None: + del self._foo + else: + self._foo = abs(value) + e = E() + e.foo = -42 + assert e.foo == 42 + del e.foo + + class F(E): + @E.foo.deleter + def foo(self): + del self._foo + @foo.setter + def foo(self, value): + self._foo = max(0, value) + f = F() + f.foo = -10 + assert f.foo == 0 + del f.foo + + def supers(): if verbose: print("Testing super...") diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py index 89c127a..56ce722 100644 --- a/Lib/test/test_dict.py +++ b/Lib/test/test_dict.py @@ -236,6 +236,10 @@ class DictTest(unittest.TestCase): self.assertRaises(Exc, baddict2.fromkeys, [1]) + # test fast path for dictionary inputs + d = dict(zip(range(6), range(6))) + self.assertEqual(dict.fromkeys(d, 0), dict(zip(range(6), [0]*6))) + def test_copy(self): d = {1:1, 2:2, 3:3} self.assertEqual(d.copy(), {1:1, 2:2, 3:3}) diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py index 1e3520f..fb70ced 100644 --- a/Lib/test/test_marshal.py +++ b/Lib/test/test_marshal.py @@ -188,6 +188,17 @@ class BugsTestCase(unittest.TestCase): last.append([0]) self.assertRaises(ValueError, marshal.dumps, head) + def test_exact_type_match(self): + # Former bug: + # >>> class Int(int): pass + # >>> type(loads(dumps(Int()))) + # <type 'int'> + for typ in (int, float, complex, tuple, list, dict, set, frozenset): + # Note: str sublclasses are not tested because they get handled + # by marshal's routines for objects supporting the buffer API. + subtyp = type('subtyp', (typ,), {}) + self.assertRaises(ValueError, marshal.dumps, subtyp()) + def test_main(): test_support.run_unittest(IntTestCase, FloatTestCase, diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index 86a5636..ba5801d 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -102,6 +102,20 @@ class TestJointOps(unittest.TestCase): self.assertEqual(self.thetype('abcba').intersection(C('ccb')), set('bc')) self.assertEqual(self.thetype('abcba').intersection(C('ef')), set('')) + def test_isdisjoint(self): + def f(s1, s2): + 'Pure python equivalent of isdisjoint()' + return not set(s1).intersection(s2) + for larg in '', 'a', 'ab', 'abc', 'ababac', 'cdc', 'cc', 'efgfe', 'ccb', 'ef': + s1 = self.thetype(larg) + for rarg in '', 'a', 'ab', 'abc', 'ababac', 'cdc', 'cc', 'efgfe', 'ccb', 'ef': + for C in set, frozenset, dict.fromkeys, str, list, tuple: + s2 = C(rarg) + actual = s1.isdisjoint(s2) + expected = f(s1, s2) + self.assertEqual(actual, expected) + self.assert_(actual is True or actual is False) + def test_and(self): i = self.s.intersection(self.otherword) self.assertEqual(self.s & set(self.otherword), i) @@ -701,6 +715,18 @@ class TestBasicOps(unittest.TestCase): result = empty_set & self.set self.assertEqual(result, empty_set) + def test_self_isdisjoint(self): + result = self.set.isdisjoint(self.set) + self.assertEqual(result, not self.set) + + def test_empty_isdisjoint(self): + result = self.set.isdisjoint(empty_set) + self.assertEqual(result, True) + + def test_isdisjoint_empty(self): + result = empty_set.isdisjoint(self.set) + self.assertEqual(result, True) + def test_self_symmetric_difference(self): result = self.set ^ self.set self.assertEqual(result, empty_set) @@ -879,6 +905,22 @@ class TestBinaryOps(unittest.TestCase): result = self.set & set([8]) self.assertEqual(result, empty_set) + def test_isdisjoint_subset(self): + result = self.set.isdisjoint(set((2, 4))) + self.assertEqual(result, False) + + def test_isdisjoint_superset(self): + result = self.set.isdisjoint(set([2, 4, 6, 8])) + self.assertEqual(result, False) + + def test_isdisjoint_overlap(self): + result = self.set.isdisjoint(set([3, 4, 5])) + self.assertEqual(result, False) + + def test_isdisjoint_non_overlap(self): + result = self.set.isdisjoint(set([8])) + self.assertEqual(result, True) + def test_sym_difference_subset(self): result = self.set ^ set((2, 4)) self.assertEqual(result, set([6])) @@ -1497,11 +1539,14 @@ class TestVariousIteratorArgs(unittest.TestCase): def test_inline_methods(self): s = set('november') for data in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5), 'december'): - for meth in (s.union, s.intersection, s.difference, s.symmetric_difference): + for meth in (s.union, s.intersection, s.difference, s.symmetric_difference, s.isdisjoint): for g in (G, I, Ig, L, R): expected = meth(data) actual = meth(G(data)) - self.assertEqual(sorted(actual, key=repr), sorted(expected, key=repr)) + if isinstance(expected, bool): + self.assertEqual(actual, expected) + else: + self.assertEqual(sorted(actual, key=repr), sorted(expected, key=repr)) self.assertRaises(TypeError, meth, X(s)) self.assertRaises(TypeError, meth, N(s)) self.assertRaises(ZeroDivisionError, meth, E(s)) |