apply configs in tests properly

This commit is contained in:
protolambda 2020-01-04 18:33:15 +01:00
parent a5faabbf19
commit 13cdfa8edb
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
3 changed files with 10 additions and 2 deletions

View File

@ -5,6 +5,7 @@ presets: Dict[str, Any] = {}
# Access to overwrite spec constants based on configuration # Access to overwrite spec constants based on configuration
# This is called by the spec module after declaring its globals, and applies the loaded presets.
def apply_constants_preset(spec_globals: Dict[str, Any]) -> None: def apply_constants_preset(spec_globals: Dict[str, Any]) -> None:
global presets global presets
for k, v in presets.items(): for k, v in presets.items():
@ -14,6 +15,8 @@ def apply_constants_preset(spec_globals: Dict[str, Any]) -> None:
spec_globals[k] = v spec_globals[k] = v
# Load presets from a file. This does not apply the presets.
# To apply the presets, reload the spec module (it will re-initialize with the presets taken from here).
def load_presets(configs_path, config_name): def load_presets(configs_path, config_name):
global presets global presets
presets = loader.load_presets(configs_path, config_name) presets = loader.load_presets(configs_path, config_name)

View File

@ -1,4 +1,5 @@
from eth2spec.config import apply_config from eth2spec.config import apply_config
from eth2spec.test.context import reload_specs
# We import pytest only when it's present, i.e. when we are running tests. # We import pytest only when it's present, i.e. when we are running tests.
# The test-cases themselves can be generated without installing pytest. # The test-cases themselves can be generated without installing pytest.
@ -33,3 +34,5 @@ def pytest_addoption(parser):
def config(request): def config(request):
config_name = request.config.getoption("--config") config_name = request.config.getoption("--config")
apply_config.load_presets('../../configs/', config_name) apply_config.load_presets('../../configs/', config_name)
# now that the presets are loaded, reload the specs to apply them
reload_specs()

View File

@ -10,8 +10,10 @@ from typing import Any, Callable, Sequence
from importlib import reload from importlib import reload
reload(spec_phase0)
reload(spec_phase1) def reload_specs():
reload(spec_phase0)
reload(spec_phase1)
def with_custom_state(balances_fn: Callable[[Any], Sequence[int]], def with_custom_state(balances_fn: Callable[[Any], Sequence[int]],