123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import os.path as osp
- import tempfile
- import shutil
- from glob import iglob
- from testing_utils import run_script, CpuCommonTest
- class TestTutorial(CpuCommonTest):
- SUBDIR = "./"
- TIMEOUT = 300
- PATTERN = "*.py"
- @classmethod
- def setUpClass(cls):
- cls._td = tempfile.TemporaryDirectory(dir='./')
-
-
- cls._TSUBDIR = osp.join(cls._td.name, osp.basename(cls.SUBDIR))
- shutil.copytree(cls.SUBDIR, cls._TSUBDIR)
- return super().setUpClass()
- @classmethod
- def tearDownClass(cls):
- cls._td.cleanup()
- @staticmethod
- def add_tests(cls):
- """
- Automatically patch testing functions to cls.
- """
- def _test_tutorial(script_name):
- def _test_tutorial_impl(self):
-
-
- run_script(f"python {script_name}", wd=cls._TSUBDIR)
- return _test_tutorial_impl
- for script_path in iglob(osp.join(cls.SUBDIR, cls.PATTERN)):
- script_name = osp.basename(script_path)
- if osp.normpath(osp.join(cls.SUBDIR, script_name)) != osp.normpath(
- script_path):
- raise ValueError(
- f"{script_name} should be directly contained in {cls.SUBDIR}"
- )
- setattr(cls, 'test_' + script_name, _test_tutorial(script_name))
- return cls
- @TestTutorial.add_tests
- class TestCDTutorial(TestTutorial):
- SUBDIR = "../tutorials/train/change_detection"
- @TestTutorial.add_tests
- class TestClasTutorial(TestTutorial):
- SUBDIR = "../tutorials/train/classification"
- @TestTutorial.add_tests
- class TestDetTutorial(TestTutorial):
- SUBDIR = "../tutorials/train/object_detection"
- @TestTutorial.add_tests
- class TestSegTutorial(TestTutorial):
- SUBDIR = "../tutorials/train/semantic_segmentation"
|