File indexing completed on 2026-04-17 07:47:24
0001 import acts
0002 import pytest
0003
0004
0005 def test_get_default_logger_creates_logger():
0006 logger = acts.getDefaultLogger("test_logger", acts.logging.INFO)
0007 assert logger is not None
0008 assert logger.name == "test_logger"
0009 assert logger.level == acts.logging.INFO
0010
0011
0012 def test_get_default_logger_default_level():
0013 logger = acts.getDefaultLogger("test_default_level")
0014 assert logger.level == acts.logging.INFO
0015
0016
0017 @acts.with_log_threshold(acts.logging.FATAL)
0018 def test_get_default_logger_different_levels():
0019 for level in (
0020 acts.logging.VERBOSE,
0021 acts.logging.DEBUG,
0022 acts.logging.WARNING,
0023 acts.logging.ERROR,
0024 acts.logging.FATAL,
0025 ):
0026 logger = acts.getDefaultLogger(f"logger_{level}", level)
0027 assert logger.level == level
0028
0029
0030 @acts.with_log_threshold(acts.logging.MAX)
0031 def test_get_default_logger_log_methods(capfd):
0032 logger = acts.getDefaultLogger("test_log_methods", acts.logging.VERBOSE)
0033 logger.verbose("verbose message")
0034 logger.debug("debug message")
0035 logger.info("info message")
0036 logger.warning("warning message")
0037 logger.error("error message")
0038 logger.fatal("fatal message")
0039
0040 captured = capfd.readouterr()
0041 assert "test_log_met" in captured.out
0042 assert "verbose message" in captured.out
0043 assert "debug message" in captured.out
0044 assert "info message" in captured.out
0045 assert "warning message" in captured.out
0046 assert "error message" in captured.out
0047 assert "fatal message" in captured.out
0048
0049
0050 def test_get_default_logger_format_args(capfd):
0051 logger = acts.getDefaultLogger("test_format", acts.logging.INFO)
0052 logger.info("value: {}", 42)
0053 logger.info("two values: {} {}", "foo", "bar")
0054
0055 captured = capfd.readouterr()
0056 assert "test_format" in captured.out
0057 assert "value: 42" in captured.out
0058 assert "two values: foo bar" in captured.out
0059
0060
0061 def test_get_default_logger_level_filtering(capfd):
0062 logger = acts.getDefaultLogger("test_filter", acts.logging.INFO)
0063 logger.debug("filtered out")
0064 logger.info("should appear")
0065
0066 captured = capfd.readouterr()
0067 assert "should appear" in captured.out
0068 assert "filtered out" not in captured.out
0069
0070
0071 def test_logging_threshold():
0072 assert acts.logging.getFailureThreshold() == acts.logging.WARNING
0073
0074
0075 def test_logging_threshold_context_manager():
0076 with acts.logging.ScopedFailureThreshold(acts.logging.ERROR):
0077 assert acts.logging.getFailureThreshold() == acts.logging.ERROR
0078 assert acts.logging.getFailureThreshold() == acts.logging.WARNING
0079
0080
0081 def test_logging_threshold_context_manager_exception():
0082 with pytest.raises(RuntimeError):
0083 with acts.logging.ScopedFailureThreshold(level=acts.logging.ERROR):
0084 assert acts.logging.getFailureThreshold() == acts.logging.ERROR
0085 raise RuntimeError("test")
0086 assert acts.logging.getFailureThreshold() == acts.logging.WARNING
0087
0088
0089 def test_consum_logger_function(capfd):
0090 logger = acts.getDefaultLogger("test_consum_logger_function", acts.logging.VERBOSE)
0091 acts.logging._consumeLoggerFunction(logger)
0092 captured = capfd.readouterr()
0093 assert "consumed logger logs" in captured.out
0094 with pytest.raises(ValueError):
0095 logger.verbose("verbose message")
0096
0097
0098 def test_clone_preserves_name_and_level():
0099 logger = acts.getDefaultLogger("original", acts.logging.INFO)
0100 cloned = logger.clone()
0101 assert cloned.name == "original"
0102 assert cloned.level == acts.logging.INFO
0103
0104
0105 def test_clone_with_new_name():
0106 logger = acts.getDefaultLogger("original", acts.logging.INFO)
0107 cloned = logger.clone(name="renamed")
0108 assert cloned.name == "renamed"
0109 assert cloned.level == acts.logging.INFO
0110
0111
0112 def test_clone_with_new_level():
0113 logger = acts.getDefaultLogger("original", acts.logging.INFO)
0114 cloned = logger.clone(level=acts.logging.DEBUG)
0115 assert cloned.name == "original"
0116 assert cloned.level == acts.logging.DEBUG
0117
0118
0119 @acts.with_log_threshold(acts.logging.FATAL)
0120 def test_clone_with_name_and_level():
0121 logger = acts.getDefaultLogger("original", acts.logging.INFO)
0122 cloned = logger.clone(name="new_name", level=acts.logging.ERROR)
0123 assert cloned.name == "new_name"
0124 assert cloned.level == acts.logging.ERROR
0125
0126
0127 def test_clone_level_only_overload():
0128 logger = acts.getDefaultLogger("original", acts.logging.INFO)
0129 cloned = logger.clone(acts.logging.WARNING)
0130 assert cloned.name == "original"
0131 assert cloned.level == acts.logging.WARNING
0132
0133
0134 def test_clone_is_independent(capfd):
0135 logger = acts.getDefaultLogger("original", acts.logging.INFO)
0136 cloned = logger.clone(level=acts.logging.DEBUG)
0137
0138 cloned.debug("from clone")
0139 logger.debug("from original")
0140 captured = capfd.readouterr()
0141 assert "from clone" in captured.out
0142 assert "from original" not in captured.out
0143
0144
0145 def test_clone_with_suffix():
0146 logger = acts.getDefaultLogger("base", acts.logging.INFO)
0147 cloned = logger.cloneWithSuffix("_sub")
0148 assert cloned.name == "base_sub"
0149 assert cloned.level == acts.logging.INFO
0150
0151
0152 def test_clone_with_suffix_and_level():
0153 logger = acts.getDefaultLogger("base", acts.logging.INFO)
0154 cloned = logger.cloneWithSuffix("_sub", acts.logging.DEBUG)
0155 assert cloned.name == "base_sub"
0156 assert cloned.level == acts.logging.DEBUG
0157
0158
0159 def test_config_with_logger(capfd):
0160 logger = acts.getDefaultLogger("test_config_with_logger", acts.logging.VERBOSE)
0161 config = acts.logging._ConfigWithLogger(logger)
0162 with pytest.raises(ValueError):
0163 logger.verbose("verbose message")
0164 config.logger.verbose("verbose message")
0165 captured = capfd.readouterr()
0166 assert "test_config_" in captured.out
0167 assert "verbose message" in captured.out