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

feat(api): add method read_study_api #22

Merged
merged 42 commits into from
Dec 4, 2024
Merged

Conversation

mehdiwahada
Copy link
Contributor

No description provided.

mehdiwahada and others added 30 commits November 26, 2024 14:53
@MartinBelthle MartinBelthle changed the title Feat/read study api feat(api): add method read_study Dec 2, 2024

assert study.service.study_id == actual_study.service.study_id
assert study.name == actual_study.name
assert study.version == actual_study.version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also test that the 2 studies contain the same areas name. And the same settings (just test some values if the == doesn't work)


study_name = json_study.pop("name")
study_version = str(json_study.pop("version"))
json_study.pop("id")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you remove id ?

src/antares/model/study.py Show resolved Hide resolved
with requests_mock.Mocker() as mocker:
mocker.get(url, json=json_study)
mocker.get(config_urls, json={})
mocker.get(area_url, json={})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could change this to make it return an area to test even further that the created study has an area

@@ -194,7 +211,13 @@ def service(self) -> BaseStudyService:
return self._study_service

def read_areas(self) -> list[Area]:
return self._area_service.read_areas()
"""
Syncronize the internal study object with the object written in an antares study
Copy link
Contributor

@MartinBelthle MartinBelthle Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: Synchronize, also you can add with the actual written etc.
Also you can either remove the Return: or finish your sentence :)

assert study.service.study_id == actual_study.service.study_id
assert study.name == actual_study.name
assert study.version == actual_study.version
assert study.get_areas()["fr"].id == actual_study.get_areas()["fr"].id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer you check that list(study.get_areas.keys()) == list(actual_study.get_areas.keys()).
Also, for the first area of the list, it could be nice to ensure that the areas contain the same renewable and clusters (just check the names)

Copy link
Contributor

@MartinBelthle MartinBelthle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 comments and we're good to go

}
}

json_thermal = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To simplify your test you can just replace the json you introduce by:

json_thermal = []
json_renewable = []
json_st_storage = []
json_properties = {}

and your test will still pass.
You can even remove these variables and simply pur the [] or {} inside the .get() to make it even simpler

assert study.name == actual_study.name
assert study.version == actual_study.version
assert list(study.get_areas().keys()) == list(actual_study.get_areas().keys())
assert (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better. You can introduce
actual_area_fr = actual_study.get_areas()["fr"] and expected_area_fr = study.get_areas()["fr"] to avoid calling get_areas multiple times.
Also I would prefer you do the same check as the ones for areas (line 228) for thermal, storages and renewables as it would check more things.
Last thing, I believe you can also check the settings

@MartinBelthle MartinBelthle changed the title feat(api): add method read_study feat(api): add method read_study_api Dec 4, 2024
@MartinBelthle MartinBelthle merged commit 795d14d into main Dec 4, 2024
8 checks passed
@MartinBelthle MartinBelthle deleted the feat/read_study_api branch December 4, 2024 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants