-
Notifications
You must be signed in to change notification settings - Fork 16
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
Cdf attribute tests #637
Cdf attribute tests #637
Conversation
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 like a great first start! Not approving only because it's a draft rn, but it's looking really good!
@@ -0,0 +1,23 @@ | |||
default_attrs: &default |
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.
These YAML files look good, but they should go under tests/
Logical_source_description: IMAP Mission MAGi Normal Rate Instrument Level-1A Data. | ||
|
||
|
||
imap_test_section_5: |
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 don't need more than 2 imap_test_sections IMO. What is adding additional sections adding from a test perspective? One test is good to validate that you can get into the section. Two is good to validate that you can choose between the sections. But adding additional sections doesn't test anything extra.
|
||
# Default global tests | ||
# Check false case | ||
assert cdf_manager.global_attribute_schema["DOI"]["required"] is False |
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.
It's a very minor thing, but you can also check falseness by saying assert not [statement]
or check trueness with assert [statement]
cdf_manager = CdfAttributeManager(Path(__file__).parent.parent / "config") | ||
# Test that default information was loaded in from "imap_default_global_cdf_attrs.yaml" |
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.
hm, this might actually be a bug within CdfAttributeManger
. I don't think it should load in any information to start. This is irrelevant to your PR, just a mental note for me to go back and fix that
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.
Ah! Okay, I see. This is the code that shows information is loaded in:
# Load Default IMAP Global Attributes self.global_attributes = CdfAttributeManager._load_yaml_data( self.source_dir / DEFAULT_GLOBAL_CDF_ATTRS_FILE ) self.variable_attributes = dict()
That is line 78 in cdf_attribute_manager.py, and DEFAULT_GLOBAL_CDF_ATTRS_FILE is defined as
DEFAULT_GLOBAL_CDF_ATTRS_FILE = "imap_default_global_cdf_attrs.yaml"
in line 12.
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.
Hmm ok in that case, leave this test in, but I probably will want to update that lol
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.
Should not block or really affect you
cdf_manager.load_global_attributes("imap_default_global_cdf_attrs.yaml") | ||
# Load in different data, test what was carried over | ||
cdf_manager.load_global_attributes("imap_default_global_test_cdf_attrs.yaml") | ||
assert cdf_manager.global_attributes["Project"] == "STP>Solar-Terrestrial Physics" |
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.
Nice
|
||
# test add_instrument_global_attrs(self, instrument: str): | ||
|
||
|
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.
Nice, I like this file, but don't add much more than this to it. ImapCdfAttributes is very minimal, and you don't want to duplicate tests. Really, the only test needed is that self.source_dir
is set correctly, because right now that's the only thing done in ImapCdfAttributes, with everything else needing to be tested in test_cdf_attribute_manager
@@ -164,9 +197,6 @@ def test_global_attribute(): | |||
if required_schema is True: | |||
assert attr_name in test_get_global_attrs.keys() | |||
|
|||
# Testing second elif statement | |||
# Should throw error |
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.
If this is testing that the code successfully throws an error, you can use pytest.raises
. If this test is failing because the code it's testing is incomplete or wrong, but it shouldn't, that's when you use pytest.mark.xfail
. Basically, if someone should come back and fix it, xfail
is your friend.
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.
Not done with my review yet - but nice work!
if source_dir_input is None: | ||
super().__init__(Path(__file__).parent / "config") | ||
else: | ||
super().__init__(Path(__file__).parent / "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.
You should pass the source_dir_input into the super() init function because there are steps in __init__
that depend on the source_dir and it would be confusing to have it set to different values for the init vs for the rest of processing.
Then you can remove line 21
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 has actually been causing me a lot of weird struggles with testing this class. In CdfAttributeManager , the default schema and IMAPS default variables are in the "config" file path and not guaranteed in the source_dir_input file path. I can't get the tests to run correctly without loading in that default info first, and then switching the file path... Thoughts?
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.
In those tests, you can pass in the "config" path (or pass in nothing and use the default) and then override it. This way it will still get the default schemas and global variables from "config" but you can also access your test files in the other file path.
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.
Hahaha, happy to say I just got it. Thank you so much! I see now.
imap_processing/cdf/tests/imap_instrument2_global_cdf_attrs.yaml
Outdated
Show resolved
Hide resolved
imap_processing/cdf/tests/imap_instrument2_level2_variable_attrs.yaml
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,246 @@ | |||
DOI: |
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.
Is there any way/is it reasonable to use the real schema? I know this goes back to the source_dir question again, but I think it would be valuable to test against the real schema - because if that ever changes, and the person updating doesn't realize that the file is duplicated in the tests, it could cause issues.
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.
Yes! Sorry, I actually am using the real schema, I should have deleted these files. This is why we have to initially set the CdfAttributeManager.source_dir to end in the "config" folder to get those real schema...
imap_processing/cdf/tests/shared/default_variable_cdf_attrs_schema_test.yaml
Outdated
Show resolved
Hide resolved
# Testing that required schema keys are in get_global_attributes | ||
for attr_name in cdf_manager.global_attribute_schema.keys(): | ||
required_schema = cdf_manager.global_attribute_schema[attr_name]["required"] | ||
if required_schema is True: |
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.
Nice
cdf_manager.add_global_attribute("Project", "Test Project") | ||
assert cdf_manager.global_attributes["Project"] == "Test Project" | ||
test_get_global_attrs = cdf_manager.get_global_attributes("imap_test_T1_test") | ||
assert test_get_global_attrs["Project"] == "Test Project" |
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.
Nice test, I like it. Can you also add a test for adding a new attribute that didn't exist in the file? For example, delete one of the required attributes (you can delete it out of cdf_manager.global_attributes) and then assert that get_global_attributes
fails for that attribute, then run add_global_attribute
and assert that it now exists.
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.
Yeah! You will see the updated test in some of my new pushes, but I did have a few questions about this:
- The code in get_global_attributes does not throw an error if a required attribute is missing, it just sets that attribute to
None
. Shall this be changed in the method definition? - I can't add attributes that are instrument specific because all instrument specific data is accessed through dictionary objects. and not CdfAttributeManager objects (such as
cdf_manager.global_attributes["instrument"]
orinstrument = cdf_manager.get_global_attributes("instrument)
). Is that okay?
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.
- No, don't change the code, but instead validate that it's None.
- You can add instrument specific attributes through
add_global_attribute
because the global attributes are flat and contain the global attributes for the instruments and for the shared values.
I'm not totally sure I understand your second question, did I answer it?
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.
Ah. I think I got it now, thanks!
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.
Finished review, ping me when you're ready for another one! Also, let me know if you want to meet to discuss any of this since there are some larger questions here that might be easier to have a conversation about.
cdf_manager.add_global_attribute("Project", "Test Project") | ||
assert cdf_manager.global_attributes["Project"] == "Test Project" | ||
test_get_global_attrs = cdf_manager.get_global_attributes("imap_test_T1_test") | ||
assert test_get_global_attrs["Project"] == "Test Project" |
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.
- No, don't change the code, but instead validate that it's None.
- You can add instrument specific attributes through
add_global_attribute
because the global attributes are flat and contain the global attributes for the instruments and for the shared values.
I'm not totally sure I understand your second question, did I answer it?
assert imap_instrument["Data_type"] == "T1_test-one>Test-1 test one" | ||
assert imap_instrument["Project"] == "STP>Solar-Terrestrial Physics" | ||
|
||
# Testing reloading data |
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 already tested in the test_cdf_attribute_manager code - most of these tests are somewhat duplicating it. It's ok to have some duplicate tests, but generally, you should really try to focus in and make sure you only have one test per thing. If we changed the way we add global attrs, we would have to go and update 2 tests that test the same thing, so it's a little annoying.
This isn't a blocker for me since this test file is pretty minimal - so I will leave it up to your judgement which tests are duplicating and which ones are adding value. Just wanted to point that out as something to think about.
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.
The particular reason I included both of these tests is because they are loaded in from different files. That being said though, I definitely hear what you are saying. I'll rake through my tests, and get rid of the silly ones.
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.
Nice work! Really really close now, if you address my newest comments then you can go ahead and merge! Congrats for making it through the first review thunderdome 😁
imap_cdf_manager = ImapCdfAttributes("tests") | ||
# Create an ImapCdfAttributes object, set to correct file path | ||
imap_cdf_manager = ImapCdfAttributes() | ||
imap_cdf_manager.source_dir = Path(__file__).parent.parent / "tests" |
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.
Nice
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.
Awesome work! I just have a few non-blocking nit-picky suggestions, if you so chose to accept them.
Mission_group: Dysfunctional Cats | ||
PI_name: Ana Manica |
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.
Nice 😂
This file is nothing more than a test yamal. This description? This is a test description. | ||
This Testinstrument will contribute to our understanding of the cdf_attribute_manager.py file. | ||
This test file is led by me, Ana Manica. Lasp undergraduate employee. | ||
I don't have a website. Sorry. |
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.
Beautifully written 😂
imap_processing/cdf/tests/imap_instrument_global_cdf_attrs.yaml
Outdated
Show resolved
Hide resolved
"CATDESC", | ||
"DEPEND_0", | ||
"DISPLAY_TYPE", | ||
"FIELDNAM", | ||
"FILLVAL", | ||
"FORMAT", | ||
"LABLAXIS", | ||
"UNITS", |
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.
Yay for alphabetical order!
951d0dc
to
4a7712a
Compare
d012a9b
into
IMAP-Science-Operations-Center:dev
Change Summary
Overview
Creating CDF attribute code tests for the two files:
1.) cdf_attribute_manager.py
2.) imap_cdf_manager.py
New Dependencies
None
New Files
For CDF Attribute Manager:
For IMAP CDF Manager
Deleted Files
None
Updated Files
__init__
so that I could reach my test files while also preserving the API.Testing
The purpose of this ticket is to specifically create unit tests, and thus all the work this ticket is unit testing.
closes #592