-
-
Notifications
You must be signed in to change notification settings - Fork 409
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
[TEP014] Update Model and Density classes to use HDFWriter + Unit Tests #747
Conversation
@wkerzendorf Please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall but I'd suggest some changes to make implementing the tests for the other classes easier and to follow the Don't Repeat Yourself
principle of python.
Another change I'd like to see which is not directly tied to this PR but could be implemented here, is changing the name of HDFWriter
to HDFWriterMixin
. This would then correctly reflect that HDFWriter
is only a utility class and not the common Root for all our classes.
tardis/model/base.py
Outdated
from density import HomologousDensity | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Radial1DModel(object): | ||
class Radial1DModel(HDFWriter, object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove object
since it is not needed here.
tardis/model/tests/test_base.py
Outdated
|
||
|
||
@pytest.fixture(scope="module") | ||
def hdf_file_path(tmpdir_factory): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should define a top level fixture in conftest.py
that can be used by all test modules. That way you only have to write this code once and if it needs changes, you only have to change one instance of it.
tardis/model/tests/test_base.py
Outdated
|
||
|
||
@pytest.fixture(scope="module") | ||
def actual_model(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can have this as a top level fixture, too? See above.
tardis/model/tests/test_base.py
Outdated
|
||
|
||
@pytest.fixture(scope="module", autouse=True) | ||
def to_hdf_buffer(hdf_file_path, actual_model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an interesting way to achieve that the model is saved, however I'd prefer if there was a fixture that either returns the filename or the buffer the data was saved to.
Someone not very familiar with the internal workings of pytest
might not understand what's happening here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yeganer If I return hdf buffer path
from this function , then it same as input argument hdf_file_path
. I think , If I return hdf_file_path
here , then it is inconsistent .
tardis/model/tests/test_density.py
Outdated
|
||
### | ||
# Save and Load | ||
### |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See remarks for test_model.py
. Most apply here aswell
@vg3095 I haven't had the time to look in depth at the latest changes. Can you please explain, why you had to revert the name changes? I'm confused... |
@yeganer , If I change For now , I am importing I will then, make a seperate PR for this afterwards. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good and goes into the right direction, good job!
Nevertheless I have some minor suggestions
tardis/conftest.py
Outdated
return model | ||
|
||
@pytest.fixture(scope="session") | ||
def homologous_density(hdf_config): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not say that homologous density is used anywhere else than the corresponding test
tardis/conftest.py
Outdated
return str(path) | ||
|
||
@pytest.fixture(scope="session") | ||
def hdf_config(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest a rename to config_verysimple
tardis/conftest.py
Outdated
return config | ||
|
||
@pytest.fixture(scope="session") | ||
def model(hdf_config): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you try to create a simulation_verysimple
fixture? If that works, then we can get a model by simulation_verysimple.model
and therefore we don't need additional fixtures.
Do you think, that could work?
@vg3095 You are right, the name change of I'd suggest you make a small PR containing the name change and then you rebase this PR and other on your name change PR. That way you can implement it correctly right from the start but you can keep the change separate. |
@yeganer Coverage is decreasing , due to usage of |
@vg3095 Looks good, however please remove the two commits which introduce the name change and then revert it in the next commit. You can delete, modify or merge commits with |
tardis/conftest.py
Outdated
|
||
@pytest.fixture(scope="session") | ||
def simulation_verysimple(config_verysimple, atomic_data_fname): | ||
atomic_data = AtomData.from_hdf5(atomic_data_fname) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know there is a problem with the atomic data and preparing it multiple times. I think we could solve this by having a session fixture that does AtomData.from_hdf(...)
and another function scope fixture that takes the first fixture and returns a copy.deepcopy
. Could that work?
@yeganer I created a separate session based |
The issue is fixed now. |
tardis/conftest.py
Outdated
'(md5="21095dd25faa1683f4c90c911a00c3f8"') | ||
|
||
sim = Simulation.from_config(config_verysimple, atom_data=atomic_data) | ||
def simulation_verysimple(config_verysimple, atomic_dataset): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are using the session
scoped atomic dataset fixture here. I believe you want to use kurucz_atomic_data
which is the one making use of the deepcopy
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yeganer kurucz_atomic_data
fixture is a function scope
fixture , that`s why It can`t be used for session based Simulation fixture
(It throws ScopeMismatch Error
) , that`s why , I used atomic_dataset
here(session based fixture
) and used deepcopy
to create a new copy for atomic dataset inside the function itself..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yeganer And you are seeing the old commit
@vg3095 can you rebase onto the current master |
@yeganer and @wkerzendorf signed off - will merge when tests pass |
No description provided.