forked from pushingkarmaorg/python-plexapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_misc.py
More file actions
64 lines (55 loc) · 1.93 KB
/
test_misc.py
File metadata and controls
64 lines (55 loc) · 1.93 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
import shlex
import subprocess
from os.path import abspath, dirname, join
SKIP_EXAMPLES = ["Example 4"]
def test_build_documentation():
docroot = join(dirname(dirname(abspath(__file__))), "docs")
cmd = shlex.split("sphinx-build -aE . _build")
proc = subprocess.Popen(
cmd, cwd=docroot, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
status = proc.wait()
assert status == 0
issues = []
for output in proc.communicate():
for line in str(output).split("\\n"):
line = line.lower().strip()
if "warning" in line or "error" in line or "traceback" in line:
issues.append(line)
for line in issues:
print(line)
assert not issues
def test_readme_examples(plex):
failed = 0
examples = _fetch_examples()
assert len(examples), "No examples found in README"
for title, example in examples:
if _check_run_example(title):
try:
print(f"\n{title}\n{'-' * len(title)}")
exec("\n".join(example))
except Exception as err:
failed += 1
print(f"Error running test: {title}\nError: {err}")
assert not failed, f"{failed} examples raised an exception."
def _fetch_examples():
parsing = False
examples = []
filepath = join(dirname(dirname(abspath(__file__))), "README.rst")
with open(filepath, "r") as handle:
for line in handle.read().split("\n"):
line = line[4:]
if line.startswith("# Example "):
parsing = True
title = line.lstrip("# ")
examples.append([title, []])
elif parsing and line == "":
parsing = False
elif parsing:
examples[-1][1].append(line)
return examples
def _check_run_example(title):
for skip_example in SKIP_EXAMPLES:
if skip_example in title:
return False
return True