Skip to content

Commit

Permalink
Make rez-test tests cross-platform (AcademySoftwareFoundation#1851)
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Christophe Morin <[email protected]>
  • Loading branch information
JeanChristopheMorinPerso committed Oct 14, 2024
1 parent cc62703 commit 07abf44
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
15 changes: 13 additions & 2 deletions src/rez/data/tests/builds/packages/testing_obj/1.0.0/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,21 @@ def commands():
build_command = 'python {root}/build.py {install}'

tests = {
"command_as_string_success": {
"command": "exit 0"
},
"command_as_string_fail": {
"command": "exit 1"
},
"check_car_ideas": {
"command": "[[ -z ${CAR_IDEA} ]] && exit 1 || exit 0"
"command": ["python", "-c", "import os; assert os.environ.get('CAR_IDEA') == 'STURDY STEERING WHEEL'"],
"requires": ["python"]
},
"move_meeting_to_noon": {
"command": "[[ -z ${SKIP_LUNCH} ]] && exit 1 || exit 0"
# We want this test to fail. SKIP_LUNCH should not be set.
# TODO: We should not test for failures here. Testing failures, str vs lsit commands, etc
# should we tested separately.
"command": ["python", "-c", "import os; assert os.environ.get('SKIP_LUNCH') is not None"],
"requires": ["python"]
}
}
6 changes: 5 additions & 1 deletion src/rez/tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ def test_execute_command_testing_environ(self):
"""Test that execute_command properly sets test specific environ dict"""
self.inject_python_repo()
packages_path = self.data_path("builds", "packages")
r = ResolvedContext(["testing_obj", "python"], testing=True, package_paths=[packages_path] + self.settings["packages_path"])
r = ResolvedContext(
["testing_obj", "python"],
testing=True,
package_paths=[packages_path] + self.settings["packages_path"]
)
self.assertEqual(r.get_environ().get("CAR_IDEA"), "STURDY STEERING WHEEL")

def test_execute_command_environ(self):
Expand Down
38 changes: 30 additions & 8 deletions src/rez/tests/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,49 @@ def test_1(self):
context = ResolvedContext(["testing_obj", "python"])
self._run_tests(context)

def _run_tests(self, r):
def test_2(self):
"""package.py unit tests are correctly run in a testing environment when no verbosity is set"""
self.inject_python_repo()
context = ResolvedContext(["testing_obj", "python"])
# This will get us more code coverage :)
self._run_tests(context, verbose=0)

def _run_tests(self, r, verbose=2):
"""Run unit tests in package.py"""
self.inject_python_repo()
runner = PackageTestRunner(
package_request="testing_obj",
package_paths=r.package_paths,
stop_on_fail=False,
verbose=2
verbose=verbose
)

test_names = runner.get_test_names()

for test_name in test_names:
runner.run_test(test_name)

successful_test = self._get_test_result(runner, "check_car_ideas")
failed_test = self._get_test_result(runner, "move_meeting_to_noon")

self.assertEqual(runner.test_results.num_tests, 2)
self.assertEqual(successful_test["status"], "success")
self.assertEqual(failed_test["status"], "failed")
self.assertEqual(runner.test_results.num_tests, 4)
self.assertEqual(
self._get_test_result(runner, "check_car_ideas")["status"],
"success",
"check_car_ideas did not succeed",
)
self.assertEqual(
self._get_test_result(runner, "move_meeting_to_noon")["status"],
"failed",
"move_meeting_to_noon did not fail",
)
self.assertEqual(
self._get_test_result(runner, "command_as_string_success")["status"],
"success",
"command_as_string_success did not succeed",
)
self.assertEqual(
self._get_test_result(runner, "command_as_string_fail")["status"],
"failed",
"command_as_string_fail did not fail",
)

def _get_test_result(self, runner, test_name):
return next(
Expand Down

0 comments on commit 07abf44

Please sign in to comment.