-
Notifications
You must be signed in to change notification settings - Fork 5
CI: test that runs pdf pack examples in CI #40
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
Conversation
.gitignore
Outdated
| docs/examples/ch*/solutions/diffpy-cmi/fig/* | ||
| docs/examples/ch*/solutions/diffpy-cmi/fit/* | ||
| docs/examples/ch*/solutions/diffpy-cmi/res/* | ||
|
|
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 examples create these dirs. This prevents any accidental commits of the 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 not good. This is precisely what we want to avoid (test-generated junk). How do the examples decide where to write these files? Can you copy the files to tmpdir and then run them?
| # If we want to run using multiprocessors, we can switch this to 'True'. | ||
| # This requires that the 'psutil' python package installed. | ||
| RUN_PARALLEL = True | ||
| RUN_PARALLEL = 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.
Requires psutil to be installed or it throws an 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.
We don't want to do this either. Is there a reason not to install psutil? or make it conditional on whether psutil is installed? We don't want to change the behavior of the examples just so the CI will run.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #40 +/- ##
===========================================
+ Coverage 50.00% 80.95% +30.95%
===========================================
Files 2 17 +15
Lines 18 1313 +1295
===========================================
+ Hits 9 1063 +1054
- Misses 9 250 +241
🚀 New features to boost your workflow:
|
|
Thanks @cadenmyers13 I didn't see this before, sorry about that. Thanks for looping it to me again. |
|
@sbillinge I tested this on my fork and the new test I wrote seem to pass (it just runs all tutorial scripts). I had to add special handling since one of the files depends on the Ni fit instrument params to get Qdamp and Qbroad. We could also just hard-code these values in but this seems to work. The downside to this test is that all the scripts take about 20 min to run on CI. This could get annoying for future PRs especially small ones. Let me know what you think of this. Im sending this message before it finishes running so hopefully it passes |
|
There is this codecov error being generated too. Might need to add a token |
|
Thanks for this @cadenmyers13 . I took a quick look and it looked as if we need to tweak it a bit but I haven't had time. Ideally we want to move everything inside pytest so it is using the teting framework and not running outside it. The testing framework is very good at setting up a kind of virtual testing environment, running all the tests, then tearing it down and deleting everything. It has to do it in a way that if anything crashes during the test, the tear-down still takes place, or your computer gets junked up with unwanted stuff. Maybe you can look again with this new view and see if it makes sense what I am saying. Another aspect of this is getting things to run on all platforms which is hard if you are using command-line calls. It is better if you can do the "command line" call by by calling the main function in the entry-point app. little tricks like that. I am not sure how well it translates to your nice script but just a few things to look for.... |
|
@sbillinge ready for review when you've got a chance. |
sbillinge
left a comment
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 definitely getting better. Nice that you are using type hints.....the first in the group to do so! very advanced.....
I wonder if we want to just glob the examples directory instead of doing it this way?. This would be less work to maintain if we can figure it out because if we add new examples in the future they will automatically get tested.
tests/test_ch03.py
Outdated
| @pytest.mark.parametrize( | ||
| "relative_path", | ||
| [ | ||
| f"{__examples_dir__}/ch03NiModelling" |
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.
please use our pattern if you can that has a comment that mentions what is being tested and what the expected behavior is.
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.
done
I saw tieqiong doing this and thought i'd try!
I globbed each chapter dir. Since its now been broken out into separate tests for each chapter, there will be some maintenance if we add a chapter. But if new scripts are added to a chapter that already exists, this should run it. @sbillinge ready for review |
|
@sbillinge ready for review I added the meta-test and tested many different configurations of filenames and dir names. got expected behavior. |
| print("Please run the Ni example first\n") | ||
| print("Setting Q_damp and Q_broad to refined values\n") | ||
| QDAMP_I = 0.045298 | ||
| QBROAD_I = 0.016809 |
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.
pytest was failing on CI (but not locally) without this. The reason why is because fitBulkNi.py refines these values, then fitNPPt.py grabs these refined values and uses them. CI cannot find these values from the Ni fit so I just pasted them here. This somewhat changes how the tutorial will be ran because the user doesn't need to fit the Ni first, but I don't feel great about adding special handling in the test for this file (potentially more maintenance in the future). Let me know if you feel differently about this.
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 we put this in a conditional, so it runs the old way but does it the new way if it can't find the other results?
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, that is what it is doing here.
|
@sbillinge I made one small change (see inline comment here https://github.com/diffpy/diffpy.cmi/pull/40/files#r2359918512). If you approve this this can be merged. Then we can release! |
sbillinge
left a comment
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.
pls see comments
.gitignore
Outdated
| docs/examples/ch*/solutions/diffpy-cmi/fig/* | ||
| docs/examples/ch*/solutions/diffpy-cmi/fit/* | ||
| docs/examples/ch*/solutions/diffpy-cmi/res/* | ||
|
|
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 not good. This is precisely what we want to avoid (test-generated junk). How do the examples decide where to write these files? Can you copy the files to tmpdir and then run them?
| # If we want to run using multiprocessors, we can switch this to 'True'. | ||
| # This requires that the 'psutil' python package installed. | ||
| RUN_PARALLEL = True | ||
| RUN_PARALLEL = 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.
We don't want to do this either. Is there a reason not to install psutil? or make it conditional on whether psutil is installed? We don't want to change the behavior of the examples just so the CI will run.
| print("Please run the Ni example first\n") | ||
| print("Setting Q_damp and Q_broad to refined values\n") | ||
| QDAMP_I = 0.045298 | ||
| QBROAD_I = 0.016809 |
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 we put this in a conditional, so it runs the old way but does it the new way if it can't find the other results?
tests/conftest.py
Outdated
| import matplotlib | ||
| import pytest | ||
|
|
||
| __examples_dir__ = Path(__file__).parent.parent / "docs" / "examples" |
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.
we may want to cd to tmpdir copy over the examples something like that.
tests/test_ch03.py
Outdated
| import pytest | ||
| from conftest import __examples_dir__, run_cmi_script | ||
|
|
||
| chapter = "ch03NiModelling" |
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 still is not using glob as I had in mind. Is there a reason we can't glob from the parent directory?
|
I am working on this. Weirdly, I can't get |
@sbillinge Actually yes, I get the same thing. I thought it mightve been an issue with my local since I don't get this error when I install from conda-forge, but I guess not since you're getting the same thing... |
|
interesting. As a workaround I will do |
|
closing because new PR #45 |
@sbillinge yeah Ill check it out. |
😂, it wasn't chatgpt? |
@sbillinge lol, maybe a bit of both.... 😳 |
|
I will never openly admit it lol 😂 |
|
using type hints is not our group style atm, and we want standardization. However, it is a good thing in general, so we should revisit this shortly. Taking that decision means adding type hints to everything we edit on to remove technical debt, so we want to make sure the benefits outweigh the costs. It has been a struggle to bring our code to py 3.13 as you know, but now everything is pretty much updated, it may be hte right time. |
|
@sbillinge Yeah, using chatgpt for this could be very useful for public repos if we decide to add. still think it would take a lot of work though |
|
I wouldn't use chatgpt for that. We don't have to change everything, just things we work on. |
closes #8
Updated comment: This tests the example scripts by running each test in pytest infrastructure.