Debian Codegraph @

tests/test_parsing/test_docstrings.py

raw
1 """Check the docstring parsing."""
2 import io
3
4 from fades import parsing, REPO_PYPI, REPO_VCS
5
6 from tests import get_reqs
7
8
9 def test_empty():
10 parsed = parsing._parse_docstring(
11 io.StringIO("""
12
13 """)
14 )
15 assert parsed == {}
16
17
18 def test_only_comment():
19 with open("tests/test_files/no_req.py") as f:
20 parsed = parsing._parse_docstring(f)
21 assert parsed == {}
22
23
24 def test_req_in_module_docstring_triple_doublequoute():
25 with open("tests/test_files/req_module.py") as f:
26 parsed = parsing._parse_docstring(f)
27 assert parsed == {REPO_PYPI: get_reqs("foo", "bar")}
28
29
30 def test_req_in_module_docstring_triple_singlequote():
31 with open("tests/test_files/req_module_2.py") as f:
32 parsed = parsing._parse_docstring(f)
33 assert parsed == {REPO_PYPI: get_reqs("foo", "bar")}
34
35
36 def test_req_in_module_docstring_one_doublequote():
37 with open("tests/test_files/req_module_3.py") as f:
38 parsed = parsing._parse_docstring(f)
39 assert parsed == {}
40
41
42 def test_req_in_class_docstring():
43 with open("tests/test_files/req_class.py") as f:
44 parsed = parsing._parse_docstring(f)
45 # no requirements found
46 assert parsed == {}
47
48
49 def test_req_in_def_docstring():
50 with open("tests/test_files/req_def.py") as f:
51 parsed = parsing._parse_docstring(f)
52 # no requirements found
53 assert parsed == {}
54
55
56 def test_req_in_multi_docstring():
57 with open("tests/test_files/req_all.py") as f:
58 parsed = parsing._parse_docstring(f)
59 # Only module requirements was found
60 assert parsed == {REPO_PYPI: get_reqs("foo==1.4")}
61
62
63 def test_fades_word_as_part_of_text():
64 with open("tests/test_files/fades_as_part_of_other_word.py") as f:
65 parsed = parsing._parse_docstring(f)
66 assert parsed == {}
67
68
69 def test_mixed_backends():
70 with open("tests/test_files/req_mixed_backends.py") as f:
71 parsed = parsing._parse_docstring(f)
72 # Only module requirements was found
73 assert parsed == {
74 REPO_PYPI: get_reqs("foo", "bar"),
75 REPO_VCS: [
76 parsing.VCSDependency("git+http://whatever"),
77 parsing.VCSDependency("anotherurl"),
78 ],
79 }