forked from AcademySoftwareFoundation/rez
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing "testing" object (AcademySoftwareFoundation#1740)
* Introducing 'testing' object Signed-off-by: Fabrice Macagno <[email protected]> Signed-off-by: Nathan Cheung <[email protected]> Co-authored-by: Jean-Christophe Morin <[email protected]> Co-authored-by: Nathan Cheung <[email protected]>
- Loading branch information
1 parent
84c827d
commit cc62703
Showing
11 changed files
with
163 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/rez/data/tests/builds/packages/testing_obj/1.0.0/build.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from build_util import build_directory_recurse | ||
import os.path | ||
|
||
|
||
def build(source_path, build_path, install_path, targets): | ||
|
||
if "install" not in (targets or []): | ||
install_path = None | ||
|
||
build_directory_recurse(src_dir="testing_obj", | ||
dest_dir=os.path.join("python", "testing_obj"), | ||
source_path=source_path, | ||
build_path=build_path, | ||
install_path=install_path) | ||
|
||
|
||
if __name__ == '__main__': | ||
import os, sys | ||
build( | ||
source_path=os.environ['REZ_BUILD_SOURCE_PATH'], | ||
build_path=os.environ['REZ_BUILD_PATH'], | ||
install_path=os.environ['REZ_BUILD_INSTALL_PATH'], | ||
targets=sys.argv[1:] | ||
) |
31 changes: 31 additions & 0 deletions
31
src/rez/data/tests/builds/packages/testing_obj/1.0.0/package.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name = 'testing obj' | ||
version = '1.0.0' | ||
authors = ["Dan Flashes"] | ||
|
||
description = "testing the 'testing' attribute available during rez test" | ||
|
||
@late() | ||
def requires(): | ||
if in_context() and testing: | ||
return ["floob"] | ||
return ["hello"] | ||
|
||
private_build_requires = ["build_util", "python"] | ||
|
||
def commands(): | ||
env.PYTHONPATH.append('{root}/python') | ||
if testing: | ||
env.CAR_IDEA = "STURDY STEERING WHEEL" | ||
else: | ||
env.SKIP_LUNCH = "False" | ||
|
||
build_command = 'python {root}/build.py {install}' | ||
|
||
tests = { | ||
"check_car_ideas": { | ||
"command": "[[ -z ${CAR_IDEA} ]] && exit 1 || exit 0" | ||
}, | ||
"move_meeting_to_noon": { | ||
"command": "[[ -z ${SKIP_LUNCH} ]] && exit 1 || exit 0" | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/rez/data/tests/builds/packages/testing_obj/1.0.0/testing_obj/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def hello(): | ||
return "This shirt was $150 out the door and the pattern's not that complicated" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright Contributors to the Rez Project | ||
|
||
|
||
""" | ||
test rez package.py unit tests | ||
""" | ||
from rez.tests.util import TestBase, TempdirMixin | ||
from rez.resolved_context import ResolvedContext | ||
from rez.package_test import PackageTestRunner | ||
|
||
|
||
class TestTest(TestBase, TempdirMixin): | ||
@classmethod | ||
def setUpClass(cls): | ||
TempdirMixin.setUpClass() | ||
|
||
packages_path = cls.data_path("builds", "packages") | ||
cls.settings = dict( | ||
packages_path=[packages_path], | ||
package_filter=None, | ||
implicit_packages=[], | ||
warn_untimestamped=False, | ||
resolve_caching=False | ||
) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
TempdirMixin.tearDownClass() | ||
|
||
def test_1(self): | ||
"""package.py unit tests are correctly run in a testing environment""" | ||
self.inject_python_repo() | ||
context = ResolvedContext(["testing_obj", "python"]) | ||
self._run_tests(context) | ||
|
||
def _run_tests(self, r): | ||
"""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 | ||
) | ||
|
||
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") | ||
|
||
def _get_test_result(self, runner, test_name): | ||
return next( | ||
(result for result in runner.test_results.test_results if result.get("test_name") == test_name), | ||
None | ||
) |