From d92c562cd9c64a0a6977fb331c2445a68cda6b00 Mon Sep 17 00:00:00 2001 From: Bryce Gattis Date: Sat, 6 Apr 2024 19:42:45 -0500 Subject: [PATCH 1/7] Add cli bind test Signed-off-by: Bryce Gattis --- src/rez/tests/test_cli_bind.py | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/rez/tests/test_cli_bind.py diff --git a/src/rez/tests/test_cli_bind.py b/src/rez/tests/test_cli_bind.py new file mode 100644 index 000000000..8061eb8b0 --- /dev/null +++ b/src/rez/tests/test_cli_bind.py @@ -0,0 +1,45 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright Contributors to the Rez Project + + +""" +test running rez bind commandline tool +""" +from rez.tests.util import TestBase, TempdirMixin +import os.path +import subprocess +import unittest + +from rez.system import system + + +class TestBindCLI(TestBase, TempdirMixin): + @classmethod + def setUpClass(cls): + TempdirMixin.setUpClass() + + cls.install_root = os.path.join(cls.root, "packages") + + cls.settings = dict( + packages_path=[cls.install_root] + ) + + @classmethod + def tearDownClass(cls): + TempdirMixin.tearDownClass() + + def test_basic(self): + """run basic bind test""" + + # skip if cli not available + if not system.rez_bin_path: + self.skipTest("Not a production install") + + binfile = os.path.join(system.rez_bin_path, 'rez-bind') + subprocess.check_output([binfile, "platform"]) + package_exists = os.path.exists(os.path.join(self.install_root, 'platform')) + self.assertTrue(package_exists) + + +if __name__ == '__main__': + unittest.main() From eef47d3f84e04429ce7cc476d92b3be235fc4425 Mon Sep 17 00:00:00 2001 From: Bryce Gattis Date: Sat, 6 Apr 2024 20:00:12 -0500 Subject: [PATCH 2/7] Use correct config setting Signed-off-by: Bryce Gattis --- src/rez/tests/test_cli_bind.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rez/tests/test_cli_bind.py b/src/rez/tests/test_cli_bind.py index 8061eb8b0..fd8c01a5b 100644 --- a/src/rez/tests/test_cli_bind.py +++ b/src/rez/tests/test_cli_bind.py @@ -21,7 +21,7 @@ def setUpClass(cls): cls.install_root = os.path.join(cls.root, "packages") cls.settings = dict( - packages_path=[cls.install_root] + local_packages_path=[cls.install_root] ) @classmethod From 8a651bc16662b6e668eb9ab45ff49d22f8c94a0d Mon Sep 17 00:00:00 2001 From: Bryce Gattis Date: Sun, 7 Apr 2024 14:21:56 -0500 Subject: [PATCH 3/7] Fix issue by setting os.environ in class setup so subprocess sees environment variables Signed-off-by: Bryce Gattis --- src/rez/tests/test_cli_bind.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rez/tests/test_cli_bind.py b/src/rez/tests/test_cli_bind.py index fd8c01a5b..37c1345ad 100644 --- a/src/rez/tests/test_cli_bind.py +++ b/src/rez/tests/test_cli_bind.py @@ -21,9 +21,12 @@ def setUpClass(cls): cls.install_root = os.path.join(cls.root, "packages") cls.settings = dict( - local_packages_path=[cls.install_root] + local_packages_path=cls.install_root ) + # set config settings into env so subprocess sees them + os.environ.update(cls.get_settings_env(cls)) + @classmethod def tearDownClass(cls): TempdirMixin.tearDownClass() From abf87517a84878c8a5745cdd6cc7ee78bcc4c363 Mon Sep 17 00:00:00 2001 From: Bryce Gattis Date: Sun, 7 Apr 2024 14:38:25 -0500 Subject: [PATCH 4/7] Add additional test Signed-off-by: Bryce Gattis --- src/rez/tests/test_cli_bind.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/rez/tests/test_cli_bind.py b/src/rez/tests/test_cli_bind.py index 37c1345ad..08d8e387a 100644 --- a/src/rez/tests/test_cli_bind.py +++ b/src/rez/tests/test_cli_bind.py @@ -18,10 +18,12 @@ class TestBindCLI(TestBase, TempdirMixin): def setUpClass(cls): TempdirMixin.setUpClass() - cls.install_root = os.path.join(cls.root, "packages") + cls.local_root = os.path.join(cls.root, "local", "packages") + cls.release_root = os.path.join(cls.root, "release", "packages") cls.settings = dict( - local_packages_path=cls.install_root + local_packages_path=cls.local_root, + release_packages_path=cls.release_root ) # set config settings into env so subprocess sees them @@ -40,7 +42,19 @@ def test_basic(self): binfile = os.path.join(system.rez_bin_path, 'rez-bind') subprocess.check_output([binfile, "platform"]) - package_exists = os.path.exists(os.path.join(self.install_root, 'platform')) + package_exists = os.path.exists(os.path.join(self.local_root, 'platform')) + self.assertTrue(package_exists) + + def test_release(self): + """run release bind test""" + + # skip if cli not available + if not system.rez_bin_path: + self.skipTest("Not a production install") + + binfile = os.path.join(system.rez_bin_path, 'rez-bind') + subprocess.check_output([binfile, "-r", "platform"]) + package_exists = os.path.exists(os.path.join(self.release_root, 'platform')) self.assertTrue(package_exists) From c9648db7cb5eadc8cbfc589f5868b560a0208351 Mon Sep 17 00:00:00 2001 From: Bryce Gattis Date: Sun, 7 Apr 2024 14:55:03 -0500 Subject: [PATCH 5/7] Small reorg to ensure os.environ is cleaned up between tests Signed-off-by: Bryce Gattis --- src/rez/tests/test_cli_bind.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/rez/tests/test_cli_bind.py b/src/rez/tests/test_cli_bind.py index 08d8e387a..42230bfca 100644 --- a/src/rez/tests/test_cli_bind.py +++ b/src/rez/tests/test_cli_bind.py @@ -5,7 +5,7 @@ """ test running rez bind commandline tool """ -from rez.tests.util import TestBase, TempdirMixin +from rez.tests.util import restore_os_environ, TestBase, TempdirMixin import os.path import subprocess import unittest @@ -26,9 +26,6 @@ def setUpClass(cls): release_packages_path=cls.release_root ) - # set config settings into env so subprocess sees them - os.environ.update(cls.get_settings_env(cls)) - @classmethod def tearDownClass(cls): TempdirMixin.tearDownClass() @@ -41,7 +38,10 @@ def test_basic(self): self.skipTest("Not a production install") binfile = os.path.join(system.rez_bin_path, 'rez-bind') - subprocess.check_output([binfile, "platform"]) + with restore_os_environ(): + # set config settings into env so subprocess sees them + os.environ.update(self.get_settings_env()) + subprocess.check_output([binfile, "platform"]) package_exists = os.path.exists(os.path.join(self.local_root, 'platform')) self.assertTrue(package_exists) @@ -53,7 +53,10 @@ def test_release(self): self.skipTest("Not a production install") binfile = os.path.join(system.rez_bin_path, 'rez-bind') - subprocess.check_output([binfile, "-r", "platform"]) + with restore_os_environ(): + # set config settings into env so subprocess sees them + os.environ.update(self.get_settings_env()) + subprocess.check_output([binfile, "-r", "platform"]) package_exists = os.path.exists(os.path.join(self.release_root, 'platform')) self.assertTrue(package_exists) From eb3c2b9d0ac233d00957e2175742a37d5cf5a7c5 Mon Sep 17 00:00:00 2001 From: Bryce Gattis Date: Sun, 7 Apr 2024 15:05:02 -0500 Subject: [PATCH 6/7] Add additional test Signed-off-by: Bryce Gattis --- src/rez/tests/test_cli_bind.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/rez/tests/test_cli_bind.py b/src/rez/tests/test_cli_bind.py index 42230bfca..fffc3f170 100644 --- a/src/rez/tests/test_cli_bind.py +++ b/src/rez/tests/test_cli_bind.py @@ -60,6 +60,22 @@ def test_release(self): package_exists = os.path.exists(os.path.join(self.release_root, 'platform')) self.assertTrue(package_exists) + def test_custom_path(self): + """run custom path bind test""" + + # skip if cli not available + if not system.rez_bin_path: + self.skipTest("Not a production install") + + binfile = os.path.join(system.rez_bin_path, 'rez-bind') + custom_path = os.path.join(self.root, "custom", "packages") + with restore_os_environ(): + # set config settings into env so subprocess sees them + os.environ.update(self.get_settings_env()) + subprocess.check_output([binfile, "-i", custom_path, "platform"]) + package_exists = os.path.exists(os.path.join(custom_path, 'platform')) + self.assertTrue(package_exists) + if __name__ == '__main__': unittest.main() From c5a405f1f6d3424794b9f079f09afd8b0cbd7319 Mon Sep 17 00:00:00 2001 From: Bryce Gattis Date: Sun, 7 Apr 2024 15:58:49 -0500 Subject: [PATCH 7/7] Add bind list test Signed-off-by: Bryce Gattis --- src/rez/tests/test_cli_bind.py | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/rez/tests/test_cli_bind.py b/src/rez/tests/test_cli_bind.py index fffc3f170..d9fc9527e 100644 --- a/src/rez/tests/test_cli_bind.py +++ b/src/rez/tests/test_cli_bind.py @@ -5,6 +5,7 @@ """ test running rez bind commandline tool """ +import rez from rez.tests.util import restore_os_environ, TestBase, TempdirMixin import os.path import subprocess @@ -76,6 +77,44 @@ def test_custom_path(self): package_exists = os.path.exists(os.path.join(custom_path, 'platform')) self.assertTrue(package_exists) + def test_list(self): + """run list bind test""" + + # skip if cli not available + if not system.rez_bin_path: + self.skipTest("Not a production install") + + binfile = os.path.join(system.rez_bin_path, 'rez-bind') + proc = subprocess.run([binfile, "-l"], + capture_output=True, text=True) + output = proc.stdout + self.assertIn("PACKAGE BIND MODULE", output) + self.assertIn("------- -----------", output) + expected_bind_packages = [ + "arch", + "cmake", + "gcc", + "hello_world", + "os", + "pip", + "platform", + "PyQt", + "PySide", + "python", + "rez", + "rezgui", + "setuptools", + "sip" + ] + for expected_bind_pkg in expected_bind_packages: + expected_bind_file_path = os.path.join( + rez.module_root_path, + 'bind', + expected_bind_pkg + '.py' + ) + self.assertIn(expected_bind_pkg, output) + self.assertIn(expected_bind_file_path, output) + if __name__ == '__main__': unittest.main()