pytests use configuration system now, add command option to conftest to switch, also fix minor testing bug

This commit is contained in:
protolambda 2019-04-22 17:46:13 +10:00
parent 6f1669c046
commit 7f5cffb286
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
7 changed files with 17 additions and 48 deletions

View File

@ -34,10 +34,10 @@ install_test:
cd $(PY_SPEC_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements.txt; cd $(PY_SPEC_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements.txt;
test: $(PY_SPEC_ALL_TARGETS) test: $(PY_SPEC_ALL_TARGETS)
cd $(PY_SPEC_DIR); . venv/bin/activate; python -m pytest -m minimal_config . cd $(PY_SPEC_DIR); . venv/bin/activate; python -m pytest .
citest: $(PY_SPEC_ALL_TARGETS) citest: $(PY_SPEC_ALL_TARGETS)
cd $(PY_SPEC_DIR); mkdir -p test-reports/eth2spec; . venv/bin/activate; python -m pytest --junitxml=test-reports/eth2spec/test_results.xml -m minimal_config . cd $(PY_SPEC_DIR); mkdir -p test-reports/eth2spec; . venv/bin/activate; python -m pytest --junitxml=test-reports/eth2spec/test_results.xml .
# "make pyspec" to create the pyspec for all phases. # "make pyspec" to create the pyspec for all phases.
pyspec: $(PY_SPEC_ALL_TARGETS) pyspec: $(PY_SPEC_ALL_TARGETS)

View File

@ -38,7 +38,7 @@ Install dependencies:
```bash ```bash
python3 -m venv venv python3 -m venv venv
. venv/bin/activate . venv/bin/activate
pip3 install -r requirements.txt pip3 install -r requirements-testing.txt
``` ```
Note: make sure to run `make -B pyspec` from the root of the specs repository, Note: make sure to run `make -B pyspec` from the root of the specs repository,
to build the parts of the pyspec module derived from the markdown specs. to build the parts of the pyspec module derived from the markdown specs.
@ -46,7 +46,7 @@ The `-B` flag may be helpful to force-overwrite the `pyspec` output after you ma
Run the tests: Run the tests:
``` ```
pytest -m minimal_config . pytest --config=minimal
``` ```

View File

@ -0,0 +1,3 @@
-r requirements.txt
pytest>=3.6,<3.7
../config_helpers

View File

@ -2,4 +2,3 @@ eth-utils>=1.3.0,<2
eth-typing>=2.1.0,<3.0.0 eth-typing>=2.1.0,<3.0.0
pycryptodome==3.7.3 pycryptodome==3.7.3
py_ecc>=1.6.0 py_ecc>=1.6.0
pytest>=3.6,<3.7

View File

@ -1,58 +1,24 @@
import pytest import pytest
from eth2spec.phase0 import spec from eth2spec.phase0 import spec
from preset_loader import loader
from .helpers import ( from .helpers import (
create_genesis_state, create_genesis_state,
) )
DEFAULT_CONFIG = {} # no change def pytest_addoption(parser):
parser.addoption(
MINIMAL_CONFIG = { "--config", action="store", default="minimal", help="config: make the pyspec use the specified configuration"
"SHARD_COUNT": 8, )
"MIN_ATTESTATION_INCLUSION_DELAY": 2,
"TARGET_COMMITTEE_SIZE": 4,
"SLOTS_PER_EPOCH": 8,
"SLOTS_PER_HISTORICAL_ROOT": 64,
"LATEST_RANDAO_MIXES_LENGTH": 64,
"LATEST_ACTIVE_INDEX_ROOTS_LENGTH": 64,
"LATEST_SLASHED_EXIT_LENGTH": 64,
}
def overwrite_spec_config(config):
for field in config:
setattr(spec, field, config[field])
if field == "LATEST_RANDAO_MIXES_LENGTH":
spec.BeaconState.fields['latest_randao_mixes'][1] = config[field]
elif field == "SHARD_COUNT":
spec.BeaconState.fields['current_crosslinks'][1] = config[field]
spec.BeaconState.fields['previous_crosslinks'][1] = config[field]
elif field == "SLOTS_PER_HISTORICAL_ROOT":
spec.BeaconState.fields['latest_block_roots'][1] = config[field]
spec.BeaconState.fields['latest_state_roots'][1] = config[field]
spec.HistoricalBatch.fields['block_roots'][1] = config[field]
spec.HistoricalBatch.fields['state_roots'][1] = config[field]
elif field == "LATEST_ACTIVE_INDEX_ROOTS_LENGTH":
spec.BeaconState.fields['latest_active_index_roots'][1] = config[field]
elif field == "LATEST_SLASHED_EXIT_LENGTH":
spec.BeaconState.fields['latest_slashed_balances'][1] = config[field]
@pytest.fixture(
params=[
pytest.param(MINIMAL_CONFIG, marks=pytest.mark.minimal_config),
DEFAULT_CONFIG,
]
)
def config(request):
return request.param
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def overwrite_config(config): def config(request):
overwrite_spec_config(config) config_name = request.config.getoption("--config")
presets = loader.load_presets('../../configs/', config_name)
spec.apply_constants_preset(presets)
@pytest.fixture @pytest.fixture

View File

@ -118,6 +118,7 @@ def create_genesis_state(num_validators, deposit_data_leaves=None):
def build_empty_block_for_next_slot(state): def build_empty_block_for_next_slot(state):
empty_block = BeaconBlock() empty_block = BeaconBlock()
empty_block.slot = state.slot + 1 empty_block.slot = state.slot + 1
empty_block.body.eth1_data.deposit_count = state.deposit_index
previous_block_header = deepcopy(state.latest_block_header) previous_block_header = deepcopy(state.latest_block_header)
if previous_block_header.state_root == spec.ZERO_HASH: if previous_block_header.state_root == spec.ZERO_HASH:
previous_block_header.state_root = state.hash_tree_root() previous_block_header.state_root = state.hash_tree_root()