Files
NexQuant/test/utils/test_import.py
T

62 lines
2.1 KiB
Python
Raw Normal View History

2024-09-06 17:18:52 +08:00
import importlib
import os
import unittest
from pathlib import Path
import pytest
@pytest.mark.offline
class TestRDAgentImports(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.rdagent_directory = Path(__file__).resolve().parent.parent.parent
cls.modules = list(cls.import_all_modules_from_directory(cls.rdagent_directory))
@staticmethod
def import_all_modules_from_directory(directory):
for file in directory.joinpath("rdagent").rglob("*.py"):
fstr = str(file)
if "example" in fstr:
continue
2024-09-06 17:18:52 +08:00
if "meta_tpl" in fstr:
continue
if "autorl_bench/workspace/" in fstr:
continue
2024-11-20 17:01:18 +08:00
if "template" in fstr or "tpl" in fstr:
2024-09-06 17:18:52 +08:00
continue
2024-10-21 15:56:04 +08:00
if "model_coder" in fstr:
continue
if "llm_st" in fstr:
continue
2024-09-06 17:18:52 +08:00
if (
"rdagent/log/ui/" in fstr
2024-09-06 17:18:52 +08:00
or fstr.endswith("rdagent/app/cli.py")
or fstr.endswith("rdagent/app/CI/run.py")
or fstr.endswith("rdagent/app/utils/ape.py")
or fstr.endswith("rdagent/log/ui/utils.py")
2024-09-06 17:18:52 +08:00
):
# the entrance points
continue
2026-03-02 19:04:10 +08:00
# llamafactory==0.9.3 pins numpy to an older version, causing other
# installations to fail. The `extract_parameters` tests are therefore
# temporarily disabled and can be re-enabled once the numpy constraint is relaxed.
if "extract_parameters" in fstr:
continue
2024-09-06 17:18:52 +08:00
yield fstr[fstr.index("rdagent") : -3].replace("/", ".")
def test_import_modules(self):
print(self.modules)
for module_name in self.modules:
with self.subTest(module=module_name):
try:
print(module_name)
importlib.import_module(module_name)
except Exception as e:
self.fail(f"Failed to import {module_name}: {e}")
if __name__ == "__main__":
unittest.main()