mktestdocs 0.2.0__py2.py3-none-any.whl → 0.2.2__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mktestdocs/__init__.py CHANGED
@@ -7,7 +7,7 @@ from mktestdocs.__main__ import (
7
7
  get_codeblock_members,
8
8
  )
9
9
 
10
- __version__ = "0.2.0"
10
+ __version__ = "0.2.2"
11
11
 
12
12
  __all__ = [
13
13
  "__version__",
mktestdocs/__main__.py CHANGED
@@ -3,7 +3,6 @@ import pathlib
3
3
  import subprocess
4
4
  import textwrap
5
5
 
6
-
7
6
  _executors = {}
8
7
 
9
8
 
@@ -90,6 +89,7 @@ def grab_code_blocks(docstring, lang="python"):
90
89
  docstring: the docstring to analyse
91
90
  lang: if not None, the language that is assigned to the codeblock
92
91
  """
92
+ docstring = format_docstring(docstring)
93
93
  docstring = textwrap.dedent(docstring)
94
94
  in_block = False
95
95
  block = ""
@@ -104,6 +104,11 @@ def grab_code_blocks(docstring, lang="python"):
104
104
  block += line + "\n"
105
105
  return [c for c in codeblocks if c != ""]
106
106
 
107
+ def format_docstring(docstring):
108
+ """Formats docstring to be able to successfully go through dedent."""
109
+ if docstring[:1] != "\n":
110
+ return f"\n {docstring}"
111
+ return docstring
107
112
 
108
113
  def check_docstring(obj, lang=""):
109
114
  """
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.1
2
+ Name: mktestdocs
3
+ Version: 0.2.2
4
+ License-File: LICENSE
5
+ Provides-Extra: test
6
+ Requires-Dist: pytest >=4.0.2 ; extra == 'test'
7
+
@@ -0,0 +1,7 @@
1
+ mktestdocs/__init__.py,sha256=wL-m_63-2NFVKQpqKySIm7y2vfwcutnIXpgLJU4xsxw,371
2
+ mktestdocs/__main__.py,sha256=J-x8TWbSanfrbry41ApOuoZRFClvXaH0Dq3SLXpZqtw,4745
3
+ mktestdocs-0.2.2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
4
+ mktestdocs-0.2.2.dist-info/METADATA,sha256=YdOdkMSjz5zQzR8VJIc3uEsCNUGHBZ932h38meQ-GW0,146
5
+ mktestdocs-0.2.2.dist-info/WHEEL,sha256=DZajD4pwLWue70CAfc7YaxT1wLUciNBvN_TTcvXpltE,110
6
+ mktestdocs-0.2.2.dist-info/top_level.txt,sha256=1XGYsQSl3FsAtilWThIet3WOJQSuzQXXn6sQA7hxlho,11
7
+ mktestdocs-0.2.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.37.1)
2
+ Generator: bdist_wheel (0.43.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py2-none-any
5
5
  Tag: py3-none-any
@@ -1,12 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: mktestdocs
3
- Version: 0.2.0
4
- Summary: UNKNOWN
5
- License: UNKNOWN
6
- Platform: UNKNOWN
7
- License-File: LICENSE
8
- Provides-Extra: test
9
- Requires-Dist: pytest (>=4.0.2) ; extra == 'test'
10
-
11
- UNKNOWN
12
-
@@ -1,14 +0,0 @@
1
- mktestdocs/__init__.py,sha256=dkhHcGV1XKIm22O3NkS7j9Cabmxpo39XNMAlLqQS_oM,371
2
- mktestdocs/__main__.py,sha256=BO5LopXLAeKFFuKcT0KaeErUeFXt8ekjIiyrTymBG3k,4508
3
- tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- tests/conftest.py,sha256=9K0dbGVqN7yeK4PJ3k36vOKGlZecILTZRJPxuEomjqM,214
5
- tests/test_actual_docstrings.py,sha256=N1yIuHOBNhv2qR2yO1DkqiBNvHK3_o_pbLJCHLKUa68,940
6
- tests/test_class.py,sha256=lkZ73We8Hb4IvPbQVn8w5LX5zMHptFHkUcJ3xfBJqgc,1220
7
- tests/test_codeblock.py,sha256=FxyPZZw1lVLFWXB1BErciHP6h-kFNBLLPU9UX_6uBfE,903
8
- tests/test_markdown.py,sha256=ny6_Jy9Wj9FNXQMrz48RYloEdgPjCkE3z8X6Ch7HMAU,2656
9
- tests/test_mktestdocs.py,sha256=EegZRk2GRrsxAQW-TPQnXXbAogdNG0Eb5OZ0dabQtTU,235
10
- mktestdocs-0.2.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
11
- mktestdocs-0.2.0.dist-info/METADATA,sha256=oM6g1nrBC3KNILrI30eSzMmZCW0nnSXdYTG9VPyDav4,209
12
- mktestdocs-0.2.0.dist-info/WHEEL,sha256=z9j0xAa_JmUKMpmz72K0ZGALSM_n-wQVmGbleXx2VHg,110
13
- mktestdocs-0.2.0.dist-info/top_level.txt,sha256=Wh9mCrbRZsALS8VKzSi8ifKBj95gf-BHeWQCoTTNBKc,17
14
- mktestdocs-0.2.0.dist-info/RECORD,,
tests/__init__.py DELETED
File without changes
tests/conftest.py DELETED
@@ -1,12 +0,0 @@
1
- from copy import copy
2
-
3
- import pytest
4
-
5
- import mktestdocs
6
-
7
-
8
- @pytest.fixture
9
- def temp_executors():
10
- old_executors = copy(mktestdocs.__main__._executors)
11
- yield
12
- mktestdocs.__main__._executors = old_executors
@@ -1,60 +0,0 @@
1
- import pytest
2
- from mktestdocs import check_docstring
3
-
4
-
5
- def foobar_good(a, b):
6
- """
7
- Returns a + b.
8
-
9
- Examples:
10
-
11
- ```python
12
- import random
13
-
14
- random.random()
15
- assert 'a' + 'b' == 'ab'
16
- assert 1 + 2 == 3
17
- ```
18
- """
19
- return a + b
20
-
21
-
22
- def foobar_also_good(a, b):
23
- """
24
- Returns a + b.
25
-
26
- Examples:
27
-
28
- ```python
29
- import random
30
-
31
- assert random.random() < 10
32
- ```
33
- """
34
- return a + b
35
-
36
-
37
- def foobar_bad(a, b):
38
- """
39
- Returns a + b.
40
-
41
- Examples:
42
-
43
- ```python
44
- assert foobar(1, 2) == 4
45
- ```
46
- """
47
- return a + b
48
-
49
-
50
- @pytest.mark.parametrize("func", [foobar_good, foobar_also_good])
51
- def test_base_docstrings(func):
52
- check_docstring(func)
53
-
54
-
55
- @pytest.mark.parametrize("func", [foobar_bad])
56
- def test_base_docstrings_bad(func, capsys):
57
- with pytest.raises(Exception):
58
- check_docstring(func)
59
- capsys.readouterr()
60
- assert func.__name__ in capsys.readouterr().out
tests/test_class.py DELETED
@@ -1,73 +0,0 @@
1
- import pytest
2
-
3
- from mktestdocs import get_codeblock_members, check_docstring
4
-
5
-
6
- class Dinosaur:
7
- """
8
- This is a dino.
9
-
10
- ```python
11
- from dinosaur import Dinosaur
12
-
13
- assert Dinosaur().name == 'trex'
14
- ```
15
- """
16
-
17
- def __init__(self):
18
- self.name = "trex"
19
-
20
- @staticmethod
21
- def a(value):
22
- """
23
- Returns value
24
-
25
- Example:
26
-
27
- ```python
28
- from dinosaur import Dinosaur
29
-
30
- dino = Dinosaur()
31
- assert dino.a(1) == 1
32
- ```
33
- """
34
- return value
35
-
36
- @classmethod
37
- def b(cls, value):
38
- """
39
- Returns value
40
-
41
- Example:
42
-
43
- ```python
44
- from dinosaur import Dinosaur
45
- assert Dinosaur.b(1) == 1
46
- ```
47
- """
48
- return value
49
-
50
- def hello(self):
51
- """
52
- Returns value
53
-
54
- Example:
55
-
56
- ```python
57
- from dinosaur import Dinosaur
58
- assert Dinosaur().name == 'trex'
59
- ```
60
- """
61
- return self.name
62
-
63
-
64
- members = get_codeblock_members(Dinosaur)
65
-
66
-
67
- def test_grab_methods():
68
- assert len(get_codeblock_members(Dinosaur)) == 4
69
-
70
-
71
- @pytest.mark.parametrize("obj", members, ids=lambda d: d.__qualname__)
72
- def test_member(obj):
73
- check_docstring(obj)
tests/test_codeblock.py DELETED
@@ -1,56 +0,0 @@
1
- import pytest
2
-
3
- from mktestdocs import check_codeblock, grab_code_blocks
4
-
5
- exibit_a = """
6
- This is an example docstring.
7
-
8
- Arguments:
9
- a: a parameter
10
-
11
- There is no example
12
- """
13
-
14
- exibit_b = """
15
- This is an example docstring.
16
-
17
- Arguments:
18
- a: a parameter
19
-
20
- ```python
21
- assert 1 == 1
22
- ```
23
- """
24
-
25
- exibit_c = """
26
- This is an example docstring.
27
-
28
- Arguments:
29
- a: a parameter
30
-
31
- ```
32
- assert 1 == 1
33
- ```
34
-
35
- ```python
36
- assert 1 == 1
37
- ```
38
- """
39
-
40
-
41
- @pytest.mark.parametrize(
42
- "doc, n",
43
- [(exibit_a, 0), (exibit_b, 1), (exibit_c, 1)],
44
- ids=["exibit_a", "exibit_b", "exibit_c"],
45
- )
46
- def test_number_of_codeblocks(doc, n):
47
- assert len(grab_code_blocks(doc, lang="python")) == n
48
-
49
-
50
- @pytest.mark.parametrize(
51
- "doc, n",
52
- [(exibit_a, 0), (exibit_b, 1), (exibit_c, 2)],
53
- ids=["exibit_a", "exibit_b", "exibit_c"],
54
- )
55
- def test_number_of_codeblocks_any(doc, n):
56
- assert len(grab_code_blocks(doc, lang=None)) == n
tests/test_markdown.py DELETED
@@ -1,77 +0,0 @@
1
- import pathlib
2
- import pytest
3
- from shutil import which
4
- from unittest.mock import Mock
5
-
6
- from mktestdocs import check_md_file, register_executor
7
- from mktestdocs.__main__ import exec_bash
8
-
9
-
10
- @pytest.mark.parametrize("fpath", pathlib.Path("tests/data/good").glob("?.md"), ids=str)
11
- def test_files_good(fpath):
12
- check_md_file(fpath=fpath)
13
-
14
-
15
- def test_files_bad():
16
- fpath = pathlib.Path("tests") / "data" / "bad" / "a.md"
17
- with pytest.raises(Exception):
18
- check_md_file(fpath=fpath)
19
-
20
-
21
- def test_big_files_good():
22
- """Confirm that we can deal with multi-cell markdown cells."""
23
- check_md_file(fpath="tests/data/good/big-good.md", memory=True)
24
-
25
-
26
- def test_big_file_independant():
27
- """Confirm that different files don't influence each other."""
28
- check_md_file(fpath="tests/data/good/big-good.md", memory=True)
29
- with pytest.raises(Exception):
30
- check_md_file(fpath="tests/data/bad/big-bad.md", memory=True)
31
-
32
-
33
- @pytest.mark.skipif(which("bash") is None, reason="No bash shell available")
34
- @pytest.mark.parametrize("fpath", pathlib.Path("tests/data/good").glob("?.md"), ids=str)
35
- def test_files_good_bash(fpath):
36
- check_md_file(fpath=fpath, lang="bash")
37
-
38
-
39
- @pytest.mark.skipif(which("bash") is None, reason="No bash shell available")
40
- def test_files_bad_bash():
41
- fpath = pathlib.Path("tests") / "data" / "bad" / "b.md"
42
- with pytest.raises(Exception):
43
- check_md_file(fpath=fpath, lang="bash")
44
-
45
-
46
- @pytest.mark.skipif(which("bash") is None, reason="No bash shell available")
47
- def test_big_files_good_bash():
48
- fpath = pathlib.Path("tests") / "data" / "good" / "big-good.md"
49
- check_md_file(fpath=fpath, memory=True, lang="bash")
50
-
51
-
52
- @pytest.mark.skipif(which("bash") is None, reason="No bash shell available")
53
- def test_big_file_independant_bash():
54
- fdir = pathlib.Path("tests") / "data"
55
- check_md_file(fpath=fdir / "good" / "big-good.md", memory=True, lang="bash")
56
- with pytest.raises(Exception):
57
- check_md_file(fpath=fdir / "bad" / "big-bad.md", memory=True, lang="bash")
58
-
59
-
60
- def test_files_unmarked_language_default():
61
- fpath = pathlib.Path("tests") / "data" / "good" / "c.md"
62
- check_md_file(fpath, lang="")
63
-
64
-
65
- @pytest.mark.skipif(which("bash") is None, reason="No bash shell available")
66
- def test_files_unmarked_language_bash(temp_executors):
67
- fpath = pathlib.Path("tests") / "data" / "good" / "c.md"
68
- register_executor("", exec_bash)
69
- check_md_file(fpath, lang="")
70
-
71
-
72
- def test_override_executor(temp_executors):
73
- fpath = pathlib.Path("tests") / "data" / "good" / "a.md"
74
- hijack = Mock()
75
- register_executor("python", hijack)
76
- check_md_file(fpath, lang="python")
77
- hijack.assert_called()
tests/test_mktestdocs.py DELETED
@@ -1,10 +0,0 @@
1
- import pathlib
2
-
3
- from mktestdocs import check_md_file
4
-
5
- def test_readme(monkeypatch):
6
- test_dir = pathlib.Path(__file__).parent
7
- fpath = test_dir.parent / "README.md"
8
- monkeypatch.chdir(test_dir)
9
-
10
- check_md_file(fpath=fpath)