summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_collections.py8
-rw-r--r--Lib/test/test_descr.py5
-rw-r--r--Lib/test/test_property.py22
3 files changed, 34 insertions, 1 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index ad94fdd..2bb5538 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -199,6 +199,14 @@ class TestNamedTuple(unittest.TestCase):
Point = namedtuple('Point', 'x y')
self.assertEqual(Point.__doc__, 'Point(x, y)')
+ @unittest.skipIf(sys.flags.optimize >= 2,
+ "Docstrings are omitted with -O2 and above")
+ def test_doc_writable(self):
+ Point = namedtuple('Point', 'x y')
+ self.assertEqual(Point.x.__doc__, 'Alias for field number 0')
+ Point.x.__doc__ = 'docstring for Point.x'
+ self.assertEqual(Point.x.__doc__, 'docstring for Point.x')
+
def test_name_fixer(self):
for spec, renamed in [
[('efg', 'g%hi'), ('efg', '_1')], # field with non-alpha char
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 9f3d34d..80a526d 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -2022,7 +2022,7 @@ order (MRO) for bases """
self.assertIs(raw.fset, C.__dict__['setx'])
self.assertIs(raw.fdel, C.__dict__['delx'])
- for attr in "__doc__", "fget", "fset", "fdel":
+ for attr in "fget", "fset", "fdel":
try:
setattr(raw, attr, 42)
except AttributeError as msg:
@@ -2033,6 +2033,9 @@ order (MRO) for bases """
self.fail("expected AttributeError from trying to set readonly %r "
"attr on a property" % attr)
+ raw.__doc__ = 42
+ self.assertEqual(raw.__doc__, 42)
+
class D(object):
__getitem__ = property(lambda s: 1/0)
diff --git a/Lib/test/test_property.py b/Lib/test/test_property.py
index e72eb55..5addd36 100644
--- a/Lib/test/test_property.py
+++ b/Lib/test/test_property.py
@@ -76,6 +76,13 @@ class PropertyNewGetter(object):
"""new docstring"""
return 8
+class PropertyWritableDoc(object):
+
+ @property
+ def spam(self):
+ """Eggs"""
+ return "eggs"
+
class PropertyTests(unittest.TestCase):
def test_property_decorator_baseclass(self):
# see #1620
@@ -150,6 +157,21 @@ class PropertyTests(unittest.TestCase):
foo = property(foo)
C.foo.__isabstractmethod__
+ @unittest.skipIf(sys.flags.optimize >= 2,
+ "Docstrings are omitted with -O2 and above")
+ def test_property_builtin_doc_writable(self):
+ p = property(doc='basic')
+ self.assertEqual(p.__doc__, 'basic')
+ p.__doc__ = 'extended'
+ self.assertEqual(p.__doc__, 'extended')
+
+ @unittest.skipIf(sys.flags.optimize >= 2,
+ "Docstrings are omitted with -O2 and above")
+ def test_property_decorator_doc_writable(self):
+ sub = PropertyWritableDoc()
+ self.assertEqual(sub.__class__.spam.__doc__, 'Eggs')
+ sub.__class__.spam.__doc__ = 'Spam'
+ self.assertEqual(sub.__class__.spam.__doc__, 'Spam')
# Issue 5890: subclasses of property do not preserve method __doc__ strings
class PropertySub(property):