summaryrefslogtreecommitdiff
path: root/Lib/test/test_funcattrs.py
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2009-02-01 10:28:51 +0000
committerMark Dickinson <dickinsm@gmail.com>2009-02-01 10:28:51 +0000
commit211c6258294bf683935bff73a61ce3dd84070988 (patch)
tree8dc2a5a5fdcd1f7bc0e176bce006b12e1b588a05 /Lib/test/test_funcattrs.py
parent776e7014e97a79cc2bd5fffd15908e83ff0273cf (diff)
downloadcpython-git-211c6258294bf683935bff73a61ce3dd84070988.tar.gz
Issue #1717, stage 2: remove uses of tp_compare in Modules and most
Objects.
Diffstat (limited to 'Lib/test/test_funcattrs.py')
-rw-r--r--Lib/test/test_funcattrs.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/Lib/test/test_funcattrs.py b/Lib/test/test_funcattrs.py
index 5e9f7d3aff..7aab8b813e 100644
--- a/Lib/test/test_funcattrs.py
+++ b/Lib/test/test_funcattrs.py
@@ -224,10 +224,41 @@ class FunctionDocstringTest(FuncAttrsTest):
del self.b.__doc__
self.assertEqual(self.b.__doc__, None)
+def cell(value):
+ """Create a cell containing the given value."""
+ def f():
+ print(a)
+ a = value
+ return f.__closure__[0]
+
+def empty_cell(empty=True):
+ """Create an empty cell."""
+ def f():
+ print(a)
+ # the intent of the following line is simply "if False:"; it's
+ # spelt this way to avoid the danger that a future optimization
+ # might simply remove an "if False:" code block.
+ if not empty:
+ a = 1729
+ return f.__closure__[0]
+
+class CellTest(unittest.TestCase):
+ def test_comparison(self):
+ # These tests are here simply to exercise the comparison code;
+ # their presence should not be interpreted as providing any
+ # guarantees about the semantics (or even existence) of cell
+ # comparisons in future versions of CPython.
+ self.assert_(cell(2) < cell(3))
+ self.assert_(empty_cell() < cell('saturday'))
+ self.assert_(empty_cell() == empty_cell())
+ self.assert_(cell(-36) == cell(-36.0))
+ self.assert_(cell(True) > empty_cell())
+
+
def test_main():
support.run_unittest(FunctionPropertiesTest, ImplicitReferencesTest,
ArbitraryFunctionAttrTest, FunctionDictsTest,
- FunctionDocstringTest)
+ FunctionDocstringTest, CellTest)
if __name__ == "__main__":
test_main()