|
| 1 | +import pytest |
| 2 | +from docstring_to_markdown.cpython import looks_like_cpython, cpython_to_markdown |
| 3 | + |
| 4 | +BOOL = """\ |
| 5 | +bool(x) -> bool |
| 6 | +
|
| 7 | +Returns True when the argument x is true, False otherwise.\ |
| 8 | +""" |
| 9 | + |
| 10 | +BOOL_MD = """\ |
| 11 | +``` |
| 12 | +bool(x) -> bool |
| 13 | +``` |
| 14 | +
|
| 15 | +Returns True when the argument x is true, False otherwise.\ |
| 16 | +""" |
| 17 | + |
| 18 | +BYTES = """\ |
| 19 | +bytes(iterable_of_ints) -> bytes |
| 20 | +bytes(string, encoding[, errors]) -> bytes |
| 21 | +bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer |
| 22 | +bytes(int) -> bytes object of size given by the parameter initialized with null bytes |
| 23 | +bytes() -> empty bytes object |
| 24 | +
|
| 25 | +Construct an immutable array of bytes from: |
| 26 | + - an iterable yielding integers in range(256) |
| 27 | + - a text string encoded using the specified encoding |
| 28 | + - any object implementing the buffer API. |
| 29 | + - an integer\ |
| 30 | +""" |
| 31 | + |
| 32 | +COLLECTIONS_DEQUEUE = """\ |
| 33 | +deque([iterable[, maxlen]]) --> deque object |
| 34 | +
|
| 35 | +A list-like sequence optimized for data accesses near its endpoints.\ |
| 36 | +""" |
| 37 | + |
| 38 | +DICT = """\ |
| 39 | +dict() -> new empty dictionary |
| 40 | +dict(mapping) -> new dictionary initialized from a mapping object's |
| 41 | + (key, value) pairs |
| 42 | +dict(iterable) -> new dictionary initialized as if via: |
| 43 | + d = {} |
| 44 | + for k, v in iterable: |
| 45 | + d[k] = v |
| 46 | +dict(**kwargs) -> new dictionary initialized with the name=value pairs |
| 47 | + in the keyword argument list. For example: dict(one=1, two=2)\ |
| 48 | +""" |
| 49 | + |
| 50 | +STR = """\ |
| 51 | +str(object='') -> str |
| 52 | +str(bytes_or_buffer[, encoding[, errors]]) -> str |
| 53 | +
|
| 54 | +Create a new string object from the given object. If encoding or |
| 55 | +errors is specified, then the object must expose a data buffer |
| 56 | +that will be decoded using the given encoding and error handler. |
| 57 | +Otherwise, returns the result of object.__str__() (if defined) |
| 58 | +or repr(object).\ |
| 59 | +""" |
| 60 | + |
| 61 | +STR_MD = """\ |
| 62 | +``` |
| 63 | +str(object='') -> str |
| 64 | +str(bytes_or_buffer[, encoding[, errors]]) -> str |
| 65 | +``` |
| 66 | +
|
| 67 | +Create a new string object from the given object. If encoding or |
| 68 | +errors is specified, then the object must expose a data buffer |
| 69 | +that will be decoded using the given encoding and error handler. |
| 70 | +Otherwise, returns the result of object.\\_\\_str\\_\\_() (if defined) |
| 71 | +or repr(object).\ |
| 72 | +""" |
| 73 | + |
| 74 | + |
| 75 | +@pytest.mark.parametrize("text", [BYTES, STR, DICT, BOOL, COLLECTIONS_DEQUEUE]) |
| 76 | +def test_accepts_cpython_docstrings(text): |
| 77 | + assert looks_like_cpython(text) is True |
| 78 | + |
| 79 | + |
| 80 | +@pytest.mark.parametrize("text", [ |
| 81 | + "[link label](https://link)", |
| 82 | + "", |
| 83 | + "Some **bold** text", |
| 84 | + "More __bold__ text", |
| 85 | + "Some *italic* text", |
| 86 | + "More _italic_ text", |
| 87 | + "This is a sentence.", |
| 88 | + "Exclamation!", |
| 89 | + "Can I ask a question?", |
| 90 | + "Let's send an e-mail", |
| 91 | + "Parentheses (are) fine (really)", |
| 92 | + "Double \"quotes\" and single 'quotes'" |
| 93 | +]) |
| 94 | +def test_rejects_markdown_and_plain_text(text): |
| 95 | + assert looks_like_cpython(text) is False |
| 96 | + |
| 97 | + |
| 98 | +def test_conversion_bool(): |
| 99 | + assert cpython_to_markdown(BOOL) == BOOL_MD |
| 100 | + |
| 101 | + |
| 102 | +def test_conversion_str(): |
| 103 | + assert cpython_to_markdown(STR) == STR_MD |
0 commit comments