From c4bf772d30b4a557c484e9527c2c670cdbacfe89 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Mon, 10 Jun 2019 17:26:39 -0600 Subject: [PATCH] demo phase restricted generators for epoch processing --- test_generators/epoch_processing/main.py | 10 +++++----- test_libs/gen_helpers/gen_from_tests/gen.py | 7 ++++--- test_libs/pyspec/eth2spec/test/context.py | 13 +++++++++++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/test_generators/epoch_processing/main.py b/test_generators/epoch_processing/main.py index 2ce895fc5..679ef4c6b 100644 --- a/test_generators/epoch_processing/main.py +++ b/test_generators/epoch_processing/main.py @@ -2,7 +2,7 @@ from typing import Callable, Iterable from eth2spec.phase0 import spec as spec_phase0 from eth2spec.phase1 import spec as spec_phase1 -from eth2spec.test.epoch_processing import ( +from eth2spec.test.phase_0.epoch_processing import ( test_process_crosslinks, test_process_registry_updates ) @@ -33,8 +33,8 @@ def create_suite(transition_name: str, config_name: str, get_cases: Callable[[], if __name__ == "__main__": gen_runner.run_generator("epoch_processing", [ - create_suite('crosslinks', 'minimal', lambda: generate_from_tests(test_process_crosslinks)), - create_suite('crosslinks', 'mainnet', lambda: generate_from_tests(test_process_crosslinks)), - create_suite('registry_updates', 'minimal', lambda: generate_from_tests(test_process_registry_updates)), - create_suite('registry_updates', 'mainnet', lambda: generate_from_tests(test_process_registry_updates)), + create_suite('crosslinks', 'minimal', lambda: generate_from_tests(test_process_crosslinks, 'phase0')), + create_suite('crosslinks', 'mainnet', lambda: generate_from_tests(test_process_crosslinks, 'phase0')), + create_suite('registry_updates', 'minimal', lambda: generate_from_tests(test_process_registry_updates, 'phase0')), + create_suite('registry_updates', 'mainnet', lambda: generate_from_tests(test_process_registry_updates, 'phase0')), ]) diff --git a/test_libs/gen_helpers/gen_from_tests/gen.py b/test_libs/gen_helpers/gen_from_tests/gen.py index e7d801131..3810c385e 100644 --- a/test_libs/gen_helpers/gen_from_tests/gen.py +++ b/test_libs/gen_helpers/gen_from_tests/gen.py @@ -1,9 +1,10 @@ from inspect import getmembers, isfunction -def generate_from_tests(src, bls_active=True): +def generate_from_tests(src, phase, bls_active=True): """ Generate a list of test cases by running tests from the given src in generator-mode. - :param src: to retrieve tests from (discovered using inspect.getmembers) + :param src: to retrieve tests from (discovered using inspect.getmembers). + :param phase: to run tests against particular phase. :param bls_active: optional, to override BLS switch preference. Defaults to True. :return: the list of test cases. """ @@ -16,7 +17,7 @@ def generate_from_tests(src, bls_active=True): for name in fn_names: tfn = getattr(src, name) try: - test_case = tfn(generator_mode=True, bls_active=bls_active) + test_case = tfn(generator_mode=True, phase=phase, bls_active=bls_active) # If no test case data is returned, the test is ignored. if test_case is not None: out.append(test_case) diff --git a/test_libs/pyspec/eth2spec/test/context.py b/test_libs/pyspec/eth2spec/test/context.py index cbc594cd8..520eb9745 100644 --- a/test_libs/pyspec/eth2spec/test/context.py +++ b/test_libs/pyspec/eth2spec/test/context.py @@ -119,9 +119,18 @@ def with_phases(phases): fn(*args, **kw) def wrapper(*args, **kw): - if 'phase0' in phases: + run_phases = phases + + # limit phases if one explicitly specified + if 'phase' in kw: + phase = kw.pop('phase') + if phase not in phases: + return + run_phases = [phase] + + if 'phase0' in run_phases: run_with_spec_version(spec_phase0, *args, **kw) - if 'phase1' in phases: + if 'phase1' in run_phases: run_with_spec_version(spec_phase1, *args, **kw) return wrapper return decorator