diff options
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/kmstest.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/kmstest.py b/tests/kmstest.py index 960c27f..e84d8fe 100755 --- a/tests/kmstest.py +++ b/tests/kmstest.py @@ -334,7 +334,17 @@ class KMSTest(object): if use_default_key_handler: self.loop.register(sys.stdin, selectors.EVENT_READ, self.__read_key) + def __enter__(self): + return self + + def __exit__(self, *err): + self.card = None + self.loop.close() + self.logger.close() + def __del__(self): + self.card = None + self.loop.close() self.logger.close() def atomic_crtc_disable(self, crtc, sync=True): @@ -520,3 +530,33 @@ class KMSTest(object): sys.stdout.write(f'\rTesting {self.test_name}: SUCCESS\n') sys.stdout.flush() + +if __name__ == '__main__': + import importlib + import inspect + import os + + files = [] + for path in os.scandir(): + if path.is_file() and path.name.startswith('kms-test-') and path.name.endswith('.py'): + files.append(path.name) + + files.sort() + for file in files: + print(f'- {file}') + module = importlib.import_module(file[:-3]) + tests = [] + for name in dir(module): + obj = getattr(module, name) + if not isinstance(obj, type): + continue + + if 'KMSTest' in [cls.__name__ for cls in inspect.getmro(obj)]: + tests.append(obj) + + for test in tests: + # Use a context manager to ensure proper cleanup after each test, + # otherwise state from one test may leak to the other based on when + # objects end up being deleted. + with test() as test: + test.execute() |