move tests to standard pkg/test folder, enable conftest options with soft-import, update readme and makefile
This commit is contained in:
parent
f9539ed1ab
commit
d9baee2481
2
Makefile
2
Makefile
|
@ -34,7 +34,7 @@ install_test:
|
||||||
cd $(PY_SPEC_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements-testing.txt;
|
cd $(PY_SPEC_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements-testing.txt;
|
||||||
|
|
||||||
test: $(PY_SPEC_ALL_TARGETS)
|
test: $(PY_SPEC_ALL_TARGETS)
|
||||||
cd $(PY_SPEC_DIR); . venv/bin/activate; python -m pytest .
|
cd $(PY_SPEC_DIR); . venv/bin/activate; python -m pytest eth2spec
|
||||||
|
|
||||||
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 .
|
cd $(PY_SPEC_DIR); mkdir -p test-reports/eth2spec; . venv/bin/activate; python -m pytest --junitxml=test-reports/eth2spec/test_results.xml .
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from eth2spec.testing.block_processing import (
|
from eth2spec.test.block_processing import (
|
||||||
test_process_attestation,
|
test_process_attestation,
|
||||||
test_process_attester_slashing,
|
test_process_attester_slashing,
|
||||||
test_process_block_header,
|
test_process_block_header,
|
||||||
|
|
|
@ -46,8 +46,9 @@ The `-B` flag may be helpful to force-overwrite the `pyspec` output after you ma
|
||||||
|
|
||||||
Run the tests:
|
Run the tests:
|
||||||
```
|
```
|
||||||
pytest --config=minimal
|
pytest --config=minimal eth2spec
|
||||||
```
|
```
|
||||||
|
Note the package-name, this is to locate the tests.
|
||||||
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
|
@ -9,14 +9,14 @@ from eth2spec.phase0.spec import (
|
||||||
get_current_epoch,
|
get_current_epoch,
|
||||||
process_attestation
|
process_attestation
|
||||||
)
|
)
|
||||||
from eth2spec.testing.helpers import (
|
from eth2spec.test.helpers import (
|
||||||
build_empty_block_for_next_slot,
|
build_empty_block_for_next_slot,
|
||||||
get_valid_attestation,
|
get_valid_attestation,
|
||||||
next_epoch,
|
next_epoch,
|
||||||
next_slot,
|
next_slot,
|
||||||
)
|
)
|
||||||
|
|
||||||
from eth2spec.testing.context import spec_state_test, expect_assertion_error
|
from eth2spec.test.context import spec_state_test, expect_assertion_error
|
||||||
|
|
||||||
|
|
||||||
def run_attestation_processing(state, attestation, valid=True):
|
def run_attestation_processing(state, attestation, valid=True):
|
|
@ -3,13 +3,13 @@ from eth2spec.phase0.spec import (
|
||||||
get_beacon_proposer_index,
|
get_beacon_proposer_index,
|
||||||
process_attester_slashing,
|
process_attester_slashing,
|
||||||
)
|
)
|
||||||
from eth2spec.testing.helpers import (
|
from eth2spec.test.helpers import (
|
||||||
get_balance,
|
get_balance,
|
||||||
get_valid_attester_slashing,
|
get_valid_attester_slashing,
|
||||||
next_epoch,
|
next_epoch,
|
||||||
)
|
)
|
||||||
|
|
||||||
from eth2spec.testing.context import spec_state_test, expect_assertion_error
|
from eth2spec.test.context import spec_state_test, expect_assertion_error
|
||||||
|
|
||||||
|
|
||||||
def run_attester_slashing_processing(state, attester_slashing, valid=True):
|
def run_attester_slashing_processing(state, attester_slashing, valid=True):
|
|
@ -6,12 +6,12 @@ from eth2spec.phase0.spec import (
|
||||||
advance_slot,
|
advance_slot,
|
||||||
process_block_header,
|
process_block_header,
|
||||||
)
|
)
|
||||||
from eth2spec.testing.helpers import (
|
from eth2spec.test.helpers import (
|
||||||
build_empty_block_for_next_slot,
|
build_empty_block_for_next_slot,
|
||||||
next_slot,
|
next_slot,
|
||||||
)
|
)
|
||||||
|
|
||||||
from eth2spec.testing.context import spec_state_test, expect_assertion_error
|
from eth2spec.test.context import spec_state_test, expect_assertion_error
|
||||||
|
|
||||||
|
|
||||||
def prepare_state_for_header_processing(state):
|
def prepare_state_for_header_processing(state):
|
|
@ -4,7 +4,7 @@ from eth2spec.phase0.spec import (
|
||||||
ZERO_HASH,
|
ZERO_HASH,
|
||||||
process_deposit,
|
process_deposit,
|
||||||
)
|
)
|
||||||
from eth2spec.testing.helpers import (
|
from eth2spec.test.helpers import (
|
||||||
get_balance,
|
get_balance,
|
||||||
build_deposit,
|
build_deposit,
|
||||||
prepare_state_and_deposit,
|
prepare_state_and_deposit,
|
||||||
|
@ -12,7 +12,7 @@ from eth2spec.testing.helpers import (
|
||||||
pubkeys,
|
pubkeys,
|
||||||
)
|
)
|
||||||
|
|
||||||
from eth2spec.testing.context import spec_state_test, expect_assertion_error
|
from eth2spec.test.context import spec_state_test, expect_assertion_error
|
||||||
|
|
||||||
|
|
||||||
def run_deposit_processing(state, deposit, validator_index, valid=True):
|
def run_deposit_processing(state, deposit, validator_index, valid=True):
|
|
@ -3,12 +3,12 @@ from eth2spec.phase0.spec import (
|
||||||
get_current_epoch,
|
get_current_epoch,
|
||||||
process_proposer_slashing,
|
process_proposer_slashing,
|
||||||
)
|
)
|
||||||
from eth2spec.testing.helpers import (
|
from eth2spec.test.helpers import (
|
||||||
get_balance,
|
get_balance,
|
||||||
get_valid_proposer_slashing,
|
get_valid_proposer_slashing,
|
||||||
)
|
)
|
||||||
|
|
||||||
from eth2spec.testing.context import spec_state_test, expect_assertion_error
|
from eth2spec.test.context import spec_state_test, expect_assertion_error
|
||||||
|
|
||||||
|
|
||||||
def run_proposer_slashing_processing(state, proposer_slashing, valid=True):
|
def run_proposer_slashing_processing(state, proposer_slashing, valid=True):
|
|
@ -6,12 +6,12 @@ from eth2spec.phase0.spec import (
|
||||||
get_current_epoch,
|
get_current_epoch,
|
||||||
process_transfer,
|
process_transfer,
|
||||||
)
|
)
|
||||||
from eth2spec.testing.helpers import (
|
from eth2spec.test.helpers import (
|
||||||
get_valid_transfer,
|
get_valid_transfer,
|
||||||
next_epoch,
|
next_epoch,
|
||||||
)
|
)
|
||||||
|
|
||||||
from eth2spec.testing.context import spec_state_test, expect_assertion_error
|
from eth2spec.test.context import spec_state_test, expect_assertion_error
|
||||||
|
|
||||||
|
|
||||||
def run_transfer_processing(state, transfer, valid=True):
|
def run_transfer_processing(state, transfer, valid=True):
|
|
@ -6,12 +6,12 @@ from eth2spec.phase0.spec import (
|
||||||
get_current_epoch,
|
get_current_epoch,
|
||||||
process_voluntary_exit,
|
process_voluntary_exit,
|
||||||
)
|
)
|
||||||
from eth2spec.testing.helpers import (
|
from eth2spec.test.helpers import (
|
||||||
build_voluntary_exit,
|
build_voluntary_exit,
|
||||||
pubkey_to_privkey,
|
pubkey_to_privkey,
|
||||||
)
|
)
|
||||||
|
|
||||||
from eth2spec.testing.context import spec_state_test, expect_assertion_error
|
from eth2spec.test.context import spec_state_test, expect_assertion_error
|
||||||
|
|
||||||
|
|
||||||
def run_voluntary_exit_processing(state, voluntary_exit, valid=True):
|
def run_voluntary_exit_processing(state, voluntary_exit, valid=True):
|
|
@ -0,0 +1,36 @@
|
||||||
|
from eth2spec.phase0 import spec
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
def module_exists(module_name):
|
||||||
|
try:
|
||||||
|
__import__(module_name)
|
||||||
|
except ImportError:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def fixture(*args, **kwargs):
|
||||||
|
if module_exists("pytest"):
|
||||||
|
import pytest
|
||||||
|
return pytest.fixture(*args, **kwargs)
|
||||||
|
else:
|
||||||
|
def ignore():
|
||||||
|
pass
|
||||||
|
return ignore
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_addoption(parser):
|
||||||
|
parser.addoption(
|
||||||
|
"--config", action="store", default="minimal", help="config: make the pyspec use the specified configuration"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@fixture(autouse=True)
|
||||||
|
def config(request):
|
||||||
|
config_name = request.config.getoption("--config")
|
||||||
|
from preset_loader import loader
|
||||||
|
presets = loader.load_presets('../../configs/', config_name)
|
||||||
|
spec.apply_constants_preset(presets)
|
|
@ -10,7 +10,7 @@ from eth2spec.phase0.spec import (
|
||||||
get_crosslink_deltas,
|
get_crosslink_deltas,
|
||||||
process_crosslinks,
|
process_crosslinks,
|
||||||
)
|
)
|
||||||
from eth2spec.testing.helpers import (
|
from eth2spec.test.helpers import (
|
||||||
add_attestation_to_state,
|
add_attestation_to_state,
|
||||||
build_empty_block_for_next_slot,
|
build_empty_block_for_next_slot,
|
||||||
fill_aggregate_attestation,
|
fill_aggregate_attestation,
|
||||||
|
@ -19,7 +19,7 @@ from eth2spec.testing.helpers import (
|
||||||
next_epoch,
|
next_epoch,
|
||||||
next_slot,
|
next_slot,
|
||||||
)
|
)
|
||||||
from eth2spec.testing.context import spec_state_test
|
from eth2spec.test.context import spec_state_test
|
||||||
|
|
||||||
|
|
||||||
def run_process_crosslinks(state, valid=True):
|
def run_process_crosslinks(state, valid=True):
|
|
@ -4,11 +4,11 @@ from eth2spec.phase0.spec import (
|
||||||
get_current_epoch,
|
get_current_epoch,
|
||||||
is_active_validator,
|
is_active_validator,
|
||||||
)
|
)
|
||||||
from eth2spec.testing.helpers import (
|
from eth2spec.test.helpers import (
|
||||||
next_epoch,
|
next_epoch,
|
||||||
)
|
)
|
||||||
|
|
||||||
from eth2spec.testing.context import spec_state_test
|
from eth2spec.test.context import spec_state_test
|
||||||
|
|
||||||
|
|
||||||
@spec_state_test
|
@spec_state_test
|
|
@ -1,17 +0,0 @@
|
||||||
import pytest
|
|
||||||
|
|
||||||
from eth2spec.phase0 import spec
|
|
||||||
from preset_loader import loader
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
|
||||||
parser.addoption(
|
|
||||||
"--config", action="store", default="minimal", help="config: make the pyspec use the specified configuration"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
|
||||||
def config(request):
|
|
||||||
config_name = request.config.getoption("--config")
|
|
||||||
presets = loader.load_presets('../../configs/', config_name)
|
|
||||||
spec.apply_constants_preset(presets)
|
|
Loading…
Reference in New Issue