mirror of
https://github.com/ArchipelagoMW/Archipelago.git
synced 2026-03-18 13:33:48 -07:00
Compare commits
1 Commits
revert-404
...
tests_apwo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1db6b67953 |
@@ -1,20 +1,42 @@
|
|||||||
def load_tests(loader, standard_tests, pattern):
|
def load_tests(loader, standard_tests, pattern):
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
from ..TestBase import file_path
|
import Utils
|
||||||
|
import typing
|
||||||
|
import zipfile
|
||||||
|
import importlib
|
||||||
|
import inspect
|
||||||
|
|
||||||
from worlds.AutoWorld import AutoWorldRegister
|
from worlds.AutoWorld import AutoWorldRegister
|
||||||
|
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
suite.addTests(standard_tests)
|
suite.addTests(standard_tests)
|
||||||
folders = [os.path.join(os.path.split(world.__file__)[0], "test")
|
folders = [(os.path.join(os.path.split(world.__file__)[0], "test"), world.zip_path)
|
||||||
for world in AutoWorldRegister.world_types.values()]
|
for world in AutoWorldRegister.world_types.values()]
|
||||||
|
|
||||||
all_tests = [
|
all_tests: typing.List[unittest.TestCase] = [
|
||||||
test_case for folder in folders if os.path.exists(folder)
|
|
||||||
for test_collection in loader.discover(folder, top_level_dir=file_path)
|
|
||||||
for test_suite in test_collection
|
|
||||||
for test_case in test_suite
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
for folder, zip_path in folders:
|
||||||
|
if os.path.exists(folder) and not zip_path:
|
||||||
|
all_tests.extend(
|
||||||
|
test_case
|
||||||
|
for test_collection in loader.discover(folder, top_level_dir=Utils.local_path("."))
|
||||||
|
for test_suite in test_collection
|
||||||
|
for test_case in test_suite
|
||||||
|
)
|
||||||
|
elif zip_path and os.path.exists(zip_path):
|
||||||
|
with zipfile.ZipFile(zip_path) as zf:
|
||||||
|
for zip_info in zf.infolist():
|
||||||
|
if "__pycache__" in zip_info.filename:
|
||||||
|
continue
|
||||||
|
if "test" in zip_info.filename and zip_info.filename.endswith((".py", ".pyc", ".pyo")):
|
||||||
|
import_path = "worlds." + os.path.splitext(zip_info.filename)[0].replace("/", ".")
|
||||||
|
module = importlib.import_module(import_path)
|
||||||
|
for name, obj in inspect.getmembers(module, inspect.isclass):
|
||||||
|
if issubclass(obj, unittest.TestCase):
|
||||||
|
all_tests.extend(obj(method_name) for method_name in loader.getTestCaseNames(obj))
|
||||||
|
|
||||||
|
assert all_tests, "No custom tests found, when it was expected to find them."
|
||||||
suite.addTests(sorted(all_tests, key=lambda test: test.__module__))
|
suite.addTests(sorted(all_tests, key=lambda test: test.__module__))
|
||||||
return suite
|
return suite
|
||||||
|
|||||||
Reference in New Issue
Block a user