-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtext_test.py
57 lines (50 loc) · 2.23 KB
/
text_test.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
import os
import shutil
import pytest
from fast_ssg.utils import determine_path
from fast_ssg.text import OUTPUT_DIR, TextFile
class TestText:
def test_get_fullpath(self):
parsed_arg_obj = {"input": "./tests/test_files/test_file.md"}
path_obj = determine_path(parsed_arg_obj)
full_path = TextFile(path_obj["file_path"], path_obj["dir_path"]).get_path()
assert full_path == os.path.join(path_obj["dir_path"], path_obj["file_path"])
def test_read_file(self):
parsed_arg_obj = {"input": "./tests/test_files/test_file.md"}
path_obj = determine_path(parsed_arg_obj)
text_obj = TextFile(path_obj["file_path"], path_obj["dir_path"])
# Open file
file = open(text_obj.get_path(), mode="r", encoding="utf8")
# Read the contents
content = file.read()
assert (
content == text_obj.read_file()
), "Content from read_file() func should be the same as reading file directly"
def test_genetate_html(self):
# Create Dir path
dir_path = os.path.join(os.getcwd(), OUTPUT_DIR)
if os.path.isdir(dir_path):
shutil.rmtree(dir_path)
os.mkdir(dir_path)
# Create Text obj
parsed_arg_obj = {"input": "./tests/test_files/test_file.md"}
path_obj = determine_path(parsed_arg_obj)
text_obj = TextFile(path_obj["file_path"], path_obj["dir_path"])
text_obj.generate_html()
assert os.path.isfile(
dir_path + "/test_file.html"
), "HTML file should exist in OUTPUT directory"
def test_process_file_invalid_file(self):
parsed_arg_obj = {"input": "./tests/test_files/test_unsupported_type.epub"}
path_obj = determine_path(parsed_arg_obj)
text_obj = TextFile(path_obj["file_path"], path_obj["dir_path"])
# Should throw error
with pytest.raises(Exception):
text_obj.process_file()
def test_process_empty_file(self):
parsed_arg_obj = {"input": "./tests/test_files/test_empty_file.txt"}
path_obj = determine_path(parsed_arg_obj)
text_obj = TextFile(path_obj["file_path"], path_obj["dir_path"])
# Should throw error
with pytest.raises(Exception):
text_obj.process_file()