forked from area4lib/area4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
161 lines (143 loc) · 6.13 KB
/
Copy pathtests.py
File metadata and controls
161 lines (143 loc) · 6.13 KB
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
151
152
153
154
155
156
157
158
159
160
161
"""Runs code tests in a CI environment."""
# Import needed modules
import unittest
import os
import restructuredtext_lint
from sys import platform
# Try to import area4.
# This will fail if it could not be installed or if faulty code is present.
try:
import area4
except ImportError:
# At this point, area4 either isn't in site-packages,
# or not on the system at all.
raise OSError("Failed to import the library.")
class Tests(unittest.TestCase):
"""The test class."""
def setUp(self):
"""Prepare for a test."""
# Get working directory:
self.working_directory = os.getenv("CIRRUS_WORKING_DIR")
# Fallback in case this is being run locally:
if self.working_directory is None:
self.working_directory = os.path.abspath(
os.path.dirname(__file__)
)
# Get divider text file:
self.dividers_file = "{0}/{1}".format(
self.working_directory,
"area4/dividers.txt"
)
with open(file=self.dividers_file, mode="r") as fh:
self.raw_dividers = fh.readlines()
def test_dividers(self):
"""Test dividers."""
try:
for i in range(len(self.raw_dividers)):
# Try to match the raw divider with the result
# of the function:
if i != 35 and i != 0 and i != 32:
self.assertEqual(
self.raw_dividers[i].replace("\n", ""),
area4.divider(i),
f"Divider number {i} was not the same in the file and in the code. Please ask a maintainer for help."
)
elif (i == 35 or i == 32) and i != 0:
self.assertNotEqual(
self.raw_dividers[i], area4.divider(i)
)
finally:
pass
def test_splitter_1(self):
"""Test splitter function."""
self.assertEqual(area4.splitter("---", "Hello"), "Hello")
def test_splitter_2(self):
"""Test splitter function."""
self.assertEqual(area4.splitter("---", "Hello", "world"), "Hello\n---\nworld\n---\n")
def test_splitter_3(self):
"""Test splitter function."""
self.assertEqual(area4.splitter(3, "Hello", "world"), "Hello\n............\n\nworld\n............\n\n")
def test_splitter_4(self):
"""Test splitter function."""
self.assertEqual(area4.splitter(45, "Hello", "world", "fine"), "Hello\neeeeeeeeeeee\n\nworld\neeeeeeeeeeee\n\nfine\neeeeeeeeeeee\n\n")
def test_splitter_5(self):
"""Test splitter function."""
self.assertEqual(area4.splitter("xyz", "Hello", "world"), "Hello\nxyz\nworld\nxyz\n")
def test_utilities(self):
"""Test util module."""
module = area4.util
self.assertEqual(module.get_divider_character(1), "-")
self.assertEqual(module.get_divider_character(2), "_")
self.assertEqual(module.get_divider_character(3), ".")
self.assertEqual(module.get_divider_character(7), "=")
self.assertEqual(module.get_divider_character(9), "*")
self.assertEqual(module.get_divider_character(13), "~")
self.assertNotEqual(module.get_divider_character(21), "¯\\_(ツ)_/¯")
self.assertEqual(module.get_divider_character(23), "2")
self.assertEqual(module.get_divider_character(24), "3")
self.assertEqual(module.get_divider_character(25), "4")
self.assertEqual(module.get_divider_character(26), "5")
self.assertEqual(module.get_divider_character(27), "6")
self.assertEqual(module.get_divider_character(28), "7")
self.assertEqual(module.get_divider_character(29), "8")
self.assertEqual(module.get_divider_character(30), "9")
self.assertEqual(module.get_divider_character(216), ";")
self.assertEqual(module.reddit_horizontal(), "*****")
self.assertEqual(module.markdown_horizontal(), "---")
@unittest.skip("Todo: remove found duplicate lines (breaking change!)")
def test_for_divider_duplicates(self):
"""Checks for any duplicate dividers."""
for x, z in enumerate(self.raw_dividers):
# foreach entry, check equality to the parent foreach's current index
for g, h in enumerate(self.raw_dividers):
if x == g:
# during enumeration, the divider will find itself
self.assertEqual(self.raw_dividers[x], self.raw_dividers[g])
else:
# but all the other times it will be another divider
# which can NOT be equal!
self.assertNotEqual(
self.raw_dividers[x],
self.raw_dividers[g],
f"Dividers {x} and {g} are the same! Duplicates are not allowed."
)
def test_info(self):
"""Test info."""
right_data = [
"area4",
"RDIL",
"me@rdil.rocks",
"Dividers in Python, the easy way!"
]
from_class = [
area4.name,
area4.__author__,
area4.author_email,
area4.description
]
for i, e in enumerate(right_data):
self.assertEqual(right_data[i], from_class[i])
self.assertEqual(
area4.area4info(),
"Name: {0}\nAuthor: {1}\nAuthor Email: {2}\nDescription: {3}".format(
right_data[0],
right_data[1],
right_data[2],
right_data[3],
)
)
@unittest.skipIf(platform.startswith("win"), "better supported on Linux/macOS")
def test_restructuredtext(self):
"""Lint RST files."""
files = os.listdir("{0}/docs".format(self.working_directory))
for name in files:
path = "{0}/docs/{1}".format(self.working_directory, name)
restructuredtext_lint.lint_file(filepath=path)
def test_make_div(self):
"""Test make_div."""
self.assertEqual(
area4.make_div('=-', length=9, start='<', end='=>'),
"<=-=-=-=>"
)
if __name__ == '__main__':
unittest.main()