Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Alvaro Frias Garay <[email protected]>
  • Loading branch information
qequ authored and sirosen committed May 29, 2024
1 parent 7227199 commit 557536d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nose2/tests/functional/support/toml/a.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[tool.nose2.a]
a = 1

[tool.nose2.unittest]
plugins = "plugin_a"
5 changes: 5 additions & 0 deletions nose2/tests/functional/support/toml/b.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[tool.nose2.b]
b = """
4
5
"""
51 changes: 51 additions & 0 deletions nose2/tests/functional/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 557536d

Please sign in to comment.