diff --git a/nose2/tests/functional/support/toml/a.toml b/nose2/tests/functional/support/toml/a.toml new file mode 100644 index 00000000..c93321f6 --- /dev/null +++ b/nose2/tests/functional/support/toml/a.toml @@ -0,0 +1,5 @@ +[tool.nose2.a] +a = 1 + +[tool.nose2.unittest] +plugins = "plugin_a" diff --git a/nose2/tests/functional/support/toml/b.toml b/nose2/tests/functional/support/toml/b.toml new file mode 100644 index 00000000..2c23c117 --- /dev/null +++ b/nose2/tests/functional/support/toml/b.toml @@ -0,0 +1,5 @@ +[tool.nose2.b] +b = """ +4 +5 +""" diff --git a/nose2/tests/functional/test_session.py b/nose2/tests/functional/test_session.py index 3dea9601..651e884a 100644 --- a/nose2/tests/functional/test_session.py +++ b/nose2/tests/functional/test_session.py @@ -53,3 +53,54 @@ def test_session_config_cacheing(self): # rather than parsing config file again secondaccess = cache_sess.get("a") assert secondaccess.as_int("a") == 0 + + +class SessionTomlFunctionalTests(FunctionalTestCase): + def setUp(self): + self.s = session.Session() + self.s.loadConfigFiles( + support_file("toml", "a.toml"), support_file("toml", "b.toml") + ) + sys.path.insert(0, support_file("lib")) + + def test_session_can_load_config_files(self): + assert self.s.config.has_section("a") + assert self.s.config.has_section("b") + + def test_session_holds_plugin_config(self): + plug_config = self.s.get("a") + assert plug_config + + def test_session_can_load_toml_plugins_from_modules(self): + self.s.loadPlugins() + assert self.s.plugins + plug = self.s.plugins[0] + self.assertEqual(plug.a, 1) + + def test_session_config_cacheing(self): + """Test caching of config sections works""" + + # Create new session (generic one likely already cached + # depending on test order) + cache_sess = session.Session() + cache_sess.loadConfigFiles(support_file("toml", "a.toml")) + + # First access to given section, should read from config file + firstaccess = cache_sess.get("a") + assert firstaccess.as_int("a") == 1 + + # Hack cached Config object internals to make the stored value + # something different + cache_sess.configCache["a"]._mvd["a"] = "0" + newitems = [] + for item in cache_sess.configCache["a"]._items: + if item != ("a", "1"): + newitems.append(item) + else: + newitems.append(("a", "0")) + cache_sess.configCache["a"]._items = newitems + + # Second access to given section, confirm returns cached value + # rather than parsing config file again + secondaccess = cache_sess.get("a") + assert secondaccess.as_int("a") == 0