Skip to content

Commit 002cd0a

Browse files
committed
Ensure function name is saved to JSON
1 parent 39223ed commit 002cd0a

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

ratapi/project.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,12 +956,16 @@ def make_data_dict(item):
956956
elif field == "custom_files":
957957

958958
def make_custom_file_dict(item):
959-
return {
959+
file_dict = {
960960
"name": item.name,
961961
"filename": item.filename,
962962
"language": item.language,
963963
"path": try_relative_to(item.path, filepath.parent),
964964
}
965+
if item.name != item.function_name:
966+
file_dict["function_name"] = item.function_name
967+
968+
return file_dict
965969

966970
json_dict["custom_files"] = [make_custom_file_dict(file) for file in attr]
967971

tests/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8537,3 +8537,11 @@ def absorption():
85378537
"""The project from the absorption example."""
85388538
project, _ = ratapi.examples.absorption()
85398539
return project
8540+
8541+
8542+
@pytest.fixture
8543+
def absorption_different_function():
8544+
"""The project from the absorption example with a function name different from filename."""
8545+
project, _ = ratapi.examples.absorption()
8546+
project.custom_files[0].function_name = "test_func"
8547+
return project

tests/test_project.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,7 @@ def test_wrap_extend(test_project, class_list: str, model_type: str, field: str,
16161616
"domains_custom_layers",
16171617
"domains_custom_xy",
16181618
"absorption",
1619+
"absorption_different_function",
16191620
],
16201621
)
16211622
def test_save_load(project, request):

0 commit comments

Comments
 (0)