-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconftest.py
150 lines (130 loc) · 4.46 KB
/
conftest.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# pylint: disable=line-too-long
"""Module contains fixtures, helper functions, global variables for pytest"""
import os
import pytest
class Helpers:
"""Defines helper functions"""
@staticmethod
def new_file(directory, file_name, file_contents):
"""Creates new file and returns the path"""
# Create temporary input txt file
file_path = directory.join(file_name)
# Write contents to file
with open(str(file_path), mode="w", encoding="utf-8") as file:
file.write(file_contents)
return str(file_path)
@staticmethod
def file_contents(file_path):
"""Returns file contents"""
with open(str(file_path), "r", encoding="utf-8") as file:
return file.read()
# Global variables
def pytest_configure():
"""Defines pytest global variables"""
pytest.simple_txt_contents = 'Hello\n'
pytest.simple_md_contents = 'Hello\n' \
'---\n' \
'**Bold**\n' \
'*Italics*\n'
pytest.simple_md_with_code_contents = 'Hello\n' \
'**Bold**\n' \
'__Another Bold__\n' \
'`some code`\n' \
'```\n' \
'some multiline code\n' \
'```\n'
pytest.frontmatter_md_contents = '---\n' \
'title: My First Blog\n' \
'lang: en\n' \
'description: This is my first ever blog about programming.\n' \
'keywords: website, coding\n' \
'---\n' \
'\n' \
'content\n'
pytest.simple_html_from_txt = '<!doctype html>\n' \
'<html lang="en">\n' \
'<head>\n' \
'\t<meta charset="utf-8">\n' \
'\t<title>test</title>\n' \
'\t<meta name="viewport" content="width=device-width, initial-scale=1" />\n' \
'</head>\n' \
'<body>\n' \
'<p>Hello</p>\n' \
'</body>\n' \
'</html>'
pytest.simple_html_with_stylesheet = '<!doctype html>\n' \
'<html lang="en">\n' \
'<head>\n' \
'\t<meta charset="utf-8">\n' \
'\t<title>test</title>\n' \
'\t<meta name="viewport" content="width=device-width, initial-scale=1" />\n' \
'\t<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tufte-css/1.8.0/tufte.min.css">\n' \
'</head>\n' \
'<body>\n' \
'<p>Hello</p>\n' \
'</body>\n' \
'</html>'
pytest.simple_html_from_md = '<!doctype html>\n' \
'<html lang="en">\n' \
'<head>\n' \
'\t<meta charset="utf-8">\n' \
'\t<title>markdown</title>\n' \
'\t<meta name="viewport" content="width=device-width, initial-scale=1" />\n' \
'</head>\n' \
'<body>\n' \
'<p>Hello</p>\n' \
'<p><hr /></p>\n' \
'<p><strong>Bold</strong></p>\n' \
'<p>*Italics*</p>\n' \
'</body>\n' \
'</html>'
pytest.simple_html_with_code_from_md = '<!doctype html>\n' \
'<html lang="en">\n' \
'<head>\n' \
'\t<meta charset="utf-8">\n' \
'\t<title>markdownWithCode</title>\n' \
'\t<meta name="viewport" content="width=device-width, initial-scale=1" />\n' \
'</head>\n' \
'<body>\n' \
'<p>Hello</p>\n' \
'<p><strong>Bold</strong></p>\n' \
'<p><strong>Another Bold</strong></p>\n' \
'<p><code>some code</code></p>\n' \
'<pre>\n' \
'some multiline code\n' \
'</pre>\n' \
'</body>\n' \
'</html>'
pytest.html_from_frontmatter_md = '<!doctype html>\n' \
'<html lang="en">\n' \
'<head>\n' \
'\t<meta charset="utf-8">\n' \
'\t<title>My First Blog</title>\n' \
'\t<meta name="keywords" content="website, coding" />\n' \
'\t<meta name="description" content="This is my first ever blog about programming." />\n' \
'\t<meta name="viewport" content="width=device-width, initial-scale=1" />\n' \
'</head>\n' \
'<body>\n' \
'<p>content</p>\n' \
'</body>\n' \
'</html>'
@pytest.fixture
def cleanup_cwd():
"""Cleanup code to revert the CWD back to original value"""
# Startup code
old_cwd = os.getcwd() # Save the old CWD
yield
# Cleanup code
os.chdir(old_cwd) # Change CWD back
@pytest.fixture
def cleanup_output(request):
"""Cleanup code to remove output file"""
yield
# Cleanup code
for file_path in request.param:
if os.path.exists(file_path):
os.remove(file_path)
@pytest.fixture
def helpers():
"""Returns helper class"""
return Helpers