From b99d87fd6fc9914379cfc46586116618e66a28b1 Mon Sep 17 00:00:00 2001 From: Lucas Biaggi Date: Wed, 13 Mar 2024 23:47:48 +0000 Subject: [PATCH] Tests related to loading settings from a given file --- doorstop/cli/tests/test_main.py | 11 ++++++++++- doorstop/core/tests/__init__.py | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/doorstop/cli/tests/test_main.py b/doorstop/cli/tests/test_main.py index ab304cb5b..4c061ceb7 100644 --- a/doorstop/cli/tests/test_main.py +++ b/doorstop/cli/tests/test_main.py @@ -9,7 +9,7 @@ from doorstop import settings from doorstop.cli import main -from doorstop.cli.tests import SettingsTestCase +from doorstop.cli.tests import FILES, SettingsTestCase class TestMain(SettingsTestCase): @@ -84,3 +84,12 @@ def test_main(self): spec.loader.exec_module(runpy) # Assert self.assertIsNotNone(runpy) + + @patch("doorstop.cli.commands.run", Mock()) + def test_run_modified_settings_through_file(self): + """Verify --settings has override settings.""" + main.main(args=["--settings", f"{FILES}/settings_modified.py"]) + self.assertEqual(settings.MAX_LINE_LENGTH, 20) + # rollback to the original value to not impact an item test + settings.MAX_LINE_LENGTH = 79 + self.assertEqual(settings.MAX_LINE_LENGTH, 79) diff --git a/doorstop/core/tests/__init__.py b/doorstop/core/tests/__init__.py index be0a50f96..16d8d5d6a 100644 --- a/doorstop/core/tests/__init__.py +++ b/doorstop/core/tests/__init__.py @@ -103,6 +103,15 @@ def set_items(self, items): self._items = items +class MockSimpleDocumentExtensions(MockSimpleDocument): + """Mock Document class that enable extensions.""" + + def __init__(self, **kwargs): + super().__init__() + for k, v in kwargs.items(): + self.extensions[k] = v + + class MockDocumentSkip(MockDocument): # pylint: disable=W0223,R0902 """Mock Document class that is always skipped in tree placement."""