Skip to content

Commit

Permalink
Merge pull request #262 from PowerGridModel/feature/disable_pandapowe…
Browse files Browse the repository at this point in the history
…r_converter_test_writes

Feature / fix the pandapower test write to existing file
  • Loading branch information
Jerry-Jinfeng-Guo authored Jul 5, 2024
2 parents 15c5574 + 73d605f commit 9e0af9a
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions tests/validation/converters/test_pandapower_converter_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#
# SPDX-License-Identifier: MPL-2.0

import os
from contextlib import contextmanager
from functools import lru_cache
from pathlib import Path
from typing import Tuple
Expand All @@ -21,6 +23,14 @@
PGM_ASYM_OUTPUT_FILE = Path(__file__).parents[2] / "data" / "pandapower" / "pgm_asym_output_data.json"


@contextmanager
def temporary_file_cleanup(file_path):
try:
yield
finally:
os.remove(file_path)


@lru_cache
def load_and_convert_pgm_data() -> PandaPowerData:
"""
Expand Down Expand Up @@ -92,8 +102,10 @@ def test_generate_output(): # TODO: REMOVE THIS FUNCTION
assert_valid_input_data(input_data=input_data)
pgm = PowerGridModel(input_data=input_data)
output_data = pgm.calculate_power_flow()
json_converter = PgmJsonConverter(destination_file=PGM_OUTPUT_FILE)
json_converter.save(data=output_data, extra_info=extra_info)
temp_file = PGM_OUTPUT_FILE.with_name(PGM_OUTPUT_FILE.stem + "_temp").with_suffix(".json")
with temporary_file_cleanup(temp_file):
json_converter = PgmJsonConverter(destination_file=temp_file)
json_converter.save(data=output_data, extra_info=extra_info)


def test_generate_output_3ph(): # TODO: REMOVE THIS FUNCTION
Expand All @@ -107,8 +119,10 @@ def test_generate_output_3ph(): # TODO: REMOVE THIS FUNCTION
assert_valid_input_data(input_data=input_data, symmetric=False)
pgm = PowerGridModel(input_data=input_data)
output_data_asym = pgm.calculate_power_flow(symmetric=False)
json_converter = PgmJsonConverter(destination_file=PGM_ASYM_OUTPUT_FILE)
json_converter.save(data=output_data_asym, extra_info=extra_info)
temp_file = PGM_ASYM_OUTPUT_FILE.with_name(PGM_ASYM_OUTPUT_FILE.stem + "_temp").with_suffix(".json")
with temporary_file_cleanup(temp_file):
json_converter = PgmJsonConverter(destination_file=temp_file)
json_converter.save(data=output_data_asym, extra_info=extra_info)


def test_output_data(output_data: Tuple[PandaPowerData, PandaPowerData]):
Expand Down

0 comments on commit 9e0af9a

Please sign in to comment.