mirror of
https://github.com/LazoCoder/Pokemon-Terminal
synced 2024-11-22 11:53:07 +00:00
Add unit tests for terminal adapters
This commit is contained in:
parent
874696d9ff
commit
76f57062e6
2 changed files with 16 additions and 32 deletions
|
@ -1,32 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# To run use python3 -m pytest --capture=sys
|
||||
|
||||
import os
|
||||
|
||||
from pokemonterminal.adapter import available_terminals, base
|
||||
from tests.test_utils import SCRIPT_DIR
|
||||
|
||||
|
||||
def test_available_terminals():
|
||||
assert available_terminals, 'No available_terminals found.'
|
||||
terminal_names = [terminal.__name__ for terminal in available_terminals]
|
||||
non_terminals = ['NullAdapter', '__init__']
|
||||
assert all(terminal not in terminal_names for terminal in non_terminals)
|
||||
terminals_dir = os.path.join(SCRIPT_DIR, 'adapter', 'implementations')
|
||||
assert os.path.isdir(terminals_dir), 'Not found: ' + terminals_dir
|
||||
for filename in os.listdir(terminals_dir):
|
||||
terminal, ext = os.path.splitext(filename)
|
||||
if ext.lower() == '.py':
|
||||
assert terminal in (terminal_names + non_terminals), terminal
|
||||
|
||||
|
||||
def test_adapter_methods():
|
||||
for terminal in available_terminals + [base.TerminalAdapterInterface]:
|
||||
assert callable(terminal.clear)
|
||||
assert callable(terminal.is_available)
|
||||
assert callable(terminal.set_image_file_path)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_available_terminals()
|
16
tests/test_terminal.py
Normal file
16
tests/test_terminal.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from pokemonterminal.terminal import _get_adapter_classes
|
||||
import os.path as __p
|
||||
import inspect as __inspct
|
||||
|
||||
|
||||
def test_terminal_adapter_classes():
|
||||
all_adapter = _get_adapter_classes()
|
||||
files = {__inspct.getfile(x) for x in all_adapter}
|
||||
print('all adapter classes:\n', files)
|
||||
assert len(all_adapter) >= len(files), \
|
||||
"Some of the files in the adapter module don't define an adapter"
|
||||
module_name = {x.__name__: __p.splitext(__p.basename(
|
||||
__inspct.getfile(x)))[0] for x in all_adapter}
|
||||
print("'class: module' map\n", module_name)
|
||||
assert all(y.lower() in x.lower() for x, y in module_name.items()), \
|
||||
"Some of the adapters are defined in unrelated named modules"
|
Loading…
Reference in a new issue