-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_run.py
More file actions
109 lines (78 loc) · 3.46 KB
/
test_run.py
File metadata and controls
109 lines (78 loc) · 3.46 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
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
import pytest
import io
import os.path
import subprocess
import sys
import appenv
def test_bootstrap_lockfile_existing_venv_broken_python():
pass
def test_bootstrap_lockfile_missing_dependency():
pass
def test_bootstrap_and_run_with_lockfile(workdir, monkeypatch):
monkeypatch.setattr("sys.stdin", io.StringIO("ducker\nducker==2.0.1\n\n"))
env = appenv.AppEnv(os.path.join(workdir, 'ducker'), os.getcwd())
env.init()
env.update_lockfile()
os.chdir(os.path.join(workdir, "ducker"))
with open("ducker", "r") as f:
# Ensure we're called with the Python-interpreter-under-test.
script = "#!{}\n{}".format(sys.executable, f.read())
with open("ducker", "w") as f:
f.write(script)
output = subprocess.check_output("./ducker --help", shell=True)
assert output.startswith(b"usage: Ducker")
def test_bootstrap_and_run_python_with_lockfile(workdir, monkeypatch):
monkeypatch.setattr("sys.stdin", io.StringIO("ducker\nducker==2.0.1\n\n"))
env = appenv.AppEnv(os.path.join(workdir, 'ducker'), os.getcwd())
env.init()
env.update_lockfile()
os.chdir(os.path.join(workdir, "ducker"))
with open("ducker", "r") as f:
# Ensure we're called with the Python-interpreter-under-test.
script = "#!{}\n{}".format(sys.executable, f.read())
with open("ducker", "w") as f:
f.write(script)
output = subprocess.check_output(
'./appenv python -c "print(1)"', shell=True)
assert output == b"1\n"
def test_bootstrap_and_run_without_lockfile(workdir, monkeypatch):
"""It raises as error if no requirements.txt is present."""
monkeypatch.setattr("sys.stdin", io.StringIO("ducker\nducker==2.0.1\n\n"))
env = appenv.AppEnv(os.path.join(workdir, 'ducker'), os.getcwd())
env.init()
os.chdir(os.path.join(workdir, "ducker"))
with open("ducker", "r") as f:
# Ensure we're called with the Python-interpreter-under-test.
script = "#!{}\n{}".format(sys.executable, f.read())
with open("ducker", "w") as f:
f.write(script)
with pytest.raises(subprocess.CalledProcessError) as err:
subprocess.check_output(["./ducker", "--help"])
assert err.value.output == (b"No requirements.txt found. Generate it using"
b" ./appenv update-lockfile\n")
def test_bootstrap_and_run_with_outdated_lockfile(workdir, monkeypatch):
monkeypatch.setattr("sys.stdin", io.StringIO("ducker\nducker==2.0.1\n\n"))
env = appenv.AppEnv(os.path.join(workdir, 'ducker'), os.getcwd())
env.init()
env.update_lockfile()
os.chdir(os.path.join(workdir, "ducker"))
with open("ducker", "r") as f:
# Ensure we're called with the Python-interpreter-under-test.
script = "#!{}\n{}".format(sys.executable, f.read())
with open("ducker", "w") as f:
f.write(script)
output = subprocess.check_output(
'./appenv python -c "print(1)"', shell=True)
assert output == b"1\n"
with open("requirements.in", 'w') as f:
f.write('ducker==2.0.1')
s = subprocess.Popen(
'./appenv python -c "print(1)"', shell=True, stdout=subprocess.PIPE)
stdout, stderr = s.communicate()
assert stdout == b"""\
requirements.in seems out of date (hash mismatch). Regenerate using ./appenv update-lockfile
""" # noqa
subprocess.check_call('./appenv update-lockfile', shell=True)
output = subprocess.check_output(
'./appenv python -c "print(1)"', shell=True)
assert output == b"1\n"