aboutsummaryrefslogtreecommitdiff
path: root/tests/test_logging.py
diff options
context:
space:
mode:
authorCody Logan <cody@lokken.dev>2023-11-07 11:41:49 -0800
committerGitHub <noreply@github.com>2023-11-07 11:41:49 -0800
commit5129ad62392948a033ee988e4093d095f5005c77 (patch)
tree5df144f6970d7d015bce94cff4516a388b5cddab /tests/test_logging.py
parentbc5d19c8150bf7960839243ceeb6f62a9df54e18 (diff)
parent7c2dadfa38ac08a060f2df987b7d0b7f2f0b5ad0 (diff)
downloadwikiget-5129ad62392948a033ee988e4093d095f5005c77.tar.gz
wikiget-5129ad62392948a033ee988e4093d095f5005c77.zip
Merge pull request #12 from clpo13/improve-tests
Improve tests and test coverage
Diffstat (limited to 'tests/test_logging.py')
-rw-r--r--tests/test_logging.py110
1 files changed, 47 insertions, 63 deletions
diff --git a/tests/test_logging.py b/tests/test_logging.py
index b189c28..55a3397 100644
--- a/tests/test_logging.py
+++ b/tests/test_logging.py
@@ -23,67 +23,51 @@ from pytest import LogCaptureFixture
from wikiget.logging import FileLogAdapter, configure_logging
from wikiget.wikiget import parse_args
-logger = logging.getLogger()
-
-def test_custom_log_adapter(caplog: LogCaptureFixture) -> None:
- """
- The custom log adapter should prepend the filename to log messages.
- """
- args = parse_args(["File:Example.jpg"])
- configure_logging(args.verbose, args.logfile, quiet=args.quiet)
- adapter = FileLogAdapter(logger, {"filename": "Example.jpg"})
- adapter.warning("test log")
- assert "[Example.jpg] test log" in caplog.text
-
-
-def test_file_logging(tmp_path: Path) -> None:
- """
- Logging to a file should create the file in the specified location.
- """
- logfile_location = tmp_path / "test.log"
- args = parse_args(["File:Example.jpg", "-l", str(logfile_location)])
- configure_logging(args.verbose, args.logfile, quiet=args.quiet)
- assert logfile_location.is_file()
-
-
-def test_default_logging() -> None:
- """
- The default log level should be set to WARNING.
- """
- args = parse_args(["File:Example.jpg"])
- configure_logging(args.verbose, args.logfile, quiet=args.quiet)
- # each call of configure_logging() adds a new handler to the logger, so we need to
- # grab the most recently added one to test
- handler = logger.handlers[-1]
- assert handler.level == logging.WARNING
-
-
-def test_verbose_logging() -> None:
- """
- When -v is passed, the log level should be set to INFO.
- """
- args = parse_args(["File:Example.jpg", "-v"])
- configure_logging(args.verbose, args.logfile, quiet=args.quiet)
- handler = logger.handlers[-1]
- assert handler.level == logging.INFO
-
-
-def test_very_verbose_logging() -> None:
- """
- When -vv is passed, the log level should be set to DEBUG.
- """
- args = parse_args(["File:Example.jpg", "-vv"])
- configure_logging(args.verbose, args.logfile, quiet=args.quiet)
- handler = logger.handlers[-1]
- assert handler.level == logging.DEBUG
-
-
-def test_quiet_logging() -> None:
- """
- When -q is passed, the log level should be set to ERROR.
- """
- args = parse_args(["File:Example.jpg", "-q"])
- configure_logging(args.verbose, args.logfile, quiet=args.quiet)
- handler = logger.handlers[-1]
- assert handler.level == logging.ERROR
+class TestLogging:
+ logger = logging.getLogger()
+
+ def test_custom_log_adapter(self, caplog: LogCaptureFixture) -> None:
+ """The custom log adapter should prepend the filename to log messages."""
+ args = parse_args(["File:Example.jpg"])
+ configure_logging(args.verbose, args.logfile, quiet=args.quiet)
+ adapter = FileLogAdapter(self.logger, {"filename": "Example.jpg"})
+ adapter.warning("test log")
+ assert "[Example.jpg] test log" in caplog.text
+
+ def test_file_logging(self, tmp_path: Path) -> None:
+ """Logging to a file should create the file in the specified location."""
+ logfile_location = tmp_path / "test.log"
+ args = parse_args(["File:Example.jpg", "-l", str(logfile_location)])
+ configure_logging(args.verbose, args.logfile, quiet=args.quiet)
+ assert logfile_location.is_file()
+
+ def test_default_logging(self) -> None:
+ """The default log level should be set to WARNING."""
+ args = parse_args(["File:Example.jpg"])
+ configure_logging(args.verbose, args.logfile, quiet=args.quiet)
+ # each call of configure_logging() adds a new handler to the logger, so we need
+ # to grab the most recently added one to test
+ handler = self.logger.handlers[-1]
+ assert handler.level == logging.WARNING
+
+ def test_verbose_logging(self) -> None:
+ """When -v is passed, the log level should be set to INFO."""
+ args = parse_args(["File:Example.jpg", "-v"])
+ configure_logging(args.verbose, args.logfile, quiet=args.quiet)
+ handler = self.logger.handlers[-1]
+ assert handler.level == logging.INFO
+
+ def test_very_verbose_logging(self) -> None:
+ """When -vv is passed, the log level should be set to DEBUG."""
+ args = parse_args(["File:Example.jpg", "-vv"])
+ configure_logging(args.verbose, args.logfile, quiet=args.quiet)
+ handler = self.logger.handlers[-1]
+ assert handler.level == logging.DEBUG
+
+ def test_quiet_logging(self) -> None:
+ """When -q is passed, the log level should be set to ERROR."""
+ args = parse_args(["File:Example.jpg", "-q"])
+ configure_logging(args.verbose, args.logfile, quiet=args.quiet)
+ handler = self.logger.handlers[-1]
+ assert handler.level == logging.ERROR