-
Notifications
You must be signed in to change notification settings - Fork 972
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
Accept logging level names (#5765) #5772
Changes from 4 commits
8cb1982
bf478ee
72400db
8954dc0
8bb4076
7c92953
d2d3427
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import os | ||
import unittest | ||
import logging | ||
|
||
from conans.client.cache.cache import CONAN_CONF | ||
from conans.client.conf import ConanClientConfigParser | ||
from conans.paths import DEFAULT_PROFILE_NAME | ||
from conans.test.utils.test_files import temp_folder | ||
from conans.util.files import save | ||
from conans.client.tools.oss import environment_append | ||
|
||
default_client_conf = '''[storage] | ||
path: ~/.conan/data | ||
|
@@ -17,6 +19,17 @@ | |
|
||
''' | ||
|
||
default_client_conf_log = '''[storage] | ||
uilianries marked this conversation as resolved.
Show resolved
Hide resolved
|
||
path: ~/.conan/data | ||
|
||
[log] | ||
trace_file = "foo/bar/quotes" | ||
{} | ||
|
||
[general] | ||
|
||
''' | ||
|
||
default_profile = ''' | ||
[settings] | ||
arch=x86_64 | ||
|
@@ -49,3 +62,74 @@ def test_proxies(self): | |
save(os.path.join(tmp_dir, CONAN_CONF), "[proxies]\nno_proxy=localhost") | ||
config = ConanClientConfigParser(os.path.join(tmp_dir, CONAN_CONF)) | ||
self.assertEqual(config.proxies["no_proxy"], "localhost") | ||
|
||
|
||
class ClientConfLogTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.tmp_dir = temp_folder() | ||
save(os.path.join(self.tmp_dir, DEFAULT_PROFILE_NAME), default_profile) | ||
try: | ||
del os.environ["CONAN_LOGGING_LEVEL"] | ||
except: | ||
pass | ||
|
||
def test_log_level_numbers_critical(self): | ||
save(os.path.join(self.tmp_dir, CONAN_CONF), default_client_conf_log.format("level = 50")) | ||
config = ConanClientConfigParser(os.path.join(self.tmp_dir, CONAN_CONF)) | ||
self.assertEqual(logging.CRITICAL, config.logging_level) | ||
|
||
def test_log_level_numbers_debug(self): | ||
save(os.path.join(self.tmp_dir, CONAN_CONF), default_client_conf_log.format("level = 10")) | ||
config = ConanClientConfigParser(os.path.join(self.tmp_dir, CONAN_CONF)) | ||
self.assertEqual(logging.DEBUG, config.logging_level) | ||
|
||
def test_log_level_numbers_invalid(self): | ||
save(os.path.join(self.tmp_dir, CONAN_CONF), default_client_conf_log.format("level = wakawaka")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow. Shouldn't we rise? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from early condition, any error is treated as default logging level (CRITICAL). Should we change it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition is here: https://github.com/conan-io/conan/blob/1.18.5/conans/client/conf/__init__.py#L511 |
||
config = ConanClientConfigParser(os.path.join(self.tmp_dir, CONAN_CONF)) | ||
self.assertEqual(logging.CRITICAL, config.logging_level) | ||
|
||
def test_log_level_numbers_env_var_debug(self): | ||
with environment_append({"CONAN_LOGGING_LEVEL": "10"}): | ||
save(os.path.join(self.tmp_dir, CONAN_CONF), default_client_conf) | ||
config = ConanClientConfigParser(os.path.join(self.tmp_dir, CONAN_CONF)) | ||
self.assertEqual(logging.DEBUG, config.logging_level) | ||
|
||
def test_log_level_numbers_env_var_debug(self): | ||
with environment_append({"CONAN_LOGGING_LEVEL": "WakaWaka"}): | ||
save(os.path.join(self.tmp_dir, CONAN_CONF), default_client_conf) | ||
config = ConanClientConfigParser(os.path.join(self.tmp_dir, CONAN_CONF)) | ||
self.assertEqual(logging.CRITICAL, config.logging_level) | ||
|
||
def test_log_level_names_debug(self): | ||
save(os.path.join(self.tmp_dir, CONAN_CONF), default_client_conf_log.format("level = debug")) | ||
config = ConanClientConfigParser(os.path.join(self.tmp_dir, CONAN_CONF)) | ||
self.assertEqual(logging.DEBUG, config.logging_level) | ||
|
||
def test_log_level_names_critical(self): | ||
save(os.path.join(self.tmp_dir, CONAN_CONF), default_client_conf_log.format("level = Critical")) | ||
config = ConanClientConfigParser(os.path.join(self.tmp_dir, CONAN_CONF)) | ||
self.assertEqual(logging.CRITICAL, config.logging_level) | ||
|
||
def test_log_level_names_invalid(self): | ||
save(os.path.join(self.tmp_dir, CONAN_CONF), default_client_conf_log.format("level = wakawaka")) | ||
config = ConanClientConfigParser(os.path.join(self.tmp_dir, CONAN_CONF)) | ||
self.assertEqual(logging.CRITICAL, config.logging_level) | ||
|
||
def test_log_level_names_env_var_debug(self): | ||
with environment_append({"CONAN_LOGGING_LEVEL": "Debug"}): | ||
save(os.path.join(self.tmp_dir, CONAN_CONF), default_client_conf) | ||
config = ConanClientConfigParser(os.path.join(self.tmp_dir, CONAN_CONF)) | ||
self.assertEqual(logging.DEBUG, config.logging_level) | ||
|
||
def test_log_level_names_env_var_warning(self): | ||
with environment_append({"CONAN_LOGGING_LEVEL": "WARNING"}): | ||
save(os.path.join(self.tmp_dir, CONAN_CONF), default_client_conf) | ||
config = ConanClientConfigParser(os.path.join(self.tmp_dir, CONAN_CONF)) | ||
self.assertEqual(logging.WARNING, config.logging_level) | ||
|
||
def test_log_level_names_env_var_invalid(self): | ||
with environment_append({"CONAN_LOGGING_LEVEL": "WakaWaka"}): | ||
save(os.path.join(self.tmp_dir, CONAN_CONF), default_client_conf) | ||
config = ConanClientConfigParser(os.path.join(self.tmp_dir, CONAN_CONF)) | ||
self.assertEqual(logging.CRITICAL, config.logging_level) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int("wakawaka") doesn't crash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto