| 1 | from pytest import raises |
| 2 | |
| 3 | |
| 4 | def test_nodoc(): |
| 5 | class NoDoc(object): |
| 6 | pass |
| 7 | |
| 8 | try: |
| 9 | assert NoDoc.__doc__ == None |
| 10 | except AttributeError: |
| 11 | raise AssertionError("__doc__ missing!") |
| 12 | |
| 13 | def test_explicitdoc(): |
| 14 | class ExplicitDoc(object): |
| 15 | __doc__ = 'foo' |
| 16 | |
| 17 | assert ExplicitDoc.__doc__ == 'foo' |
| 18 | |
| 19 | def test_implicitdoc(): |
| 20 | class ImplicitDoc(object): |
| 21 | "foo" |
| 22 | |
| 23 | assert ImplicitDoc.__doc__ == 'foo' |
| 24 | |
| 25 | def test_set_doc(): |
| 26 | class X: |
| 27 | "elephant" |
| 28 | X.__doc__ = "banana" |
| 29 | assert X.__doc__ == "banana" |
| 30 | raises(TypeError, lambda: |
| 31 | type(list).__dict__["__doc__"].__set__(list, "blah")) |
| 32 | raises((AttributeError, TypeError), lambda: |
| 33 | type(X).__dict__["__doc__"].__delete__(X)) |
| 34 | assert X.__doc__ == "banana" |
| 35 | |
| 36 | def test_text_signature(): |
| 37 | assert object.__text_signature__ == '()' |
| 38 | |
| 39 | |
| 40 | class BufferedReader(object): |
| 41 | """BufferedReader(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n--\n\n |
| 42 | Create a new buffered reader using the given readable raw IO object. |
| 43 | """ |
| 44 | pass |
| 45 | |
| 46 | |
| 47 | assert BufferedReader.__doc__ == """BufferedReader(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n--\n\n |
| 48 | Create a new buffered reader using the given readable raw IO object. |
| 49 | """ |
| 50 | assert BufferedReader.__text_signature__ == "(raw, buffer_size=DEFAULT_BUFFER_SIZE)" |
| 51 | |
| 52 | def test_nodoc_text_signature(): |
| 53 | class NoDoc(object): |
| 54 | pass |
| 55 | |
| 56 | assert NoDoc.__text_signature__ is None |
| 57 | |
| 58 | def test_text_signature_on_function_type(): |
| 59 | def a(): pass |
| 60 | result = getattr(type(a), '__text_signature__') |
| 61 | assert result is None or isinstance(result, str) |
| 62 | |
| 63 | def test_text_signature_on_builtin_function_type(): |
| 64 | result = getattr(type(len), '__text_signature__') |
| 65 | assert result is None or isinstance(result, str) |