Skip to content

Commit

Permalink
refactor,test(fill): suggestions for x-dist-mode-fixture-collector #…
Browse files Browse the repository at this point in the history
…1118 (#1130)

* chore(fill): remove `--index` flag; it has no effect

The `--index` flag is of `store_true` type with default True; it's redundant.

* test(fill): remove unnecessary test parameter

* refactor(fill): group variable definitions for readability
  • Loading branch information
danceratopz authored Jan 27, 2025
1 parent 5536688 commit 787b910
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 55 deletions.
17 changes: 3 additions & 14 deletions src/pytest_plugins/filler/filler.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,6 @@ def pytest_addoption(parser: pytest.Parser):
type=str,
help="Specify a build name for the fixtures.ini file, e.g., 'stable'.",
)
test_group.addoption(
"--index",
action="store_true",
dest="generate_index",
default=True,
help="Generate an index file for all produced fixtures. By default this flag is set.",
)

test_group.addoption(
"--skip-index",
action="store_false",
Expand Down Expand Up @@ -774,25 +766,22 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus: int):
return

output: Path = session.config.getoption("output")
is_output_tarball = output.suffix == ".gz" and output.with_suffix("").suffix == ".tar"
output_dir = strip_output_tarball_suffix(output)

if is_output_stdout(output):
# Don't perform any further actions if the output is stdout.
return

output_dir = strip_output_tarball_suffix(output)
# Remove any lock files that may have been created.
for file in output_dir.rglob("*.lock"):
file.unlink()

# Generate index file for all produced fixtures.
generate_index = session.config.getoption("generate_index")
if generate_index:
if session.config.getoption("generate_index"):
generate_fixtures_index(
output_dir, quiet_mode=True, force_flag=False, disable_infer_format=False
)

# Create tarball of the output directory if the output is a tarball.
is_output_tarball = output.suffix == ".gz" and output.with_suffix("").suffix == ".tar"
if is_output_tarball:
source_dir = output_dir
tarball_filename = output
Expand Down
50 changes: 9 additions & 41 deletions src/pytest_plugins/filler/tests/test_filler.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_shanghai_two(state_test, x):

@pytest.mark.run_in_serial
@pytest.mark.parametrize(
"args, expected_fixture_files, expected_fixture_counts, expected_index",
"args, expected_fixture_files, expected_fixture_counts",
[
pytest.param(
[],
Expand All @@ -102,33 +102,8 @@ def test_shanghai_two(state_test, x):
Path("fixtures/state_tests/shanghai/module_shanghai/shanghai_two.json"),
],
[2, 2, 2, 2, 2, 2, 2, 2, 2, 6, 6, 6],
True,
id="default-args",
),
pytest.param(
["--index"],
[
Path("fixtures/blockchain_tests/paris/module_paris/paris_one.json"),
Path("fixtures/blockchain_tests_engine/paris/module_paris/paris_one.json"),
Path("fixtures/state_tests/paris/module_paris/paris_one.json"),
Path("fixtures/blockchain_tests/paris/module_paris/paris_two.json"),
Path("fixtures/blockchain_tests_engine/paris/module_paris/paris_two.json"),
Path("fixtures/state_tests/paris/module_paris/paris_two.json"),
Path("fixtures/blockchain_tests/shanghai/module_shanghai/shanghai_one.json"),
Path(
"fixtures/blockchain_tests_engine/shanghai/module_shanghai/shanghai_one.json"
),
Path("fixtures/state_tests/shanghai/module_shanghai/shanghai_one.json"),
Path("fixtures/blockchain_tests/shanghai/module_shanghai/shanghai_two.json"),
Path(
"fixtures/blockchain_tests_engine/shanghai/module_shanghai/shanghai_two.json"
),
Path("fixtures/state_tests/shanghai/module_shanghai/shanghai_two.json"),
],
[2, 2, 2, 2, 2, 2, 2, 2, 2, 6, 6, 6],
True,
id="index-flag",
),
pytest.param(
["--skip-index"],
[
Expand All @@ -150,11 +125,10 @@ def test_shanghai_two(state_test, x):
Path("fixtures/state_tests/shanghai/module_shanghai/shanghai_two.json"),
],
[2, 2, 2, 2, 2, 2, 2, 2, 2, 6, 6, 6],
False,
id="skip-index",
),
pytest.param(
["--index", "--build-name", "test_build"],
["--build-name", "test_build"],
[
Path("fixtures/blockchain_tests/paris/module_paris/paris_one.json"),
Path("fixtures/blockchain_tests_engine/paris/module_paris/paris_one.json"),
Expand All @@ -174,11 +148,10 @@ def test_shanghai_two(state_test, x):
Path("fixtures/state_tests/shanghai/module_shanghai/shanghai_two.json"),
],
[2, 2, 2, 2, 2, 2, 2, 2, 2, 6, 6, 6],
True,
id="build-name-in-fixtures-ini-file",
),
pytest.param(
["--flat-output", "--index"],
["--flat-output"],
[
Path("fixtures/blockchain_tests/paris_one.json"),
Path("fixtures/blockchain_tests_engine/paris_one.json"),
Expand All @@ -194,11 +167,10 @@ def test_shanghai_two(state_test, x):
Path("fixtures/state_tests/shanghai_two.json"),
],
[2, 2, 2, 2, 2, 2, 2, 2, 2, 6, 6, 6],
True,
id="flat-output",
),
pytest.param(
["--flat-output", "--index", "--output", "other_fixtures"],
["--flat-output", "--output", "other_fixtures"],
[
Path("other_fixtures/blockchain_tests/paris_one.json"),
Path("other_fixtures/blockchain_tests_engine/paris_one.json"),
Expand All @@ -214,11 +186,10 @@ def test_shanghai_two(state_test, x):
Path("other_fixtures/state_tests/shanghai_two.json"),
],
[2, 2, 2, 2, 2, 2, 2, 2, 2, 6, 6, 6],
True,
id="flat-output_custom-output-dir",
),
pytest.param(
["--single-fixture-per-file", "--index"],
["--single-fixture-per-file"],
[
Path(
"fixtures/blockchain_tests/paris/module_paris/paris_one__fork_Paris_blockchain_test.json"
Expand Down Expand Up @@ -330,11 +301,10 @@ def test_shanghai_two(state_test, x):
),
],
[1] * 36,
True,
id="single-fixture-per-file",
),
pytest.param(
["--single-fixture-per-file", "--index", "--output", "other_fixtures"],
["--single-fixture-per-file", "--output", "other_fixtures"],
[
Path(
"other_fixtures/blockchain_tests/paris/module_paris/paris_one__fork_Paris_blockchain_test.json"
Expand Down Expand Up @@ -446,11 +416,10 @@ def test_shanghai_two(state_test, x):
),
],
[1] * 36,
True,
id="single-fixture-per-file_custom_output_dir",
),
pytest.param(
["--flat-output", "--index", "--single-fixture-per-file"],
["--flat-output", "--single-fixture-per-file"],
[
Path("fixtures/blockchain_tests/paris_one__fork_Paris_blockchain_test.json"),
Path("fixtures/state_tests/paris_one__fork_Paris_state_test.json"),
Expand Down Expand Up @@ -526,13 +495,12 @@ def test_shanghai_two(state_test, x):
),
],
[1] * 36,
True,
id="flat-single-per-file_flat-output",
),
],
)
def test_fixture_output_based_on_command_line_args(
testdir, args, expected_fixture_files, expected_fixture_counts, expected_index
testdir, args, expected_fixture_files, expected_fixture_counts
):
"""
Test:
Expand Down Expand Up @@ -619,7 +587,7 @@ def test_fixture_output_based_on_command_line_args(
config = configparser.ConfigParser()
config.read(ini_file)

if expected_index:
if "--skip-index" not in args:
assert index_file is not None, f"No {expected_index_file} file was found in {meta_dir}"

properties = {key: value for key, value in config.items("fixtures")}
Expand Down

0 comments on commit 787b910

Please sign in to comment.