Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary variable assignment in rez.deprecations #1696

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()