-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
125 lines (98 loc) · 3.61 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import pytest
from main import (
get_format_by_code,
chain_research_urls,
Editor,
InputValidator,
UserInputError,
AllUrlsSkippedPages,
)
@pytest.fixture
def validator():
return InputValidator()
@pytest.fixture
def editor():
return Editor()
class TestChain:
def test_chain(self):
assert chain_research_urls(
[
["url1", "url2"],
["url3", "url4"],
["url5", "url6"],
"skipped_url",
]
) == AllUrlsSkippedPages(
all_urls=["url1", "url2", "url3", "url4", "url5", "url6"],
skipped_pages=[
"skipped_url",
],
)
def test_chain_skipped_urls_only(self):
assert chain_research_urls(
[[], [], [], "skipped_url1", "skipped_url2", "skipped_url3"]
) == AllUrlsSkippedPages(
all_urls=[], skipped_pages=["skipped_url1", "skipped_url2", "skipped_url3"]
)
class TestInputValidation:
def test_wrong_url(self, validator):
with pytest.raises(ValueError):
validator.url("wrong url")
def test_correct_url(self, validator):
assert validator.url("https://pubmed.ncbi.nlm.nih.gov/?term=test+url")
def test_incorrect_filename(self, validator):
with pytest.raises(ValueError):
validator.filename("\n\t\n")
def test_empty_filename(self, validator):
with pytest.raises(ValueError):
validator.filename("")
def test_correct_filname(self, validator):
assert validator.filename("correct name")
def test_incorrect_pages_amount(self, validator):
with pytest.raises(ValueError):
validator.pages_amount(10_000)
with pytest.raises(ValueError):
validator.pages_amount(-1)
def test_pages_amount(self, validator):
assert validator.pages_amount(77)
def test_get_format_by_code(self):
assert get_format_by_code("1")
def test_get_format_by_empty_code(self):
assert get_format_by_code("") == ".md"
def test_get_format_by_wrong_code(self):
with pytest.raises(UserInputError):
get_format_by_code("12453531632958285")
class TestEditor:
def test_clean_abstract(self, editor):
test_abstract = [
"fdsj fdj fdjjf d \t\t",
]
assert editor.clean_abstract(test_abstract) == "fdsj fdj fdjjf d \n\n"
def test_clean_abstract_with_paragraphs(self, editor):
test_abstract = ["fdsg ", "fds dfd", " ddfff"]
assert editor.clean_abstract(test_abstract) == "fdsg \n\nfds dfd\n\n ddfff\n\n"
def test_format_research_md(self, editor):
assert (
editor.format_research(
title="test title",
url="https://test.com",
cleaned_abstract="this is cleaned abstract",
file_format=".md",
)
== "## **test title**\n*https://test.com*<br>this is cleaned abstract\n"
)
def test_format_research_txt(self, editor):
editor.format_research(
title="test title",
url="https://test.com",
cleaned_abstract="this is cleaned abstract",
file_format=".txt",
) == "test title\n\nhttps://test.com\n\nthis is cleaned abstract\n\n\n"
def test_format_research_wrong_type(self, editor):
with pytest.raises(ValueError):
editor.format_research(
title="test title",
url="https://test.com",
cleaned_abstract="this is cleaned abstract",
file_format=".wrong_format",
)