Skip to content

Commit d0d4773

Browse files
Make rez-test tests cross-platform
Signed-off-by: Jean-Christophe Morin <[email protected]>
1 parent cc62703 commit d0d4773

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

src/rez/data/tests/builds/packages/testing_obj/1.0.0/package.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,21 @@ def commands():
2222
build_command = 'python {root}/build.py {install}'
2323

2424
tests = {
25+
"command_as_string_success": {
26+
"command": "exit 0"
27+
},
28+
"command_as_string_fail": {
29+
"command": "exit 1"
30+
},
2531
"check_car_ideas": {
26-
"command": "[[ -z ${CAR_IDEA} ]] && exit 1 || exit 0"
32+
"command": ["python", "-c", "import os; assert os.environ.get('CAR_IDEA') == 'STURDY STEERING WHEEL'"],
33+
"requires": ["python"]
2734
},
2835
"move_meeting_to_noon": {
29-
"command": "[[ -z ${SKIP_LUNCH} ]] && exit 1 || exit 0"
36+
# We want this test to fail. SKIP_LUNCH should not be set.
37+
# TODO: We should not test for failures here. Testing failures, str vs lsit commands, etc
38+
# should we tested separately.
39+
"command": ["python", "-c", "import os; assert os.environ.get('SKIP_LUNCH') is not None"],
40+
"requires": ["python"]
3041
}
3142
}

src/rez/tests/test_context.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ def test_execute_command_testing_environ(self):
8484
"""Test that execute_command properly sets test specific environ dict"""
8585
self.inject_python_repo()
8686
packages_path = self.data_path("builds", "packages")
87-
r = ResolvedContext(["testing_obj", "python"], testing=True, package_paths=[packages_path] + self.settings["packages_path"])
87+
r = ResolvedContext(
88+
["testing_obj", "python"],
89+
testing=True,
90+
package_paths=[packages_path] + self.settings["packages_path"]
91+
)
8892
self.assertEqual(r.get_environ().get("CAR_IDEA"), "STURDY STEERING WHEEL")
8993

9094
def test_execute_command_environ(self):

src/rez/tests/test_test.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,49 @@ def test_1(self):
3434
context = ResolvedContext(["testing_obj", "python"])
3535
self._run_tests(context)
3636

37-
def _run_tests(self, r):
37+
def test_2(self):
38+
"""package.py unit tests are correctly run in a testing environment when no verbosity is set"""
39+
self.inject_python_repo()
40+
context = ResolvedContext(["testing_obj", "python"])
41+
# This will get us more code coverage :)
42+
self._run_tests(context, verbose=0)
43+
44+
def _run_tests(self, r, verbose=2):
3845
"""Run unit tests in package.py"""
3946
self.inject_python_repo()
4047
runner = PackageTestRunner(
4148
package_request="testing_obj",
4249
package_paths=r.package_paths,
4350
stop_on_fail=False,
44-
verbose=2
51+
verbose=verbose
4552
)
4653

4754
test_names = runner.get_test_names()
4855

4956
for test_name in test_names:
5057
runner.run_test(test_name)
5158

52-
successful_test = self._get_test_result(runner, "check_car_ideas")
53-
failed_test = self._get_test_result(runner, "move_meeting_to_noon")
54-
55-
self.assertEqual(runner.test_results.num_tests, 2)
56-
self.assertEqual(successful_test["status"], "success")
57-
self.assertEqual(failed_test["status"], "failed")
59+
self.assertEqual(runner.test_results.num_tests, 4)
60+
self.assertEqual(
61+
self._get_test_result(runner, "check_car_ideas")["status"],
62+
"success",
63+
"check_car_ideas did not succeed",
64+
)
65+
self.assertEqual(
66+
self._get_test_result(runner, "move_meeting_to_noon")["status"],
67+
"failed",
68+
"move_meeting_to_noon did not fail",
69+
)
70+
self.assertEqual(
71+
self._get_test_result(runner, "command_as_string_success")["status"],
72+
"success",
73+
"command_as_string_success did not succeed",
74+
)
75+
self.assertEqual(
76+
self._get_test_result(runner, "command_as_string_fail")["status"],
77+
"failed",
78+
"command_as_string_fail did not fail",
79+
)
5880

5981
def _get_test_result(self, runner, test_name):
6082
return next(

0 commit comments

Comments
 (0)