Skip to content

Commit

Permalink
Remove unnecessary variable assignment in rez.deprecations (AcademySo…
Browse files Browse the repository at this point in the history
…ftwareFoundation#1696)

Signed-off-by: Bryce Gattis <[email protected]>
Signed-off-by: Robert Minsk <[email protected]>
  • Loading branch information
BryceGattis authored and cfxegbert committed Apr 8, 2024
1 parent caa1e17 commit 53f3dee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/rez/deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

def warn(message, category, pre_formatted=False, stacklevel=1, filename=None, **kwargs):
"""
Wrapper around warnings.warn that allows to passa a pre-formatter
Wrapper around warnings.warn that allows to pass a pre-formatter
warning message. This allows to warn about things that aren't coming
from python files, like environment variables, etc.
"""
if not pre_formatted:
message = warnings.warn(
warnings.warn(
message, category=category, stacklevel=stacklevel + 1, **kwargs
)
return
Expand Down
19 changes: 12 additions & 7 deletions src/rez/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from rez.system import system
from rez.utils.data_utils import RO_AttrDictWrapper
from rez.packages import get_developer_package
from rez.deprecations import RezDeprecationWarning
from rez.deprecations import RezDeprecationWarning, warn
import os
import os.path
import subprocess
Expand Down Expand Up @@ -332,13 +332,13 @@ def test_deprecation_from_user_config(self):
# https://docs.python.org/3.8/library/os.path.html#os.path.expanduser
os.environ["USERPROFILE"] = user_home
config = Config._create_main_config()
with self.assertWarns(RezDeprecationWarning) as warn:
with self.assertWarns(RezDeprecationWarning) as warning:
_ = config.data
# Assert just to ensure the test was set up properly.
self.assertEqual(config.data["packages_path"], ["/tmp/asd"])

self.assertEqual(
str(warn.warning),
str(warning.warning),
"config setting named 'packages_path' is deprecated and will be removed in 0.0.0.",
)

Expand All @@ -356,13 +356,13 @@ def test_deprecation_from_env_var(self):
os.environ["REZ_PACKAGES_PATH"] = "/tmp/asd2"
os.environ["REZ_DISABLE_HOME_CONFIG"] = "1"
config = Config._create_main_config()
with self.assertWarns(RezDeprecationWarning) as warn:
with self.assertWarns(RezDeprecationWarning) as warning:
_ = config.data
# Assert just to ensure the test was set up properly.
self.assertEqual(config.data["packages_path"], ["/tmp/asd2"])

self.assertEqual(
str(warn.warning),
str(warning.warning),
"config setting named 'packages_path' (configured through the "
"REZ_PACKAGES_PATH environment variable) is deprecated and will "
"be removed in 0.0.0.",
Expand All @@ -373,18 +373,23 @@ def test_deprecation_from_env_var(self):
os.environ["REZ_PACKAGES_PATH_JSON"] = '["/tmp/asd2"]'
os.environ["REZ_DISABLE_HOME_CONFIG"] = "1"
config = Config._create_main_config()
with self.assertWarns(RezDeprecationWarning) as warn:
with self.assertWarns(RezDeprecationWarning) as warning:
_ = config.data
# Assert just to ensure the test was set up properly.
self.assertEqual(config.data["packages_path"], ["/tmp/asd2"])

self.assertEqual(
str(warn.warning),
str(warning.warning),
"config setting named 'packages_path' (configured through the "
"REZ_PACKAGES_PATH_JSON environment variable) is deprecated and will "
"be removed in 0.0.0.",
)

def test_non_preformatted_warning(self):
with self.assertWarns(DeprecationWarning) as warning:
warn('Warning Message', DeprecationWarning, pre_formatted=False)
self.assertEqual(str(warning.warning), 'Warning Message')


if __name__ == "__main__":
unittest.main()

0 comments on commit 53f3dee

Please sign in to comment.