From ac8495cb18d64db7702ea1bcf49ef0ab29597935 Mon Sep 17 00:00:00 2001 From: Chris Mayo Date: Mon, 13 Nov 2023 19:22:12 +0000 Subject: [PATCH] Add tests for missing and empty FILENAMEs --- tests/configuration/data/config.empty | 0 tests/configuration/test_config.py | 10 ++++++++++ tests/test_cookies.py | 8 ++++++++ tests/test_linkchecker.py | 3 +++ 4 files changed, 21 insertions(+) create mode 100644 tests/configuration/data/config.empty diff --git a/tests/configuration/data/config.empty b/tests/configuration/data/config.empty new file mode 100644 index 00000000..e69de29b diff --git a/tests/configuration/test_config.py b/tests/configuration/test_config.py index 0529b71f..b36ef09d 100644 --- a/tests/configuration/test_config.py +++ b/tests/configuration/test_config.py @@ -191,3 +191,13 @@ class TestConfig(TestBase): # blacklist logger section self.assertEqual(config["failures"]["filename"], "blacklist") self.assertEqual(config["failures"]["encoding"], "utf-8") + + def test_confparse_empty(self): + config = linkcheck.configuration.Configuration() + files = [get_file("config.empty")] + self.assertRaises(linkcheck.LinkCheckerError, config.read, files) + + def test_confparse_missing(self): + config = linkcheck.configuration.Configuration() + files = [get_file("no_such_config")] + self.assertRaises(linkcheck.LinkCheckerError, config.read, files) diff --git a/tests/test_cookies.py b/tests/test_cookies.py index 78f29bfa..ebe8fc46 100644 --- a/tests/test_cookies.py +++ b/tests/test_cookies.py @@ -18,6 +18,7 @@ Test cookie routines. """ import os +from pathlib import Path import linkcheck.cookies import linkcheck.configuration @@ -80,3 +81,10 @@ class TestCookies(TestBase): aggregate.add_request_session() session = aggregate.get_request_session() self.assertEqual({c.name for c in session.cookies}, {"om", "multiple", "are"}) + + def test_empty_cookie_file(self): + self.assertRaises( + linkcheck.LinkCheckerError, + linkcheck.cookies.from_file, + Path(__file__).parent / "configuration/data/config.empty", + ) diff --git a/tests/test_linkchecker.py b/tests/test_linkchecker.py index e105a848..5ab06832 100644 --- a/tests/test_linkchecker.py +++ b/tests/test_linkchecker.py @@ -40,3 +40,6 @@ class TestLinkchecker(unittest.TestCase): run_with_options([option]) # unknown option self.assertRaises(OSError, run_with_options, ["--imadoofus"]) + # non-existent FILENAMEs + self.assertRaises(OSError, run_with_options, ["--config", "no_such_file"]) + self.assertRaises(OSError, run_with_options, ["--cookiefile", "no_such_file"])