-
Notifications
You must be signed in to change notification settings - Fork 650
/
test_clean.py
115 lines (80 loc) · 2.91 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
"""Testing clean functionality of the CLI."""
from pathlib import Path
from subprocess import run, PIPE
import pytest
import os
path_tests = Path(__file__).parent.resolve()
path_books = path_tests.joinpath("books")
path_root = path_tests.parent
def test_clean_book(tmpdir):
path = path_books.joinpath("clean_cache")
build_path = path.joinpath("_build")
run(f"jb build {path}".split())
# Ensure _build exists
assert build_path.exists()
# Ensure _build/.jupyter_cache exists
assert build_path.joinpath(".jupyter_cache").exists()
# Empty _build except .jupyter_cache
run(f"jb clean {path}".split())
# Ensure _build and .jupyter_cache exist
assert build_path.exists()
assert build_path.joinpath(".jupyter_cache").exists()
run(f"jb clean --all {path}".split())
# Ensure _build is removed
assert not path.joinpath("_build").exists()
# === Excepted errors ===
# Non-existent folder
with pytest.raises(ValueError):
out = run("jb clean doesnt/exist".split(), stderr=PIPE)
err = out.stderr.decode()
if "ValueError" in err:
raise ValueError(err)
assert "Path to book isn't a directory" in err
def test_clean_html(tmpdir):
path = path_books.joinpath("clean_cache")
build_path = path.joinpath("_build")
run(f"jb build {path}".split())
# Ensure _build exists
assert build_path.exists()
# Ensure _build/html exists
assert build_path.joinpath("html").exists()
# Remove html
run(f"jb clean --html {path}".split())
# Ensure _build exists
assert build_path.exists()
# Ensure html is removed
assert not build_path.joinpath("html").exists()
def test_clean_latex(tmpdir):
path = path_books.joinpath("clean_cache")
run(f"jb build {path}".split())
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
run(f"jb clean --latex {path}".split())
# Ensure _build exists
assert build_path.exists()
# Ensure latex is removed
assert not build_path.joinpath("latex").exists()
def test_clean_html_latex(tmpdir):
path = path_books.joinpath("clean_cache")
run(f"jb build {path}".split())
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
run(f"jb clean --html --latex {path}".split())
# 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()