2019-05-23 13:11:46 +00:00
|
|
|
from inspect import getmembers, isfunction
|
2019-07-26 20:40:49 +00:00
|
|
|
from typing import Any, Iterable
|
2019-05-23 13:11:46 +00:00
|
|
|
|
2019-07-25 21:13:33 +00:00
|
|
|
from gen_base.gen_typing import TestCase
|
|
|
|
|
|
|
|
|
|
|
|
def generate_from_tests(runner_name: str, handler_name: str, src: Any,
|
|
|
|
fork_name: str, bls_active: bool = True) -> Iterable[TestCase]:
|
2019-05-23 13:11:46 +00:00
|
|
|
"""
|
|
|
|
Generate a list of test cases by running tests from the given src in generator-mode.
|
2019-07-25 21:13:33 +00:00
|
|
|
:param runner_name: to categorize the test in general as.
|
|
|
|
:param handler_name: to categorize the test specialization as.
|
2019-06-10 23:26:39 +00:00
|
|
|
:param src: to retrieve tests from (discovered using inspect.getmembers).
|
2019-07-25 21:13:33 +00:00
|
|
|
:param fork_name: to run tests against particular phase and/or fork.
|
|
|
|
(if multiple forks are applicable, indicate the last fork)
|
2019-05-23 13:11:46 +00:00
|
|
|
:param bls_active: optional, to override BLS switch preference. Defaults to True.
|
2019-07-25 21:13:33 +00:00
|
|
|
:return: an iterable of test cases.
|
2019-05-23 13:11:46 +00:00
|
|
|
"""
|
|
|
|
fn_names = [
|
|
|
|
name for (name, _) in getmembers(src, isfunction)
|
|
|
|
if name.startswith('test_')
|
|
|
|
]
|
|
|
|
print("generating test vectors from tests source: %s" % src.__name__)
|
|
|
|
for name in fn_names:
|
|
|
|
tfn = getattr(src, name)
|
2019-07-26 17:19:36 +00:00
|
|
|
|
|
|
|
# strip off the `test_`
|
|
|
|
case_name = name
|
|
|
|
if case_name.startswith('test_'):
|
|
|
|
case_name = case_name[5:]
|
|
|
|
|
2019-07-25 21:13:33 +00:00
|
|
|
yield TestCase(
|
|
|
|
fork_name=fork_name,
|
|
|
|
runner_name=runner_name,
|
|
|
|
handler_name=handler_name,
|
|
|
|
suite_name='pyspec_tests',
|
2019-07-26 17:19:36 +00:00
|
|
|
case_name=case_name,
|
2019-07-26 20:40:49 +00:00
|
|
|
# TODO: with_all_phases and other per-phase tooling, should be replaced with per-fork equivalent.
|
|
|
|
case_fn=lambda: tfn(generator_mode=True, phase=fork_name, bls_active=bls_active)
|
2019-07-25 21:13:33 +00:00
|
|
|
)
|