-
Notifications
You must be signed in to change notification settings - Fork 341
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 (#1852)
Signed-off-by: Fabrice Macagno <[email protected]> Signed-off-by: Nathan Cheung <[email protected]> Signed-off-by: Jean-Christophe Morin <[email protected]> Co-authored-by: Fabrice Macagno <[email protected]> Co-authored-by: Nathan Cheung <[email protected]>
- Loading branch information
1 parent
84c827d
commit 491497f
Showing
11 changed files
with
200 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:] | ||
) |
42 changes: 42 additions & 0 deletions
42
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,42 @@ | ||
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 = { | ||
"command_as_string_success": { | ||
"command": "exit 0" | ||
}, | ||
"command_as_string_fail": { | ||
"command": "exit 1" | ||
}, | ||
"check_car_ideas": { | ||
"command": ["python", "-c", "import os; assert os.environ.get('CAR_IDEA') == 'STURDY STEERING WHEEL'"], | ||
"requires": ["python"] | ||
}, | ||
"move_meeting_to_noon": { | ||
# 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"] | ||
} | ||
} |
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,85 @@ | ||
# 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 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=verbose | ||
) | ||
|
||
test_names = runner.get_test_names() | ||
|
||
for test_name in test_names: | ||
runner.run_test(test_name) | ||
|
||
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( | ||
(result for result in runner.test_results.test_results if result.get("test_name") == test_name), | ||
None | ||
) |