Get rid of config global state, improve tests
While dicking around with the tests I noticed that you could make them fail if you ran them twice. Many hours were spent investigating, and it turns out that Overviewer's config stuff has global state that gets modified by having parsed configurations actually modify the default config values. Not good! We can fix this by having settingsDefinition return a dict of the defaults, instead of assigning it to module-level names. We can also get rid of test_all.py, because what it would do with pytest is run all tests *twice*. Instead, do the module path stuff in __init__.py. Also, instead of throwing a non-specific Exception if exmaple isn't checked out, just skip the test thank you very much. This is the weirdest rabbit hole I've ever gone down and I haven't slept in about 30 hours. I'm going to push this commit, and if it breaks anything, I'll be blissfully asleep as the unwashed masses begin to riot over exception this traceback that.
This commit is contained in:
6
test/__init__.py
Normal file
6
test/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# Magic spell to have us find overviewer_core
|
||||
import sys
|
||||
import os
|
||||
import os.path
|
||||
sys.path.insert(0, os.getcwd())
|
||||
sys.path.insert(0, os.path.join(os.getcwd(), os.pardir))
|
||||
@@ -1,44 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import unittest
|
||||
|
||||
# For convenience
|
||||
import sys
|
||||
import os
|
||||
import logging
|
||||
|
||||
sys.path.insert(0, os.getcwd())
|
||||
sys.path.insert(0, os.path.join(os.getcwd(), os.pardir))
|
||||
|
||||
# Import unit test cases or suites here
|
||||
from test_tileobj import TileTest
|
||||
from test_rendertileset import RendertileSetTest
|
||||
from test_settings import SettingsTest
|
||||
from test_tileset import TilesetTest
|
||||
from test_cache import TestLRU
|
||||
from test_contributors import TestContributors
|
||||
from test_cyrillic_convert import TestCyrillicConvert
|
||||
from test_playerInspect import TestPlayerInspect
|
||||
from test_regionTrimmer import TestRegionTrimmer
|
||||
from test_testRender import TestTestRender
|
||||
|
||||
# DISABLE THIS BLOCK TO GET LOG OUTPUT FROM TILESET FOR DEBUGGING
|
||||
if 0:
|
||||
root = logging.getLogger()
|
||||
|
||||
class NullHandler(logging.Handler):
|
||||
def handle(self, record):
|
||||
pass
|
||||
|
||||
def emit(self, record):
|
||||
pass
|
||||
|
||||
def createLock(self):
|
||||
self.lock = None
|
||||
root.addHandler(NullHandler())
|
||||
else:
|
||||
from overviewer_core import logger
|
||||
logger.configure(logging.DEBUG, True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -63,7 +63,11 @@ class SettingsTest(unittest.TestCase):
|
||||
}),
|
||||
]))
|
||||
self.s.set_config_item("outputdir", "/tmp/fictional/outputdir")
|
||||
self.assertEqual(fromfile.get_validated_config(), self.s.get_validated_config())
|
||||
first = fromfile.get_validated_config()
|
||||
del first["observer"]
|
||||
second = self.s.get_validated_config()
|
||||
del second["observer"]
|
||||
self.assertEqual(first, second)
|
||||
|
||||
def test_rendermode_string(self):
|
||||
self.s.set_config_item("worlds", {
|
||||
|
||||
@@ -5,15 +5,10 @@ import os
|
||||
from overviewer_core import world
|
||||
|
||||
class ExampleWorldTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
# Make sure that test/data/worlds/example exists
|
||||
# if it doesn't, then give a little
|
||||
if not os.path.exists("test/data/worlds/exmaple"):
|
||||
raise Exception("test data doesn't exist. Maybe you need to init/update your submodule?")
|
||||
|
||||
def test_basic(self):
|
||||
"Basic test of the world constructor and regionset constructor"
|
||||
if not os.path.exists("test/data/worlds/exmaple"):
|
||||
raise unittest.SkipTest("test data doesn't exist. Maybe you need to init/update your submodule?")
|
||||
w = world.World("test/data/worlds/exmaple")
|
||||
|
||||
regionsets = w.get_regionsets()
|
||||
|
||||
Reference in New Issue
Block a user