test: tweak tests for conf module, to avoid extensions
and use 'mod' per convention
This commit is contained in:
parent
f4d8d69cb2
commit
050a6002da
1 changed files with 83 additions and 72 deletions
|
|
@ -8,9 +8,6 @@ from unittest.mock import patch, MagicMock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from wuttjamaican import conf as mod
|
from wuttjamaican import conf as mod
|
||||||
|
|
||||||
# TODO: get rid of this eventually
|
|
||||||
from wuttjamaican import conf
|
|
||||||
from wuttjamaican.exc import ConfigurationError
|
from wuttjamaican.exc import ConfigurationError
|
||||||
from wuttjamaican.app import AppHandler
|
from wuttjamaican.app import AppHandler
|
||||||
from wuttjamaican.testing import FileTestCase, ConfigTestCase
|
from wuttjamaican.testing import FileTestCase, ConfigTestCase
|
||||||
|
|
@ -21,19 +18,19 @@ class TestWuttaConfig(FileTestCase):
|
||||||
return mod.WuttaConfig(**kwargs)
|
return mod.WuttaConfig(**kwargs)
|
||||||
|
|
||||||
def test_contstructor_basic(self):
|
def test_contstructor_basic(self):
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
self.assertEqual(config.appname, "wutta")
|
self.assertEqual(config.appname, "wutta")
|
||||||
self.assertEqual(config.files_read, [])
|
self.assertEqual(config.files_read, [])
|
||||||
|
|
||||||
def test_constructor_valid_files(self):
|
def test_constructor_valid_files(self):
|
||||||
myfile = self.write_file("my.conf", "")
|
myfile = self.write_file("my.conf", "")
|
||||||
config = conf.WuttaConfig(files=[myfile])
|
config = mod.WuttaConfig(files=[myfile])
|
||||||
self.assertEqual(len(config.files_read), 1)
|
self.assertEqual(len(config.files_read), 1)
|
||||||
self.assertEqual(config.files_read[0], myfile)
|
self.assertEqual(config.files_read[0], myfile)
|
||||||
|
|
||||||
def test_constructor_missing_files(self):
|
def test_constructor_missing_files(self):
|
||||||
invalid = os.path.join(self.tempdir, "invalid.conf")
|
invalid = os.path.join(self.tempdir, "invalid.conf")
|
||||||
self.assertRaises(FileNotFoundError, conf.WuttaConfig, files=[invalid])
|
self.assertRaises(FileNotFoundError, mod.WuttaConfig, files=[invalid])
|
||||||
|
|
||||||
def test_constructor_required_files_are_present(self):
|
def test_constructor_required_files_are_present(self):
|
||||||
first = self.write_file(
|
first = self.write_file(
|
||||||
|
|
@ -56,7 +53,7 @@ baz = B
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
config = conf.WuttaConfig(files=[second])
|
config = mod.WuttaConfig(files=[second])
|
||||||
self.assertEqual(len(config.files_read), 2)
|
self.assertEqual(len(config.files_read), 2)
|
||||||
# nb. files_read listing is in order of "priority" which is
|
# nb. files_read listing is in order of "priority" which is
|
||||||
# same the as order in which files were initially read
|
# same the as order in which files were initially read
|
||||||
|
|
@ -77,7 +74,7 @@ baz = B
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertRaises(FileNotFoundError, conf.WuttaConfig, files=[second])
|
self.assertRaises(FileNotFoundError, mod.WuttaConfig, files=[second])
|
||||||
|
|
||||||
def test_constructor_included_files_are_present(self):
|
def test_constructor_included_files_are_present(self):
|
||||||
first = self.write_file(
|
first = self.write_file(
|
||||||
|
|
@ -100,7 +97,7 @@ baz = B
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
config = conf.WuttaConfig(files=[second])
|
config = mod.WuttaConfig(files=[second])
|
||||||
self.assertEqual(len(config.files_read), 2)
|
self.assertEqual(len(config.files_read), 2)
|
||||||
# nb. files_read listing is in order of "priority" which is
|
# nb. files_read listing is in order of "priority" which is
|
||||||
# same the as order in which files were initially read
|
# same the as order in which files were initially read
|
||||||
|
|
@ -121,7 +118,7 @@ baz = B
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
config = conf.WuttaConfig(files=[second])
|
config = mod.WuttaConfig(files=[second])
|
||||||
self.assertEqual(len(config.files_read), 1)
|
self.assertEqual(len(config.files_read), 1)
|
||||||
self.assertEqual(config.files_read[0], second)
|
self.assertEqual(config.files_read[0], second)
|
||||||
self.assertIsNone(config.get("foo.bar"))
|
self.assertIsNone(config.get("foo.bar"))
|
||||||
|
|
@ -159,7 +156,7 @@ baz = C
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
config = conf.WuttaConfig(files=[top, middle, base])
|
config = mod.WuttaConfig(files=[top, middle, base])
|
||||||
self.assertEqual(len(config.files_read), 3)
|
self.assertEqual(len(config.files_read), 3)
|
||||||
# nb. files_read listing is in order of "priority" which is
|
# nb. files_read listing is in order of "priority" which is
|
||||||
# same the as order in which files were initially read
|
# same the as order in which files were initially read
|
||||||
|
|
@ -186,7 +183,7 @@ require = %(here)s/first.conf
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
config = conf.WuttaConfig(files=[second])
|
config = mod.WuttaConfig(files=[second])
|
||||||
files = config.get_prioritized_files()
|
files = config.get_prioritized_files()
|
||||||
self.assertEqual(len(files), 2)
|
self.assertEqual(len(files), 2)
|
||||||
self.assertEqual(files[0], second)
|
self.assertEqual(files[0], second)
|
||||||
|
|
@ -202,16 +199,16 @@ baz = %(__file__)s
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
config = conf.WuttaConfig(files=[myconf])
|
config = mod.WuttaConfig(files=[myconf])
|
||||||
self.assertEqual(config.get("foo.bar"), f"{self.tempdir}/bar.txt")
|
self.assertEqual(config.get("foo.bar"), f"{self.tempdir}/bar.txt")
|
||||||
self.assertEqual(config.get("foo.baz"), myconf)
|
self.assertEqual(config.get("foo.baz"), myconf)
|
||||||
|
|
||||||
def test_constructor_defaults(self):
|
def test_constructor_defaults(self):
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
self.assertEqual(config.defaults, {})
|
self.assertEqual(config.defaults, {})
|
||||||
self.assertIsNone(config.get("foo"))
|
self.assertIsNone(config.get("foo"))
|
||||||
|
|
||||||
config = conf.WuttaConfig(defaults={"foo": "bar"})
|
config = mod.WuttaConfig(defaults={"foo": "bar"})
|
||||||
self.assertEqual(config.defaults, {"foo": "bar"})
|
self.assertEqual(config.defaults, {"foo": "bar"})
|
||||||
self.assertEqual(config.get("foo"), "bar")
|
self.assertEqual(config.get("foo"), "bar")
|
||||||
|
|
||||||
|
|
@ -233,17 +230,17 @@ preferdb = true
|
||||||
)
|
)
|
||||||
|
|
||||||
# flags are off by default
|
# flags are off by default
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
self.assertFalse(config.usedb)
|
self.assertFalse(config.usedb)
|
||||||
self.assertFalse(config.preferdb)
|
self.assertFalse(config.preferdb)
|
||||||
|
|
||||||
# but may override via constructor
|
# but may override via constructor
|
||||||
config = conf.WuttaConfig(usedb=True, preferdb=True)
|
config = mod.WuttaConfig(usedb=True, preferdb=True)
|
||||||
self.assertTrue(config.usedb)
|
self.assertTrue(config.usedb)
|
||||||
self.assertTrue(config.preferdb)
|
self.assertTrue(config.preferdb)
|
||||||
|
|
||||||
# and also may override via config file
|
# and also may override via config file
|
||||||
config = conf.WuttaConfig(files=[myfile])
|
config = mod.WuttaConfig(files=[myfile])
|
||||||
self.assertTrue(config.usedb)
|
self.assertTrue(config.usedb)
|
||||||
self.assertTrue(config.preferdb)
|
self.assertTrue(config.preferdb)
|
||||||
|
|
||||||
|
|
@ -256,12 +253,12 @@ preferdb = true
|
||||||
pytest.skip("test is not relevant without sqlalchemy")
|
pytest.skip("test is not relevant without sqlalchemy")
|
||||||
|
|
||||||
# flags are off by default
|
# flags are off by default
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
self.assertFalse(config.usedb)
|
self.assertFalse(config.usedb)
|
||||||
self.assertFalse(config.preferdb)
|
self.assertFalse(config.preferdb)
|
||||||
|
|
||||||
# but caller may enable the flags (if sqlalchemy available)
|
# but caller may enable the flags (if sqlalchemy available)
|
||||||
config = conf.WuttaConfig(usedb=True, preferdb=True)
|
config = mod.WuttaConfig(usedb=True, preferdb=True)
|
||||||
self.assertTrue(config.usedb)
|
self.assertTrue(config.usedb)
|
||||||
self.assertTrue(config.preferdb)
|
self.assertTrue(config.preferdb)
|
||||||
|
|
||||||
|
|
@ -276,7 +273,7 @@ preferdb = true
|
||||||
return orig_import(name, *args, **kwargs)
|
return orig_import(name, *args, **kwargs)
|
||||||
|
|
||||||
with patch("builtins.__import__", side_effect=mock_import):
|
with patch("builtins.__import__", side_effect=mock_import):
|
||||||
config = conf.WuttaConfig(usedb=True, preferdb=True)
|
config = mod.WuttaConfig(usedb=True, preferdb=True)
|
||||||
self.assertFalse(config.usedb)
|
self.assertFalse(config.usedb)
|
||||||
self.assertFalse(config.preferdb)
|
self.assertFalse(config.preferdb)
|
||||||
|
|
||||||
|
|
@ -289,19 +286,19 @@ configure_logging = true
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch.object(conf.WuttaConfig, "_configure_logging") as method:
|
with patch.object(mod.WuttaConfig, "_configure_logging") as method:
|
||||||
# no logging config by default
|
# no logging config by default
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
method.assert_not_called()
|
method.assert_not_called()
|
||||||
|
|
||||||
# but may override via constructor
|
# but may override via constructor
|
||||||
method.reset_mock()
|
method.reset_mock()
|
||||||
config = conf.WuttaConfig(configure_logging=True)
|
config = mod.WuttaConfig(configure_logging=True)
|
||||||
method.assert_called_once()
|
method.assert_called_once()
|
||||||
|
|
||||||
# and also may override via config file
|
# and also may override via config file
|
||||||
method.reset_mock()
|
method.reset_mock()
|
||||||
config = conf.WuttaConfig(files=[myfile])
|
config = mod.WuttaConfig(files=[myfile])
|
||||||
method.assert_called_once()
|
method.assert_called_once()
|
||||||
|
|
||||||
def test_constructor_configures_logging(self):
|
def test_constructor_configures_logging(self):
|
||||||
|
|
@ -318,7 +315,7 @@ configure_logging = true
|
||||||
|
|
||||||
with patch("wuttjamaican.conf.logging") as logging:
|
with patch("wuttjamaican.conf.logging") as logging:
|
||||||
# basic constructor attempts logging config
|
# basic constructor attempts logging config
|
||||||
config = conf.WuttaConfig(configure_logging=True)
|
config = mod.WuttaConfig(configure_logging=True)
|
||||||
logging.config.fileConfig.assert_called_once()
|
logging.config.fileConfig.assert_called_once()
|
||||||
|
|
||||||
# if logging config fails, error is *not* raised
|
# if logging config fails, error is *not* raised
|
||||||
|
|
@ -326,18 +323,18 @@ configure_logging = true
|
||||||
logging.config.fileConfig.side_effect = configparser.NoSectionError(
|
logging.config.fileConfig.side_effect = configparser.NoSectionError(
|
||||||
"logging"
|
"logging"
|
||||||
)
|
)
|
||||||
config = conf.WuttaConfig(configure_logging=True)
|
config = mod.WuttaConfig(configure_logging=True)
|
||||||
logging.config.fileConfig.assert_called_once()
|
logging.config.fileConfig.assert_called_once()
|
||||||
|
|
||||||
# and it works if we specify config file
|
# and it works if we specify config file
|
||||||
logging.config.fileConfig.reset_mock()
|
logging.config.fileConfig.reset_mock()
|
||||||
config = conf.WuttaConfig(files=[myfile])
|
config = mod.WuttaConfig(files=[myfile])
|
||||||
logging.config.fileConfig.assert_called_once()
|
logging.config.fileConfig.assert_called_once()
|
||||||
|
|
||||||
def test_config_has_no_app_after_init(self):
|
def test_config_has_no_app_after_init(self):
|
||||||
# initial config should *not* have an app yet, otherwise
|
# initial config should *not* have an app yet, otherwise
|
||||||
# extensions cannot specify a default app handler
|
# extensions cannot specify a default app handler
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
self.assertIsNone(config._app)
|
self.assertIsNone(config._app)
|
||||||
|
|
||||||
# but after that we can get an app okay
|
# but after that we can get an app okay
|
||||||
|
|
@ -346,7 +343,7 @@ configure_logging = true
|
||||||
self.assertIs(app, config._app)
|
self.assertIs(app, config._app)
|
||||||
|
|
||||||
def test_setdefault(self):
|
def test_setdefault(self):
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
|
|
||||||
# value is empty by default
|
# value is empty by default
|
||||||
self.assertIsNone(config.get("foo"))
|
self.assertIsNone(config.get("foo"))
|
||||||
|
|
@ -360,15 +357,15 @@ configure_logging = true
|
||||||
self.assertEqual(config.setdefault("baz", "blarg"), "blarg")
|
self.assertEqual(config.setdefault("baz", "blarg"), "blarg")
|
||||||
|
|
||||||
def test_get_require_with_default(self):
|
def test_get_require_with_default(self):
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
self.assertRaises(ValueError, config.get, "foo", require=True, default="bar")
|
self.assertRaises(ValueError, config.get, "foo", require=True, default="bar")
|
||||||
|
|
||||||
def test_get_require_missing(self):
|
def test_get_require_missing(self):
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
self.assertRaises(ConfigurationError, config.get, "foo", require=True)
|
self.assertRaises(ConfigurationError, config.get, "foo", require=True)
|
||||||
|
|
||||||
def test_get_with_default(self):
|
def test_get_with_default(self):
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
# nb. returns None if no default specified
|
# nb. returns None if no default specified
|
||||||
self.assertIsNone(config.get("foo"))
|
self.assertIsNone(config.get("foo"))
|
||||||
self.assertEqual(config.get("foo", default="bar"), "bar")
|
self.assertEqual(config.get("foo", default="bar"), "bar")
|
||||||
|
|
@ -381,7 +378,7 @@ configure_logging = true
|
||||||
pytest.skip("test is not relevant without sqlalchemy")
|
pytest.skip("test is not relevant without sqlalchemy")
|
||||||
|
|
||||||
# minimal config, but at least it needs db cxn info
|
# minimal config, but at least it needs db cxn info
|
||||||
config = conf.WuttaConfig(defaults={"wutta.db.default.url": "sqlite://"})
|
config = mod.WuttaConfig(defaults={"wutta.db.default.url": "sqlite://"})
|
||||||
|
|
||||||
session = Session()
|
session = Session()
|
||||||
|
|
||||||
|
|
@ -414,17 +411,17 @@ configure_logging = true
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
def test_get_default(self):
|
def test_get_default(self):
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
self.assertIsNone(config.get("foo"))
|
self.assertIsNone(config.get("foo"))
|
||||||
self.assertEqual(config.get("foo", default="bar"), "bar")
|
self.assertEqual(config.get("foo", default="bar"), "bar")
|
||||||
|
|
||||||
def test_get_require(self):
|
def test_get_require(self):
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
self.assertIsNone(config.get("foo"))
|
self.assertIsNone(config.get("foo"))
|
||||||
self.assertRaises(ConfigurationError, config.get, "foo", require=True)
|
self.assertRaises(ConfigurationError, config.get, "foo", require=True)
|
||||||
|
|
||||||
def test_get_require_message(self):
|
def test_get_require_message(self):
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
self.assertIsNone(config.get("foo"))
|
self.assertIsNone(config.get("foo"))
|
||||||
try:
|
try:
|
||||||
config.get("foo", require=True, message="makin stuff up")
|
config.get("foo", require=True, message="makin stuff up")
|
||||||
|
|
@ -439,7 +436,7 @@ configure_logging = true
|
||||||
pytest.skip("test is not relevant without sqlalchemy")
|
pytest.skip("test is not relevant without sqlalchemy")
|
||||||
|
|
||||||
# start out with a default value
|
# start out with a default value
|
||||||
config = conf.WuttaConfig(
|
config = mod.WuttaConfig(
|
||||||
defaults={"wutta.db.default.url": "sqlite://", "foo": "bar"}
|
defaults={"wutta.db.default.url": "sqlite://", "foo": "bar"}
|
||||||
)
|
)
|
||||||
self.assertEqual(config.get("foo"), "bar")
|
self.assertEqual(config.get("foo"), "bar")
|
||||||
|
|
@ -479,7 +476,7 @@ configure_logging = true
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
def test_get_ambiguous(self):
|
def test_get_ambiguous(self):
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
|
|
||||||
# value is returned if key is not ambiguous
|
# value is returned if key is not ambiguous
|
||||||
config.setdefault("foo", "bar")
|
config.setdefault("foo", "bar")
|
||||||
|
|
@ -490,23 +487,23 @@ configure_logging = true
|
||||||
self.assertIsNone(config.get("foo"))
|
self.assertIsNone(config.get("foo"))
|
||||||
|
|
||||||
def test_require(self):
|
def test_require(self):
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
self.assertRaises(ConfigurationError, config.require, "foo")
|
self.assertRaises(ConfigurationError, config.require, "foo")
|
||||||
|
|
||||||
def test_get_bool(self):
|
def test_get_bool(self):
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
self.assertFalse(config.get_bool("foo.bar"))
|
self.assertFalse(config.get_bool("foo.bar"))
|
||||||
config.setdefault("foo.bar", "true")
|
config.setdefault("foo.bar", "true")
|
||||||
self.assertTrue(config.get_bool("foo.bar"))
|
self.assertTrue(config.get_bool("foo.bar"))
|
||||||
|
|
||||||
def test_get_int(self):
|
def test_get_int(self):
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
self.assertIsNone(config.get_int("foo.bar"))
|
self.assertIsNone(config.get_int("foo.bar"))
|
||||||
config.setdefault("foo.bar", "42")
|
config.setdefault("foo.bar", "42")
|
||||||
self.assertEqual(config.get_int("foo.bar"), 42)
|
self.assertEqual(config.get_int("foo.bar"), 42)
|
||||||
|
|
||||||
def test_get_list(self):
|
def test_get_list(self):
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
self.assertIsNone(config.get_list("foo.bar"))
|
self.assertIsNone(config.get_list("foo.bar"))
|
||||||
config.setdefault("foo.bar", "hello world")
|
config.setdefault("foo.bar", "hello world")
|
||||||
self.assertEqual(config.get_list("foo.bar"), ["hello", "world"])
|
self.assertEqual(config.get_list("foo.bar"), ["hello", "world"])
|
||||||
|
|
@ -626,7 +623,7 @@ configure_logging = true
|
||||||
|
|
||||||
def test_get_app(self):
|
def test_get_app(self):
|
||||||
# default handler
|
# default handler
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
self.assertEqual(config.default_app_handler_spec, "wuttjamaican.app:AppHandler")
|
self.assertEqual(config.default_app_handler_spec, "wuttjamaican.app:AppHandler")
|
||||||
app = config.get_app()
|
app = config.get_app()
|
||||||
self.assertIsInstance(app, AppHandler)
|
self.assertIsInstance(app, AppHandler)
|
||||||
|
|
@ -634,7 +631,7 @@ configure_logging = true
|
||||||
self.assertIs(type(app), AppHandler)
|
self.assertIs(type(app), AppHandler)
|
||||||
|
|
||||||
# custom default handler
|
# custom default handler
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
config.default_app_handler_spec = "tests.test_conf:CustomAppHandler"
|
config.default_app_handler_spec = "tests.test_conf:CustomAppHandler"
|
||||||
app = config.get_app()
|
app = config.get_app()
|
||||||
self.assertIsInstance(app, CustomAppHandler)
|
self.assertIsInstance(app, CustomAppHandler)
|
||||||
|
|
@ -646,7 +643,7 @@ configure_logging = true
|
||||||
pytest.skip("test is not relevant without sqlalchemy")
|
pytest.skip("test is not relevant without sqlalchemy")
|
||||||
|
|
||||||
# default func
|
# default func
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
config.default_engine_maker_spec,
|
config.default_engine_maker_spec,
|
||||||
"wuttjamaican.db.conf:make_engine_from_config",
|
"wuttjamaican.db.conf:make_engine_from_config",
|
||||||
|
|
@ -655,7 +652,7 @@ configure_logging = true
|
||||||
self.assertIs(make_engine, make_engine_from_config)
|
self.assertIs(make_engine, make_engine_from_config)
|
||||||
|
|
||||||
# custom default func
|
# custom default func
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
config.default_engine_maker_spec = (
|
config.default_engine_maker_spec = (
|
||||||
"tests.test_conf:custom_make_engine_from_config"
|
"tests.test_conf:custom_make_engine_from_config"
|
||||||
)
|
)
|
||||||
|
|
@ -663,7 +660,7 @@ configure_logging = true
|
||||||
self.assertIs(make_engine, custom_make_engine_from_config)
|
self.assertIs(make_engine, custom_make_engine_from_config)
|
||||||
|
|
||||||
def test_production(self):
|
def test_production(self):
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
|
|
||||||
# false if not defined
|
# false if not defined
|
||||||
self.assertFalse(config.production())
|
self.assertFalse(config.production())
|
||||||
|
|
@ -683,15 +680,15 @@ def custom_make_engine_from_config():
|
||||||
|
|
||||||
class TestWuttaConfigExtension(TestCase):
|
class TestWuttaConfigExtension(TestCase):
|
||||||
def test_basic(self):
|
def test_basic(self):
|
||||||
config = conf.WuttaConfig()
|
config = mod.WuttaConfig()
|
||||||
ext = conf.WuttaConfigExtension()
|
ext = mod.WuttaConfigExtension()
|
||||||
self.assertIsNone(ext.key)
|
self.assertIsNone(ext.key)
|
||||||
self.assertEqual(repr(ext), "WuttaConfigExtension(key=None)")
|
self.assertEqual(repr(ext), "WuttaConfigExtension(key=None)")
|
||||||
|
|
||||||
|
|
||||||
class TestGenericDefaultFiles(TestCase):
|
class TestGenericDefaultFiles(TestCase):
|
||||||
def test_linux(self):
|
def test_linux(self):
|
||||||
files = conf.generic_default_files("wuttatest")
|
files = mod.generic_default_files("wuttatest")
|
||||||
self.assertIsInstance(files, list)
|
self.assertIsInstance(files, list)
|
||||||
self.assertTrue(len(files) > 1)
|
self.assertTrue(len(files) > 1)
|
||||||
self.assertIn("/etc/wuttatest.conf", files)
|
self.assertIn("/etc/wuttatest.conf", files)
|
||||||
|
|
@ -701,7 +698,7 @@ class TestGenericDefaultFiles(TestCase):
|
||||||
win32com.shell.SHGetSpecialFolderPath.return_value = r"C:" + os.sep
|
win32com.shell.SHGetSpecialFolderPath.return_value = r"C:" + os.sep
|
||||||
with patch.dict("sys.modules", **{"win32com.shell": win32com}):
|
with patch.dict("sys.modules", **{"win32com.shell": win32com}):
|
||||||
with patch("wuttjamaican.conf.sys", platform="win32"):
|
with patch("wuttjamaican.conf.sys", platform="win32"):
|
||||||
files = conf.generic_default_files("wuttatest")
|
files = mod.generic_default_files("wuttatest")
|
||||||
self.assertIsInstance(files, list)
|
self.assertIsInstance(files, list)
|
||||||
self.assertTrue(len(files) > 1)
|
self.assertTrue(len(files) > 1)
|
||||||
self.assertIn(os.path.join("C:", "wuttatest.conf"), files)
|
self.assertIn(os.path.join("C:", "wuttatest.conf"), files)
|
||||||
|
|
@ -716,7 +713,7 @@ class TestGenericDefaultFiles(TestCase):
|
||||||
|
|
||||||
with patch("builtins.__import__", side_effect=mock_import):
|
with patch("builtins.__import__", side_effect=mock_import):
|
||||||
with patch("wuttjamaican.conf.sys", platform="win32"):
|
with patch("wuttjamaican.conf.sys", platform="win32"):
|
||||||
files = conf.generic_default_files("wuttatest")
|
files = mod.generic_default_files("wuttatest")
|
||||||
self.assertIsInstance(files, list)
|
self.assertIsInstance(files, list)
|
||||||
self.assertEqual(len(files), 0)
|
self.assertEqual(len(files), 0)
|
||||||
|
|
||||||
|
|
@ -731,11 +728,11 @@ winsvc.RattailFileMonitor = /path/to/other/file
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
files = conf.get_config_paths(files=[myconf], winsvc="RattailFileMonitor")
|
files = mod.get_config_paths(files=[myconf], winsvc="RattailFileMonitor")
|
||||||
self.assertEqual(files, ["/path/to/other/file"])
|
self.assertEqual(files, ["/path/to/other/file"])
|
||||||
|
|
||||||
def test_nonexistent_default_files(self):
|
def test_nonexistent_default_files(self):
|
||||||
files = conf.get_config_paths(
|
files = mod.get_config_paths(
|
||||||
files=None,
|
files=None,
|
||||||
env_files_name="IGNORE_THIS",
|
env_files_name="IGNORE_THIS",
|
||||||
default_files=["/this/does/not/exist"],
|
default_files=["/this/does/not/exist"],
|
||||||
|
|
@ -755,7 +752,7 @@ class TestMakeConfig(FileTestCase):
|
||||||
with patch("wuttjamaican.conf.WuttaConfig") as WuttaConfig:
|
with patch("wuttjamaican.conf.WuttaConfig") as WuttaConfig:
|
||||||
# generic files are used if nothing is specified
|
# generic files are used if nothing is specified
|
||||||
generic_default_files.return_value = [generic]
|
generic_default_files.return_value = [generic]
|
||||||
config = conf.make_config(appname="wuttatest")
|
config = mod.make_config(appname="wuttatest", extend=False)
|
||||||
generic_default_files.assert_called_once_with("wuttatest")
|
generic_default_files.assert_called_once_with("wuttatest")
|
||||||
WuttaConfig.assert_called_once_with(
|
WuttaConfig.assert_called_once_with(
|
||||||
[generic], appname="wuttatest", usedb=None, preferdb=None
|
[generic], appname="wuttatest", usedb=None, preferdb=None
|
||||||
|
|
@ -765,7 +762,7 @@ class TestMakeConfig(FileTestCase):
|
||||||
generic_default_files.reset_mock()
|
generic_default_files.reset_mock()
|
||||||
generic_default_files.return_value = []
|
generic_default_files.return_value = []
|
||||||
WuttaConfig.reset_mock()
|
WuttaConfig.reset_mock()
|
||||||
config = conf.make_config(appname="wuttatest")
|
config = mod.make_config(appname="wuttatest", extend=False)
|
||||||
generic_default_files.assert_called_once_with("wuttatest")
|
generic_default_files.assert_called_once_with("wuttatest")
|
||||||
WuttaConfig.assert_called_once_with(
|
WuttaConfig.assert_called_once_with(
|
||||||
[], appname="wuttatest", usedb=None, preferdb=None
|
[], appname="wuttatest", usedb=None, preferdb=None
|
||||||
|
|
@ -779,7 +776,7 @@ class TestMakeConfig(FileTestCase):
|
||||||
with patch("wuttjamaican.conf.WuttaConfig") as WuttaConfig:
|
with patch("wuttjamaican.conf.WuttaConfig") as WuttaConfig:
|
||||||
# generic defaults are used if nothing specified
|
# generic defaults are used if nothing specified
|
||||||
generic_default_files.return_value = [generic]
|
generic_default_files.return_value = [generic]
|
||||||
config = conf.make_config(appname="wuttatest")
|
config = mod.make_config(appname="wuttatest", extend=False)
|
||||||
generic_default_files.assert_called_once_with("wuttatest")
|
generic_default_files.assert_called_once_with("wuttatest")
|
||||||
WuttaConfig.assert_called_once_with(
|
WuttaConfig.assert_called_once_with(
|
||||||
[generic], appname="wuttatest", usedb=None, preferdb=None
|
[generic], appname="wuttatest", usedb=None, preferdb=None
|
||||||
|
|
@ -788,7 +785,9 @@ class TestMakeConfig(FileTestCase):
|
||||||
# can specify single default file
|
# can specify single default file
|
||||||
generic_default_files.reset_mock()
|
generic_default_files.reset_mock()
|
||||||
WuttaConfig.reset_mock()
|
WuttaConfig.reset_mock()
|
||||||
config = conf.make_config(appname="wuttatest", default_files=myfile)
|
config = mod.make_config(
|
||||||
|
appname="wuttatest", default_files=myfile, extend=False
|
||||||
|
)
|
||||||
generic_default_files.assert_not_called()
|
generic_default_files.assert_not_called()
|
||||||
WuttaConfig.assert_called_once_with(
|
WuttaConfig.assert_called_once_with(
|
||||||
[myfile], appname="wuttatest", usedb=None, preferdb=None
|
[myfile], appname="wuttatest", usedb=None, preferdb=None
|
||||||
|
|
@ -797,7 +796,9 @@ class TestMakeConfig(FileTestCase):
|
||||||
# can specify default files as list
|
# can specify default files as list
|
||||||
generic_default_files.reset_mock()
|
generic_default_files.reset_mock()
|
||||||
WuttaConfig.reset_mock()
|
WuttaConfig.reset_mock()
|
||||||
config = conf.make_config(appname="wuttatest", default_files=[myfile])
|
config = mod.make_config(
|
||||||
|
appname="wuttatest", default_files=[myfile], extend=False
|
||||||
|
)
|
||||||
generic_default_files.assert_not_called()
|
generic_default_files.assert_not_called()
|
||||||
WuttaConfig.assert_called_once_with(
|
WuttaConfig.assert_called_once_with(
|
||||||
[myfile], appname="wuttatest", usedb=None, preferdb=None
|
[myfile], appname="wuttatest", usedb=None, preferdb=None
|
||||||
|
|
@ -806,8 +807,10 @@ class TestMakeConfig(FileTestCase):
|
||||||
# can specify default files as callable
|
# can specify default files as callable
|
||||||
generic_default_files.reset_mock()
|
generic_default_files.reset_mock()
|
||||||
WuttaConfig.reset_mock()
|
WuttaConfig.reset_mock()
|
||||||
config = conf.make_config(
|
config = mod.make_config(
|
||||||
appname="wuttatest", default_files=lambda appname: [myfile]
|
appname="wuttatest",
|
||||||
|
default_files=lambda appname: [myfile],
|
||||||
|
extend=False,
|
||||||
)
|
)
|
||||||
generic_default_files.assert_not_called()
|
generic_default_files.assert_not_called()
|
||||||
WuttaConfig.assert_called_once_with(
|
WuttaConfig.assert_called_once_with(
|
||||||
|
|
@ -823,7 +826,7 @@ class TestMakeConfig(FileTestCase):
|
||||||
generic_default_files.return_value = [generic]
|
generic_default_files.return_value = [generic]
|
||||||
|
|
||||||
# no plus files by default
|
# no plus files by default
|
||||||
config = conf.make_config(appname="wuttatest")
|
config = mod.make_config(appname="wuttatest", extend=False)
|
||||||
generic_default_files.assert_called_once_with("wuttatest")
|
generic_default_files.assert_called_once_with("wuttatest")
|
||||||
WuttaConfig.assert_called_once_with(
|
WuttaConfig.assert_called_once_with(
|
||||||
[generic], appname="wuttatest", usedb=None, preferdb=None
|
[generic], appname="wuttatest", usedb=None, preferdb=None
|
||||||
|
|
@ -832,7 +835,9 @@ class TestMakeConfig(FileTestCase):
|
||||||
# can specify single plus file
|
# can specify single plus file
|
||||||
generic_default_files.reset_mock()
|
generic_default_files.reset_mock()
|
||||||
WuttaConfig.reset_mock()
|
WuttaConfig.reset_mock()
|
||||||
config = conf.make_config(appname="wuttatest", plus_files=myfile)
|
config = mod.make_config(
|
||||||
|
appname="wuttatest", plus_files=myfile, extend=False
|
||||||
|
)
|
||||||
generic_default_files.assert_called_once_with("wuttatest")
|
generic_default_files.assert_called_once_with("wuttatest")
|
||||||
WuttaConfig.assert_called_once_with(
|
WuttaConfig.assert_called_once_with(
|
||||||
[generic, myfile], appname="wuttatest", usedb=None, preferdb=None
|
[generic, myfile], appname="wuttatest", usedb=None, preferdb=None
|
||||||
|
|
@ -841,7 +846,9 @@ class TestMakeConfig(FileTestCase):
|
||||||
# can specify plus files as list
|
# can specify plus files as list
|
||||||
generic_default_files.reset_mock()
|
generic_default_files.reset_mock()
|
||||||
WuttaConfig.reset_mock()
|
WuttaConfig.reset_mock()
|
||||||
config = conf.make_config(appname="wuttatest", plus_files=[myfile])
|
config = mod.make_config(
|
||||||
|
appname="wuttatest", plus_files=[myfile], extend=False
|
||||||
|
)
|
||||||
generic_default_files.assert_called_once_with("wuttatest")
|
generic_default_files.assert_called_once_with("wuttatest")
|
||||||
WuttaConfig.assert_called_once_with(
|
WuttaConfig.assert_called_once_with(
|
||||||
[generic, myfile], appname="wuttatest", usedb=None, preferdb=None
|
[generic, myfile], appname="wuttatest", usedb=None, preferdb=None
|
||||||
|
|
@ -850,8 +857,10 @@ class TestMakeConfig(FileTestCase):
|
||||||
# can specify plus files via env
|
# can specify plus files via env
|
||||||
generic_default_files.reset_mock()
|
generic_default_files.reset_mock()
|
||||||
WuttaConfig.reset_mock()
|
WuttaConfig.reset_mock()
|
||||||
config = conf.make_config(
|
config = mod.make_config(
|
||||||
appname="wuttatest", env={"WUTTATEST_CONFIG_PLUS_FILES": myfile}
|
appname="wuttatest",
|
||||||
|
env={"WUTTATEST_CONFIG_PLUS_FILES": myfile},
|
||||||
|
extend=False,
|
||||||
)
|
)
|
||||||
generic_default_files.assert_called_once_with("wuttatest")
|
generic_default_files.assert_called_once_with("wuttatest")
|
||||||
WuttaConfig.assert_called_once_with(
|
WuttaConfig.assert_called_once_with(
|
||||||
|
|
@ -867,7 +876,7 @@ class TestMakeConfig(FileTestCase):
|
||||||
generic_default_files.return_value = [generic]
|
generic_default_files.return_value = [generic]
|
||||||
|
|
||||||
# generic files by default
|
# generic files by default
|
||||||
config = conf.make_config(appname="wuttatest")
|
config = mod.make_config(appname="wuttatest", extend=False)
|
||||||
generic_default_files.assert_called_once_with("wuttatest")
|
generic_default_files.assert_called_once_with("wuttatest")
|
||||||
WuttaConfig.assert_called_once_with(
|
WuttaConfig.assert_called_once_with(
|
||||||
[generic], appname="wuttatest", usedb=None, preferdb=None
|
[generic], appname="wuttatest", usedb=None, preferdb=None
|
||||||
|
|
@ -876,7 +885,7 @@ class TestMakeConfig(FileTestCase):
|
||||||
# can specify single primary file (nb. no default files)
|
# can specify single primary file (nb. no default files)
|
||||||
generic_default_files.reset_mock()
|
generic_default_files.reset_mock()
|
||||||
WuttaConfig.reset_mock()
|
WuttaConfig.reset_mock()
|
||||||
config = conf.make_config(myfile, appname="wuttatest")
|
config = mod.make_config(myfile, appname="wuttatest", extend=False)
|
||||||
generic_default_files.assert_not_called()
|
generic_default_files.assert_not_called()
|
||||||
WuttaConfig.assert_called_once_with(
|
WuttaConfig.assert_called_once_with(
|
||||||
[myfile], appname="wuttatest", usedb=None, preferdb=None
|
[myfile], appname="wuttatest", usedb=None, preferdb=None
|
||||||
|
|
@ -885,7 +894,7 @@ class TestMakeConfig(FileTestCase):
|
||||||
# can specify primary files as list
|
# can specify primary files as list
|
||||||
generic_default_files.reset_mock()
|
generic_default_files.reset_mock()
|
||||||
WuttaConfig.reset_mock()
|
WuttaConfig.reset_mock()
|
||||||
config = conf.make_config([myfile], appname="wuttatest")
|
config = mod.make_config([myfile], appname="wuttatest", extend=False)
|
||||||
generic_default_files.assert_not_called()
|
generic_default_files.assert_not_called()
|
||||||
WuttaConfig.assert_called_once_with(
|
WuttaConfig.assert_called_once_with(
|
||||||
[myfile], appname="wuttatest", usedb=None, preferdb=None
|
[myfile], appname="wuttatest", usedb=None, preferdb=None
|
||||||
|
|
@ -894,8 +903,10 @@ class TestMakeConfig(FileTestCase):
|
||||||
# can specify primary files via env
|
# can specify primary files via env
|
||||||
generic_default_files.reset_mock()
|
generic_default_files.reset_mock()
|
||||||
WuttaConfig.reset_mock()
|
WuttaConfig.reset_mock()
|
||||||
config = conf.make_config(
|
config = mod.make_config(
|
||||||
appname="wuttatest", env={"WUTTATEST_CONFIG_FILES": myfile}
|
appname="wuttatest",
|
||||||
|
env={"WUTTATEST_CONFIG_FILES": myfile},
|
||||||
|
extend=False,
|
||||||
)
|
)
|
||||||
generic_default_files.assert_not_called()
|
generic_default_files.assert_not_called()
|
||||||
WuttaConfig.assert_called_once_with(
|
WuttaConfig.assert_called_once_with(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue