mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-07-27 23:47:46 +00:00
test: add test import (#242)
* add test import * format with isort * format with black * merge main * fix pytest error * fix pytest error * fix pytest error * fix pytest error * format with black * fix pytest error * fix pytest error * fix pytest error * fix pytest error * fix pytest error * format with isort * Exclude entrance * Add offline test * auto-lint * update coverage rate --------- Co-authored-by: Young <afe.young@gmail.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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 "meta_tpl" in fstr:
|
||||
continue
|
||||
if "_template" in fstr:
|
||||
continue
|
||||
if (
|
||||
fstr.endswith("rdagent/log/ui/app.py")
|
||||
or fstr.endswith("rdagent/app/cli.py")
|
||||
or fstr.endswith("rdagent/app/CI/run.py")
|
||||
):
|
||||
# the entrance points
|
||||
continue
|
||||
|
||||
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()
|
||||
@@ -1,5 +1,7 @@
|
||||
import unittest
|
||||
|
||||
import pytest
|
||||
|
||||
from rdagent.core.utils import SingletonBaseClass
|
||||
|
||||
|
||||
@@ -15,6 +17,7 @@ class A(SingletonBaseClass):
|
||||
return self.__str__()
|
||||
|
||||
|
||||
@pytest.mark.offline
|
||||
class MiscTest(unittest.TestCase):
|
||||
def test_singleton(self):
|
||||
print("a1=================")
|
||||
|
||||
Reference in New Issue
Block a user