forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_runfiles_subprocess_test.py
60 lines (54 loc) · 2.62 KB
/
find_runfiles_subprocess_test.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
import os
import subprocess
import unittest
class TestFindRunfilesSubprocess(unittest.TestCase):
def _check_output(self, env=os.environ):
try:
output = subprocess.check_output([
"common/find_runfiles_test", "-spdlog_level=trace",
"--gtest_filter=FindRunfilesTest.AcceptanceTest",
], stderr=subprocess.STDOUT, env=env)
return output.decode("utf-8")
except subprocess.CalledProcessError as e:
e.output = e.output.decode("utf-8")
print(e.output)
raise
def test_basic_child_process(self):
# Check that a C++ program that uses FindRunfiles succeeds when called
# from a python binary.
output = self._check_output()
# Check that the C++ program used the resource paths we wanted it to:
# - It used the special-case TEST_SRCDIR mechanism.
self.assertIn("FindRunfile mechanism = TEST_SRCDIR", output)
# - It used find_runfiles_subprocess_test not find_runfiles_test, i.e.,
# the runfiles of the parent process were imbued to the subprocess.
self.assertIn("find_runfiles_subprocess_test.runfile", output)
self.assertNotIn("find_runfiles_test.runfile", output)
def test_sans_test_srcdir(self):
# Repeat test_basic_child_subprocess but with TEST_SRCDIR unset.
# from a python binary.
new_env = dict(os.environ)
del new_env["TEST_SRCDIR"]
output = self._check_output(env=new_env)
self.assertIn("FindRunfile mechanism = RUNFILES_{MANIFEST", output)
self.assertIn("find_runfiles_subprocess_test.runfile", output)
self.assertNotIn("find_runfiles_test.runfile", output)
def test_sans_all_env(self):
# Repeat test_basic_child_subprocess but with an empty environment.
# This covers the "argv0 mechanism" codepaths.
try:
output = self._check_output(env={})
status = 0
except subprocess.CalledProcessError as e:
output = e.output
status = e.returncode
# If the user-facing binary bazel-bin/common/find_runfiles_test happens
# to already exist then the subprocess's AcceptanceTest case passes.
#
# If instead only bazel-out/k8-opt/bin/common/find_runfiles_test exists
# (and it will always exist, because it is a data dependency of this
# python test), then the the subprocess's AcceptanceTest case fails.
#
# Either way, should report that its using argv0 and not segfault.
self.assertIn("FindRunfile mechanism = argv0", output)
self.assertIn(status, (0, 1))