From e8b3f9985b0e4c50d6ecb38a91c7a6c69567f442 Mon Sep 17 00:00:00 2001 From: protolambda Date: Fri, 26 Jul 2019 22:40:49 +0200 Subject: [PATCH] update testgen, make epoch proc work --- test_generators/epoch_processing/main.py | 25 +++++++++---------- .../config_helpers/preset_loader/loader.py | 4 +-- test_libs/gen_helpers/gen_base/gen_runner.py | 2 +- test_libs/gen_helpers/gen_base/gen_typing.py | 3 +-- test_libs/gen_helpers/gen_from_tests/gen.py | 4 ++- test_libs/pyspec/eth2spec/test/context.py | 6 ++--- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/test_generators/epoch_processing/main.py b/test_generators/epoch_processing/main.py index da41c9e95..9a6f46ae8 100644 --- a/test_generators/epoch_processing/main.py +++ b/test_generators/epoch_processing/main.py @@ -9,13 +9,12 @@ from eth2spec.test.phase_0.epoch_processing import ( test_process_registry_updates, test_process_slashings ) -from gen_base import gen_runner, gen_suite, gen_typing +from gen_base import gen_runner, gen_typing from gen_from_tests.gen import generate_from_tests from preset_loader import loader -def create_suite(handler_name: str, tests_src, config_name: str) \ - -> Callable[[str], gen_typing.TestProvider]: +def create_provider(handler_name: str, tests_src, config_name: str) -> gen_typing.TestProvider: def prepare_fn(configs_path: str) -> str: presets = loader.load_presets(configs_path, config_name) @@ -36,14 +35,14 @@ def create_suite(handler_name: str, tests_src, config_name: str) \ if __name__ == "__main__": gen_runner.run_generator("epoch_processing", [ - create_suite('crosslinks', test_process_crosslinks, 'minimal'), - create_suite('crosslinks', test_process_crosslinks, 'mainnet'), - create_suite('final_updates', test_process_final_updates, 'minimal'), - create_suite('final_updates', test_process_final_updates, 'mainnet'), - create_suite('justification_and_finalization', test_process_justification_and_finalization, 'minimal'), - create_suite('justification_and_finalization', test_process_justification_and_finalization, 'mainnet'), - create_suite('registry_updates', test_process_registry_updates, 'minimal'), - create_suite('registry_updates', test_process_registry_updates, 'mainnet'), - create_suite('slashings', test_process_slashings, 'minimal'), - create_suite('slashings', test_process_slashings, 'mainnet'), + create_provider('crosslinks', test_process_crosslinks, 'minimal'), + create_provider('crosslinks', test_process_crosslinks, 'mainnet'), + create_provider('final_updates', test_process_final_updates, 'minimal'), + create_provider('final_updates', test_process_final_updates, 'mainnet'), + create_provider('justification_and_finalization', test_process_justification_and_finalization, 'minimal'), + create_provider('justification_and_finalization', test_process_justification_and_finalization, 'mainnet'), + create_provider('registry_updates', test_process_registry_updates, 'minimal'), + create_provider('registry_updates', test_process_registry_updates, 'mainnet'), + create_provider('slashings', test_process_slashings, 'minimal'), + create_provider('slashings', test_process_slashings, 'mainnet'), ]) diff --git a/test_libs/config_helpers/preset_loader/loader.py b/test_libs/config_helpers/preset_loader/loader.py index f37aca393..9d75932df 100644 --- a/test_libs/config_helpers/preset_loader/loader.py +++ b/test_libs/config_helpers/preset_loader/loader.py @@ -10,10 +10,10 @@ from os.path import join def load_presets(configs_dir, presets_name) -> Dict[str, Any]: """ Loads the given preset - :param presets_name: The name of the generator. (lowercase snake_case) + :param presets_name: The name of the presets. (lowercase snake_case) :return: Dictionary, mapping of constant-name -> constant-value """ - path = Path(join(configs_dir, 'constant_presets', presets_name+'.yaml')) + path = Path(join(configs_dir, presets_name+'.yaml')) yaml = YAML(typ='base') loaded = yaml.load(path) out = dict() diff --git a/test_libs/gen_helpers/gen_base/gen_runner.py b/test_libs/gen_helpers/gen_base/gen_runner.py index 9a2d26664..f0867db7e 100644 --- a/test_libs/gen_helpers/gen_base/gen_runner.py +++ b/test_libs/gen_helpers/gen_base/gen_runner.py @@ -1,7 +1,7 @@ import argparse from pathlib import Path import sys -from typing import List +from typing import Iterable from ruamel.yaml import ( YAML, diff --git a/test_libs/gen_helpers/gen_base/gen_typing.py b/test_libs/gen_helpers/gen_base/gen_typing.py index 97ddfa713..34bd71db1 100644 --- a/test_libs/gen_helpers/gen_base/gen_typing.py +++ b/test_libs/gen_helpers/gen_base/gen_typing.py @@ -3,10 +3,9 @@ from typing import ( Callable, Iterable, NewType, - Dict, Tuple, ) -from collections import namedtuple +from dataclasses import dataclass # Elements: name, out_kind, data # diff --git a/test_libs/gen_helpers/gen_from_tests/gen.py b/test_libs/gen_helpers/gen_from_tests/gen.py index 22496de6b..902b0954a 100644 --- a/test_libs/gen_helpers/gen_from_tests/gen.py +++ b/test_libs/gen_helpers/gen_from_tests/gen.py @@ -1,4 +1,5 @@ from inspect import getmembers, isfunction +from typing import Any, Iterable from gen_base.gen_typing import TestCase @@ -34,5 +35,6 @@ def generate_from_tests(runner_name: str, handler_name: str, src: Any, handler_name=handler_name, suite_name='pyspec_tests', case_name=case_name, - case_fn=lambda: tfn(generator_mode=True, fork_name=fork_name, bls_active=bls_active) + # 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) ) diff --git a/test_libs/pyspec/eth2spec/test/context.py b/test_libs/pyspec/eth2spec/test/context.py index 2adb76da0..71d38dcf1 100644 --- a/test_libs/pyspec/eth2spec/test/context.py +++ b/test_libs/pyspec/eth2spec/test/context.py @@ -4,7 +4,7 @@ from eth2spec.utils import bls from .helpers.genesis import create_genesis_state -from .utils import spectest, with_tags +from .utils import spectest, with_meta_tags def with_state(fn): @@ -53,7 +53,7 @@ def expect_assertion_error(fn): # Tags a test to be ignoring BLS for it to pass. -bls_ignored = with_tags({'bls_setting': 2}) +bls_ignored = with_meta_tags({'bls_setting': 2}) def never_bls(fn): @@ -68,7 +68,7 @@ def never_bls(fn): # Tags a test to be requiring BLS for it to pass. -bls_required = with_tags({'bls_setting': 1}) +bls_required = with_meta_tags({'bls_setting': 1}) def always_bls(fn):