/
test_clean.py
121 lines (87 loc) · 3.35 KB
/
test_clean.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
"""Testing clean functionality of the CLI."""
import os
from click.testing import CliRunner
from jupyter_book.commands import build, clean
def test_clean_book(cli: CliRunner, build_resources):
books, tocs = build_resources
path = books.joinpath("clean_cache")
build_path = path.joinpath("_build")
result = cli.invoke(build, path.as_posix())
assert result.exit_code == 0
# Ensure _build exists
assert build_path.exists()
# Ensure _build/.jupyter_cache exists
assert build_path.joinpath(".jupyter_cache").exists()
# Empty _build except .jupyter_cache
result = cli.invoke(clean, path.as_posix())
assert result.exit_code == 0
# Ensure _build and .jupyter_cache exist
assert build_path.exists()
assert build_path.joinpath(".jupyter_cache").exists()
result = cli.invoke(clean, ("--all", path.as_posix()))
assert result.exit_code == 0
# Ensure _build is removed
assert not path.joinpath("_build").exists()
# === Excepted errors ===
# Non-existent folder
result = cli.invoke(clean, "doesnt/exist")
assert result.exit_code != 0
assert isinstance(result.exception, RuntimeError)
assert "Path to book isn't a directory" in str(result.exception)
def test_clean_html(cli, build_resources):
books, tocs = build_resources
path = books.joinpath("clean_cache")
build_path = path.joinpath("_build")
result = cli.invoke(build, path.as_posix())
assert result.exit_code == 0
# Ensure _build exists
assert build_path.exists()
# Ensure _build/html exists
assert build_path.joinpath("html").exists()
# Remove html
result = cli.invoke(clean, ("--html", path.as_posix()))
assert result.exit_code == 0
# Ensure _build exists
assert build_path.exists()
# Ensure html is removed
assert not build_path.joinpath("html").exists()
def test_clean_latex(cli, build_resources):
books, tocs = build_resources
path = books.joinpath("clean_cache")
result = cli.invoke(build, path.as_posix())
assert result.exit_code == 0
build_path = path.joinpath("_build")
# Ensure _build exists
assert build_path.exists()
os.mkdir(os.path.join(build_path, "latex"))
# Ensure _build/html exists
assert build_path.joinpath("latex").exists()
# Remove html
result = cli.invoke(clean, ("--latex", path.as_posix()))
assert result.exit_code == 0
# Ensure _build exists
assert build_path.exists()
# Ensure latex is removed
assert not build_path.joinpath("latex").exists()
def test_clean_html_latex(cli, build_resources):
books, tocs = build_resources
path = books.joinpath("clean_cache")
result = cli.invoke(build, path.as_posix())
assert result.exit_code == 0
build_path = path.joinpath("_build")
# Ensure _build exists
assert build_path.exists()
os.mkdir(os.path.join(build_path, "latex"))
# Ensure _build/html exists
assert build_path.joinpath("latex").exists()
# Ensure _build/html exists
assert build_path.joinpath("html").exists()
# Remove html
result = cli.invoke(clean, ("--html", "--latex", path.as_posix()))
assert result.exit_code == 0
# Ensure _build exists
assert build_path.exists()
# Ensure latex is removed
assert not build_path.joinpath("latex").exists()
# Ensure html is removed
assert not build_path.joinpath("html").exists()