Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move tests #17209

Merged
merged 4 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 1 addition & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ disable_warnings=
relative_files=True
source_pkgs=
chia
tests
omit=
tests/**/config.py
chia/_tests/**/config.py
concurrency=multiprocessing, thread
parallel=True

Expand Down
8 changes: 4 additions & 4 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exclude = ./typings/**/*
ignore = E203,W503
extend-ignore = E704,E701
per-file-ignores =
tests/util/build_network_protocol_files.py:F405
tests/util/test_network_protocol_files.py:F405
tests/util/test_network_protocol_json.py:F405
tests/util/protocol_messages_json.py:E501
chia/_tests/util/build_network_protocol_files.py:F405
chia/_tests/util/test_network_protocol_files.py:F405
chia/_tests/util/test_network_protocol_json.py:F405
chia/_tests/util/protocol_messages_json.py:E501
4 changes: 2 additions & 2 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:

- name: pytest
run: |
pytest -n 0 --capture no -m benchmark -o 'junit_suite_name=benchmarks' --junitxml=junit-data/benchmarks.raw.xml --benchmark-repeats ${{ needs.setup.outputs.repeats }} tests
pytest -n 0 --capture no -m benchmark -o 'junit_suite_name=benchmarks' --junitxml=junit-data/benchmarks.raw.xml --benchmark-repeats ${{ needs.setup.outputs.repeats }} chia/_tests/

- name: Format JUnit data and prepare results
if: always()
Expand All @@ -124,4 +124,4 @@ jobs:
- name: Add benchmark results to workflow summary
if: always()
run: |
python -m tests.process_junit --type benchmark --xml junit-data/benchmarks.xml --markdown --link-prefix ${{ github.event.repository.html_url }}/blob/${{ github.sha }}/ --link-line-separator \#L >> "$GITHUB_STEP_SUMMARY"
python -m chia._tests.process_junit --type benchmark --xml junit-data/benchmarks.xml --markdown --link-prefix ${{ github.event.repository.html_url }}/blob/${{ github.sha }}/ --link-line-separator \#L >> "$GITHUB_STEP_SUMMARY"
13 changes: 11 additions & 2 deletions .github/workflows/test-single.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ jobs:
sh install-timelord.sh -n
./vdf_bench square_asm 400000

- name: Verify source and installed tests match
run: |
echo '==== collecting source tests ===='
pytest --collect-only -qq --import-mode=prepend chia/_tests/ | sed -n 's;^\(chia/_tests/.*\);\1;p' | sort | tee source_tests
echo '==== collecting installed tests ===='
pytest --collect-only -qq --import-mode=append --pyargs chia._tests | sed -n 's;^venv/.*/\(chia/_tests/.*\);\1;p' | sort | tee installed_tests
echo '==== diffing collected tests ===='
diff --unified source_tests installed_tests

- name: Move chia/ so we test the installed code
run: |
mv chia/ notchia/
Expand All @@ -228,7 +237,7 @@ jobs:
env:
ENABLE_PYTEST_MONITOR: ${{ matrix.os.matrix == 'ubuntu' && matrix.configuration.enable_pytest_monitor || '' }}
run: |
pytest --cov=chia --cov=tests --cov-config=.coveragerc --cov-report= -o 'junit_suite_name=${{ env.JOB_FILE_NAME }}' --junitxml='junit-data/junit.${{ env.JOB_FILE_NAME }}.xml' --durations=10 ${{ matrix.configuration.pytest_parallel_args[matrix.os.matrix] }} -m "not benchmark" ${{ env.ENABLE_PYTEST_MONITOR }} ${{ matrix.configuration.test_files }}
pytest --cov=chia --cov-config=.coveragerc --cov-report= -o 'junit_suite_name=${{ env.JOB_FILE_NAME }}' --junitxml='junit-data/junit.${{ env.JOB_FILE_NAME }}.xml' --durations=10 ${{ matrix.configuration.pytest_parallel_args[matrix.os.matrix] }} -m "not benchmark" ${{ env.ENABLE_PYTEST_MONITOR }} ${{ matrix.configuration.test_files }}

- name: Move back to chia/ for coverage
run: |
Expand Down Expand Up @@ -260,4 +269,4 @@ jobs:
if: matrix.os.matrix == 'ubuntu' && matrix.configuration.check_resource_usage
run: |
sqlite3 -readonly -separator " " .pymon "select item,cpu_usage,total_time,mem_usage from TEST_METRICS order by mem_usage desc;" >metrics.out
./tests/check_pytest_monitor_output.py <metrics.out
./chia/_tests/check_pytest_monitor_output.py <metrics.out
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Generate matrix configuration
id: configure
run: |
python tests/build-job-matrix.py --per directory --verbose > matrix.json
python chia/_tests/build-job-matrix.py --per directory --verbose > matrix.json
cat matrix.json
echo configuration=$(cat matrix.json) >> "$GITHUB_OUTPUT"
echo matrix_mode=${{ ( github.event_name == 'schedule' ) && 'all' || ( github.event_name == 'workflow_dispatch' ) && 'all' || ( github.repository_owner == 'Chia-Network' && github.repository != 'Chia-Network/chia-blockchain' ) && 'limited' || ( github.repository_owner == 'Chia-Network' && github.repository == 'Chia-Network/chia-blockchain' && github.ref == 'refs/heads/main' ) && 'main' || ( github.repository_owner == 'Chia-Network' && github.repository == 'Chia-Network/chia-blockchain' && startsWith(github.ref, 'refs/heads/release/') ) && 'all' || ( github.repository_owner == 'Chia-Network' && github.repository == 'Chia-Network/chia-blockchain' && startsWith(github.base_ref, 'release/') ) && 'all' || 'main' }} >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -164,8 +164,8 @@ jobs:
- name: Add time out assert results to workflow summary
if: always()
run: |
python -m tests.process_junit --limit 50 --type time_out_assert --xml junit-results/junit.xml --markdown --link-prefix ${{ github.event.repository.html_url }}/blob/${{ github.sha }}/ --link-line-separator \#L >> "$GITHUB_STEP_SUMMARY"
python -m tests.process_junit --type time_out_assert --xml junit-results/junit.xml --markdown --link-prefix ${{ github.event.repository.html_url }}/blob/${{ github.sha }}/ --link-line-separator \#L >> junit-results/time_out_assert.md
python -m chia._tests.process_junit --limit 50 --type time_out_assert --xml junit-results/junit.xml --markdown --link-prefix ${{ github.event.repository.html_url }}/blob/${{ github.sha }}/ --link-line-separator \#L >> "$GITHUB_STEP_SUMMARY"
python -m chia._tests.process_junit --type time_out_assert --xml junit-results/junit.xml --markdown --link-prefix ${{ github.event.repository.html_url }}/blob/${{ github.sha }}/ --link-line-separator \#L >> junit-results/time_out_assert.md

- name: Publish JUnit results
if: always()
Expand All @@ -190,13 +190,13 @@ jobs:
if: always()
run: |
set -o pipefail
coverage report --rcfile=.coveragerc --data-file=coverage-reports/.coverage --include='chia/**/*' --show-missing | tee coverage-reports/coverage-chia-stdout
coverage report --rcfile=.coveragerc --data-file=coverage-reports/.coverage --include='chia/**/*' --omit='chia/_tests/**/*' --show-missing | tee coverage-reports/coverage-chia-stdout

- name: Coverage report (tests/)
- name: Coverage report (chia/_tests/)
if: always()
run: |
set -o pipefail
coverage report --rcfile=.coveragerc --data-file=coverage-reports/.coverage --include='tests/**/*' --show-missing | tee coverage-reports/coverage-tests-stdout
coverage report --rcfile=.coveragerc --data-file=coverage-reports/.coverage --include='chia/_tests/**/*' --show-missing | tee coverage-reports/coverage-tests-stdout

- name: Coverage report (diff)
if: (github.base_ref != '' || github.event.before != '') && always()
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/upload-pypi-source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ jobs:
- name: black
command: black --check --diff .
- name: flake8
command: flake8 benchmarks build_scripts chia tests tools *.py
command: flake8 benchmarks build_scripts chia tools *.py
- name: pylint
command: pylint benchmarks build_scripts chia tests tools *.py
command: pylint benchmarks build_scripts chia tools *.py
- name: generated protocol tests
command: |
python3 -m tests.util.build_network_protocol_files
python3 -m chia._tests.util.build_network_protocol_files
git diff --exit-code

steps:
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ repos:
hooks:
- id: check-sql
name: Validate SQL statements
entry: ./activated.py python -m tests.check_sql_statements
entry: ./activated.py python -m chia._tests.check_sql_statements
language: system
pass_filenames: false
- repo: local
hooks:
- id: init_py_files
name: __init__.py files
entry: ./activated.py python tests/build-init-files.py -v --root .
entry: ./activated.py python chia/_tests/build-init-files.py -v --root .
language: system
pass_filenames: false
- repo: local
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ provided configuration with `pre-commit install`.
4. Preferences > Settings > Python > Linting > flake8 enabled
5. Preferences > Settings > Python > Linting > mypy enabled
6. Preferences > Settings > Formatting > Python > Provider > black
7. Preferences > Settings > mypy > Targets: set to `./chia` and `./tests`
7. Preferences > Settings > mypy > Targets: set to `./chia`

## Configure Pycharm

Expand Down
22 changes: 11 additions & 11 deletions benchmarks/block_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
from typing import List

from benchmarks.utils import setup_db
from chia._tests.util.benchmarks import (
clvm_generator,
rand_bytes,
rand_class_group_element,
rand_g1,
rand_g2,
rand_hash,
rand_vdf,
rand_vdf_proof,
rewards,
)
from chia.consensus.block_record import BlockRecord
from chia.full_node.block_store import BlockStore
from chia.types.blockchain_format.foliage import Foliage, FoliageBlockData, FoliageTransactionBlock, TransactionsInfo
Expand All @@ -20,17 +31,6 @@
from chia.types.blockchain_format.sub_epoch_summary import SubEpochSummary
from chia.types.full_block import FullBlock
from chia.util.ints import uint8, uint32, uint64, uint128
from tests.util.benchmarks import (
clvm_generator,
rand_bytes,
rand_class_group_element,
rand_g1,
rand_g2,
rand_hash,
rand_vdf,
rand_vdf_proof,
rewards,
)

# to run this benchmark:
# python -m benchmarks.coin_store
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/blockchains.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from subprocess import check_call
from typing import Iterator

from chia._tests.util.blockchain import persistent_blocks
from chia.simulator.block_tools import create_block_tools_async, test_constants
from chia.simulator.keyring import TempKeyring
from chia.util.keyring_wrapper import KeyringWrapper
from tests.util.blockchain import persistent_blocks


@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/coin_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
from typing import List, Tuple

from benchmarks.utils import setup_db
from chia._tests.util.benchmarks import rand_hash, rewards
from chia.full_node.coin_store import CoinStore
from chia.types.blockchain_format.coin import Coin
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.util.ints import uint32, uint64
from tests.util.benchmarks import rand_hash, rewards

# to run this benchmark:
# python -m benchmarks.coin_store
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/jsonify.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import random
from time import perf_counter

from tests.util.test_full_block_utils import get_full_blocks
from chia._tests.util.test_full_block_utils import get_full_blocks

random.seed(123456789)

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/streamable.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import click

from benchmarks.utils import EnumType, get_commit_hash
from chia._tests.util.benchmarks import rand_bytes, rand_full_block, rand_hash
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.types.full_block import FullBlock
from chia.util.ints import uint8, uint64
from chia.util.streamable import Streamable, streamable
from tests.util.benchmarks import rand_bytes, rand_full_block, rand_hash

# to run this benchmark:
# python -m benchmarks.streamable
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
from chia_rs import AugSchemeMPL, G2Element
from clvm.casts import int_to_bytes

from chia._tests.blockchain.blockchain_test_utils import (
_validate_and_add_block,
_validate_and_add_block_multi_error,
_validate_and_add_block_multi_result,
_validate_and_add_block_no_error,
check_block_store_invariant,
)
from chia._tests.conftest import ConsensusMode
from chia._tests.util.blockchain import create_blockchain
from chia.consensus.block_body_validation import ForkInfo
from chia.consensus.block_header_validation import validate_finished_header_block
from chia.consensus.block_record import BlockRecord
Expand Down Expand Up @@ -53,15 +62,6 @@
DEFAULT_HIDDEN_PUZZLE_HASH,
calculate_synthetic_secret_key,
)
from tests.blockchain.blockchain_test_utils import (
_validate_and_add_block,
_validate_and_add_block_multi_error,
_validate_and_add_block_multi_result,
_validate_and_add_block_no_error,
check_block_store_invariant,
)
from tests.conftest import ConsensusMode
from tests.util.blockchain import create_blockchain

log = logging.getLogger(__name__)
bad_element = ClassgroupElement.create(b"\x00")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import pytest
from clvm.casts import int_to_bytes

from chia._tests.blockchain.blockchain_test_utils import _validate_and_add_block
from chia._tests.util.generator_tools_testing import run_and_get_removals_and_additions
from chia.full_node.full_node_api import FullNodeAPI
from chia.protocols import wallet_protocol
from chia.server.server import ChiaServer
Expand All @@ -18,8 +20,6 @@
from chia.util.errors import ConsensusError, Err
from chia.util.ints import uint32, uint64
from chia.wallet.conditions import AssertCoinAnnouncement, AssertPuzzleAnnouncement
from tests.blockchain.blockchain_test_utils import _validate_and_add_block
from tests.util.generator_tools_testing import run_and_get_removals_and_additions

BURN_PUZZLE_HASH = bytes32(b"0" * 32)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

import pytest

from chia._tests.util.benchmarks import rand_hash
from chia.consensus.block_record import BlockRecord
from chia.consensus.blockchain_interface import BlockchainInterface
from chia.consensus.find_fork_point import find_fork_point_in_chain, lookup_fork_chain
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.util.ints import uint32
from tests.util.benchmarks import rand_hash


class DummyChain:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# Create missing `__init__.py` files in the source code folders (in "chia/" and "tests/").
# Create missing `__init__.py` files in the source code folders (in "chia/").
#
# They are required by the python interpreter to properly identify modules/packages so that tools like `mypy` or an IDE
# can work with their full capabilities.
Expand Down Expand Up @@ -64,7 +64,7 @@ def command(verbose, root_str):
stream_handler = logging.StreamHandler()
logger.addHandler(stream_handler)

tree_roots = ["benchmarks", "build_scripts", "chia", "tests", "tools"]
tree_roots = ["benchmarks", "build_scripts", "chia", "tools"]
failed = False
root = pathlib.Path(root_str).resolve()
directories = [
Expand Down
16 changes: 11 additions & 5 deletions tests/build-job-matrix.py → chia/_tests/build-job-matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import testconfig

root_path = Path(__file__).parent.absolute()
project_root_path = root_path.parent
project_root_path = root_path.parent.parent


def skip(path: Path) -> bool:
return any(part.startswith(("_", ".")) for part in path.parts)
return any(part.startswith(("_", ".")) and part != "_tests" for part in path.parts)


def subdirs(per: str) -> List[Path]:
Expand Down Expand Up @@ -113,13 +113,19 @@ def update_config(parent: Dict[str, Any], child: Dict[str, Any]) -> Dict[str, An
for path, index in test_paths_with_index:
if path.is_dir():
test_files = sorted(path.glob("test_*.py"))
test_file_paths = [file.relative_to(project_root_path) for file in test_files]
paths_for_cli = " ".join(path.as_posix() for path in test_file_paths)
paths_for_cli_list = [file.relative_to(project_root_path) for file in test_files]
config_path = path
else:
paths_for_cli = path.relative_to(project_root_path).as_posix()
paths_for_cli_list = [path.relative_to(project_root_path)]
config_path = path.parent

def mung_path(path: Path) -> str:
# TODO: shell escaping, but that's per platform...
return ".".join(path.with_suffix("").parts)

paths_for_cli = " ".join(mung_path(path) for path in paths_for_cli_list)
paths_for_cli = f"--pyargs {paths_for_cli}"

try:
conf = update_config(module_dict(testconfig), dir_config(config_path))
except SpecifiedDefaultsError as e:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from chia_rs import AugSchemeMPL, G1Element, G2Element

from chia._tests.util.key_tool import KeyTool
from chia.consensus.default_constants import DEFAULT_CONSTANTS
from chia.types.blockchain_format.program import Program
from chia.types.blockchain_format.sized_bytes import bytes32
Expand All @@ -20,7 +21,6 @@
p2_puzzle_hash,
)
from chia.wallet.puzzles.puzzle_utils import make_create_coin_condition
from tests.util.key_tool import KeyTool

from ..core.make_block_generator import int_to_public_key
from .coin_store import CoinStore, CoinTimestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import pytest
from chia_rs import AugSchemeMPL, G1Element, G2Element, PrivateKey

from chia._tests.clvm.test_puzzles import public_key_for_index, secret_exponent_for_index
from chia._tests.util.key_tool import KeyTool
from chia.clvm.spend_sim import CostLogger, SimClient, SpendSim, sim_and_client
from chia.consensus.default_constants import DEFAULT_CONSTANTS
from chia.types.blockchain_format.coin import Coin
Expand All @@ -17,8 +19,6 @@
from chia.util.ints import uint64
from chia.wallet.lineage_proof import LineageProof
from chia.wallet.puzzles import p2_conditions, p2_delegated_puzzle_or_hidden_puzzle
from tests.clvm.test_puzzles import public_key_for_index, secret_exponent_for_index
from tests.util.key_tool import KeyTool

"""
This test suite aims to test:
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from chia_rs import Coin, G2Element

import chia.cmds.wallet_funcs
from chia._tests.cmds.testing_classes import create_test_block_record
from chia.cmds.chia import cli as chia_cli
from chia.cmds.cmds_util import _T_RpcClient, node_config_section_names
from chia.consensus.block_record import BlockRecord
Expand All @@ -33,7 +34,6 @@
from chia.wallet.util.transaction_type import TransactionType
from chia.wallet.util.tx_config import CoinSelectionConfig, TXConfig
from chia.wallet.util.wallet_types import WalletType
from tests.cmds.testing_classes import create_test_block_record

# Any functions that are the same for every command being tested should be below.
# Functions that are specific to a command should be in the test file for that command.
Expand Down
File renamed without changes.
Loading
Loading