Skip to content

Commit

Permalink
fix(fill): use .ini instead of .properties for build props file
Browse files Browse the repository at this point in the history
  • Loading branch information
danceratopz committed Jun 14, 2024
1 parent d1ee6ff commit e7a39c3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
22 changes: 12 additions & 10 deletions src/pytest_plugins/test_filler/test_filler.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def pytest_addoption(parser):
dest="build_name",
default=None,
type=str,
help="Specify a build name for the fixtures.properties file, e.g., 'stable'.",
help="Specify a build name for the fixtures.ini file, e.g., 'stable'.",
)

debug_group = parser.getgroup("debug", "Arguments defining debug behavior")
Expand Down Expand Up @@ -533,7 +533,8 @@ def output_dir(request, is_output_tarball: bool) -> Path:
@pytest.fixture(scope="session", autouse=True)
def create_properties_file(request, output_dir: Path) -> None:
"""
Create a properties file in the fixture output directory.
Creates an ini file with fixture build properties in the fixture output
directory.
"""
if is_output_stdout(request.config.getoption("output")):
return
Expand All @@ -559,16 +560,17 @@ def create_properties_file(request, output_dir: Path) -> None:
for key, val in request.config.stash[metadata_key].items():
if key.lower() == "command-line args":
continue
if isinstance(val, str):
if key.lower() in ["python", "platform"]:
environment_properties[key] = val
elif isinstance(val, dict):
config[key.lower()] = val
else:
warnings.warn(f"Properties file: Skipping metadata key {key} with value {val}.")
warnings.warn(f"Fixtures ini file: Skipping metadata key {key} with value {val}.")
config["environment"] = environment_properties

properties_filename = output_dir / "fixtures.properties"
with open(properties_filename, "w") as f:
ini_filename = output_dir / "fixtures.ini"
with open(ini_filename, "w") as f:
f.write("; This file describes fixture build properties\n\n")
config.write(f)


Expand All @@ -577,18 +579,18 @@ def create_tarball(
request, output_dir: Path, is_output_tarball: bool
) -> Generator[None, None, None]:
"""
Create a tarball of the output directory if the configured output ends
with '.tar.gz'.
Create a tarball of json files the output directory if the configured
output ends with '.tar.gz'.
Only include .json and .properties files in the archive.
Only include .json and .ini files in the archive.
"""
yield
if is_output_tarball:
source_dir = output_dir
tarball_filename = request.config.getoption("output")
with tarfile.open(tarball_filename, "w:gz") as tar:
for file in source_dir.rglob("*"):
if file.suffix in {".json", ".properties"}:
if file.suffix in {".json", ".ini"}:
arcname = file.relative_to(source_dir.parent)
tar.add(file, arcname=arcname)

Expand Down
13 changes: 7 additions & 6 deletions src/pytest_plugins/test_filler/tests/test_test_filler.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ 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],
id="build-name-in-properties-file",
id="build-name-in-fixtures-ini-file",
),
pytest.param(
["--flat-output"],
Expand Down Expand Up @@ -517,10 +517,11 @@ def test_fixture_output_based_on_command_line_args(

all_files = get_all_files_in_directory(output_dir)

properties_file = None
ini_file = None
expected_fixtures_ini_filename = "fixtures.ini"
for file in all_files:
if file.name == "fixtures.properties":
properties_file = file
if file.name == expected_fixtures_ini_filename:
ini_file = file
all_files.remove(file)
break

Expand All @@ -532,9 +533,9 @@ def test_fixture_output_based_on_command_line_args(
expected_fixture_files
), f"Unexpected files in directory: {set(all_files) - set(expected_fixture_files)}"

assert properties_file is not None, "No properties file was written"
assert ini_file is not None, f"No {expected_fixtures_ini_filename} file was written"
config = configparser.ConfigParser()
config.read(properties_file)
config.read(ini_file)

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

0 comments on commit e7a39c3

Please sign in to comment.