forked from textext/textext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_installation_script.py
118 lines (93 loc) · 3.97 KB
/
test_installation_script.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
"""
This file is part of TexText, an extension for the vector
illustration program Inkscape.
Copyright (c) 2006-2022 TexText developers.
TexText is released under the 3-Clause BSD license. See
file LICENSE.txt or go to https://github.com/textext/textext
for full license details.
This script creates fake executables (pdflatex, python2.7, etc...)
to test requirements check in setup.py
All fake executables are created in temporary directory and safely
deleted at the end.
setup.py is running with PATH set to temporary directory, so
actual environment does not affect this test
"""
import os
import shutil
import sys
import subprocess
import tempfile
class TempDirectory(object):
def __init__(self):
self.name = None
def __enter__(self):
self.name = tempfile.mkdtemp()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
if self.name is not None:
shutil.rmtree(self.name)
class FakeExecutablesMaker(object):
def __init__(self, dirname):
assert os.path.isdir(dirname)
self.dirname = dirname
def __call__(self, name, output="", channel='stdout'):
assert channel in ["stdout", "stderr"]
command_name = os.path.join(self.dirname, name)
with open(command_name, "w") as fout:
fout.write("#!%s\n" % sys.executable)
fout.write("from __future__ import print_function\n")
fout.write("import sys\n")
fout.write("print(%s, file=sys.%s)" % (repr(output), channel))
os.chmod(command_name, 0o755)
def test_configuration(fake_commands, expected_exit_code):
with TempDirectory() as f:
env = dict(os.environ, PATH=f.name)
make_fake_executable = FakeExecutablesMaker(f.name)
for args in fake_commands:
make_fake_executable(*args)
ret_code = subprocess.call([sys.executable,
'setup.py',
"--skip-extension-install"],
env=env
)
assert ret_code == expected_exit_code, '%d != %d' % (ret_code, expected_exit_code)
print("\033[92m ====> Test %s successfully with expected exit code %d passed!\033[0m\n" % (
fake_commands, expected_exit_code))
REQUIREMENT_CHECK_SUCCESS = 0
REQUIREMENT_CHECK_UNKNOWN = 64
REQUIREMENT_CHECK_ERROR = 65
good_configurations = []
# Definition of working combinations of Inkscape and LaTeX
for latex in [("pdflatex",), ("lualatex",), ("xelatex",)]:
good_configurations.append([("inkscape", "Inkscape 1.0 (4035a4fb49, 2020-05-01)"), latex])
good_configurations.append([("inkscape", "Inkscape 1.1.1 (3bf5ae0d25, 2021-09-20)"), latex])
good_configurations.append([("inkscape", "Inkscape 1.2-dev (1dd7bebcbd, 2021-12-20)"), latex])
# Test: Installation of working combinations must succeed
for good_configuration in good_configurations:
test_configuration(good_configuration, REQUIREMENT_CHECK_SUCCESS)
# Test: If one component of the working combinations is missing
# installation must fail
for good_configuration in good_configurations:
for i in range(len(good_configuration)):
# good configuration without one element is bad
bad_configuration = good_configuration[:i] + good_configuration[i + 1:]
print(bad_configuration)
test_configuration(bad_configuration, REQUIREMENT_CHECK_ERROR)
# Test wrong Inkscape version and no pdflatex installed
test_configuration([
("inkscape", "Inkscape 0.92.3 (2405546, 2018-03-11)"),
], REQUIREMENT_CHECK_ERROR)
# Test wrong Inkscape version and pdflatex installed
test_configuration([
("inkscape", "Inkscape 0.92.3 (2405546, 2018-03-11)"),
("pdflatex",)
], REQUIREMENT_CHECK_ERROR)
# Test what's happening when no version information
# is returned by Inkscape
test_configuration([
("inkscape",),
("pdflatex",),
], REQUIREMENT_CHECK_UNKNOWN)
# Test: Nothing is installed -> Installation must fail
test_configuration([
], REQUIREMENT_CHECK_ERROR)