Skip to content

Fix SWAPI integration tests - #175

Open
leowerneck wants to merge 4 commits into
IMAP-Science-Operations-Center:mainfrom
leowerneck:171-172-174-fix-swapi-integration-testing
Open

Fix SWAPI integration tests#175
leowerneck wants to merge 4 commits into
IMAP-Science-Operations-Center:mainfrom
leowerneck:171-172-174-fix-swapi-integration-testing

Conversation

@leowerneck

@leowerneck leowerneck commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Change Summary

Closes #171, closes #172, closes #174.

Overview

  • Fixed subprocess-spawned imap_l3_data_processor.py not inheriting the parent test's DATA_DIR, causing it to look for staged inputs in the wrong place.
  • Added the missing imap_swapi_l3b_20260101_v001.json dependency fixture, which was never checked.
  • Pinned SWAPI L3a fixtures to the correct science/ancillary file revisions.

Testing

Run:

uv run --with pytest pytest tests/integration/test_swapi_processor_integration.py

passes. Also verified the fix is robust to an arbitrary ambient IMAP_DATA_DIR (the original bug in #171):

IMAP_DATA_DIR=/tmp uv run --with pytest pytest tests/integration/test_swapi_processor_integration.py

Both pass identically on my machine.

@leowerneck
leowerneck requested a balanced review from Copilot August 24, 2026 21:33
@leowerneck leowerneck self-assigned this Aug 24, 2026
@leowerneck leowerneck added bug Something isn't working Ins: SWAPI Related to the SWAPI instrument Data Release 2 Deadline: September 1, 2026 labels Aug 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes SWAPI integration tests by aligning subprocess data paths and correcting dependency fixtures.

Changes:

  • Passes the staged data directory to processor subprocesses.
  • Adds the missing L3b dependency manifest.
  • Pins SWAPI and MAG fixtures to correct revisions.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/integration/test_swapi_processor_integration.py Aligns subprocess data paths and revised L2 fixture lookup.
tests/integration/test_data/swapi/imap_swapi_l3b_20260101_v001.json Adds the missing L3b dependencies.
tests/integration/test_data/swapi/imap_swapi_l3a_pui-he_20260101_v001.json Pins revised SWAPI science data.
tests/integration/test_data/swapi/imap_swapi_l3a_proton-sw_20260101_v001.json Pins revised SWAPI science data.
tests/integration/test_data/swapi/imap_swapi_l3a_alpha-sw_20260101_v001.json Pins revised SWAPI and MAG science data.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@leowerneck leowerneck changed the title Fix SWAP integration tests Fix SWAPI integration tests Aug 25, 2026

@jtniehof jtniehof left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Minor comments, except that test_alpha_sw_with_production_data still fails OMM:

                try:
>                   numpy.testing.assert_allclose(
                        actual_value, expected_values[key], rtol=rtol, atol=atol, err_msg=key
                    )
E                   AssertionError: 
E                   Not equal to tolerance rtol=0.001, atol=0
E                   alpha_sw_density
E                   Mismatched elements: 1 / 1 (100%)
E                   Max absolute difference among violations: 0.00503448
E                   Max relative difference among violations: 0.03190463
E                    ACTUAL: array(0.162832)
E                    DESIRED: array(0.157798)

/home/jnik/work/scm/imap_L3_processing/tests/integration/test_swapi_processor_integration.py:194: AssertionError

Does this look like something you've come across in creating this fix (in which case maybe there's some lurking "wrong file" thing), or do I need to go chasing "from scratch"?

Comment thread tests/integration/test_swapi_processor_integration.py
Comment thread tests/integration/test_data/swapi/imap_swapi_l3b_20260101_v001.json Outdated
@leowerneck

Copy link
Copy Markdown
Collaborator Author

Minor comments, except that test_alpha_sw_with_production_data still fails OMM:

                try:
>                   numpy.testing.assert_allclose(
                        actual_value, expected_values[key], rtol=rtol, atol=atol, err_msg=key
                    )
E                   AssertionError: 
E                   Not equal to tolerance rtol=0.001, atol=0
E                   alpha_sw_density
E                   Mismatched elements: 1 / 1 (100%)
E                   Max absolute difference among violations: 0.00503448
E                   Max relative difference among violations: 0.03190463
E                    ACTUAL: array(0.162832)
E                    DESIRED: array(0.157798)

/home/jnik/work/scm/imap_L3_processing/tests/integration/test_swapi_processor_integration.py:194: AssertionError

Does this look like something you've come across in creating this fix (in which case maybe there's some lurking "wrong file" thing), or do I need to go chasing "from scratch"?

Yes, I did have a couple of similar failures! I had no good reason for the particular version choice of the science/ancillary files other than "it works for me".

@jtniehof

jtniehof commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Minor comments, except that test_alpha_sw_with_production_data still fails OMM:

                try:
>                   numpy.testing.assert_allclose(
                        actual_value, expected_values[key], rtol=rtol, atol=atol, err_msg=key
                    )
E                   AssertionError: 
E                   Not equal to tolerance rtol=0.001, atol=0
E                   alpha_sw_density
E                   Mismatched elements: 1 / 1 (100%)
E                   Max absolute difference among violations: 0.00503448
E                   Max relative difference among violations: 0.03190463
E                    ACTUAL: array(0.162832)
E                    DESIRED: array(0.157798)

/home/jnik/work/scm/imap_L3_processing/tests/integration/test_swapi_processor_integration.py:194: AssertionError

Does this look like something you've come across in creating this fix (in which case maybe there's some lurking "wrong file" thing), or do I need to go chasing "from scratch"?

Yes, I did have a couple of similar failures! I had no good reason for the particular version choice of the science/ancillary files other than "it works for me".

Hmmm, so does this mean somehow I'm pulling the wrong version, or that there's something incomplete about the fix, or I'm holding it wrong? Let me try rerunning with my data directory removed, so I don't have stale files.

EDIT: Well, now all four of the SWAPI integration tests fail, getting a 404:
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.imap-mission.com/api-key/download/imap/dependency/swapi/l3a/2026/01/imap_swapi_l3a_pui-he_20260101_v001.json. Same problem if I unset IMAP_DATA_DIR before running the tests. It feels like there's some fragility in here.
wrong branch...

@jtniehof

Copy link
Copy Markdown
Collaborator

I can get the alpha test closer by using imap_mag_l2_norm-rtn_20260101_v001.0005.cdf. This is what was used in imap_swapi_l3a_alpha-sw_20260101_v001.0009.cdf, which is the closest -- .155704 for the density in record 1, where the expected is .157798, and I'm getting 0.153845 in the integration test. Other inputs for 0009 are the same as your dependency file.

Is this working on your machine right now? I'm wondering if this is something where we updated the alpha algorithm without updating the integration test (since it basically wasn't working).

@leowerneck

Copy link
Copy Markdown
Collaborator Author

Is this working on your machine right now? I'm wondering if this is something where we updated the alpha algorithm
without updating the integration test (since it basically wasn't working).

I just ran these commands (please be careful with the git clean commands below. I have provided them in "dry-run" mode, but locally I used -fd and -fdX instead of the options below):

git switch 171-172-174-fix-swapi-integration-testing
git clean -nd
git clean -ndX
rm -rf .git/lfs/objects
git lfs pull
uv run --with pytest pytest tests/integration/test_swapi_processor_integration.py

gives me

Using CPython 3.12.13
Creating virtual environment at: .venv
      Built imap-l3-processing @ file:///Users/lw3620/imap/imap_L3_processing
Installed 66 packages in 171ms
====================================================== test session starts =======================================================
platform darwin -- Python 3.12.13, pytest-9.1.1, pluggy-1.6.0
rootdir: /Users/lw3620/imap/imap_L3_processing
configfile: pyproject.toml
collected 4 items

tests/integration/test_swapi_processor_integration.py ....                                                                 [100%]

================================================= 4 passed in 238.83s (0:03:58) ==================================================

Since we made real changes in the names of the dependency files, I'm not convinced this is a code issue and not simply an input error. But I would note that I've encountered several other projects with integration tests success being OS- and Python-version-dependent. This can be specially true for tests that focus on computing relative errors like this one.

Comment thread tests/integration/test_data/swapi/imap_swapi_l3a_alpha-sw_20260101_v001.json Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

To get the density to match OMM, this rtol needs to be 0.03 or so. I really dislike this, but I think it's the best way forward.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I bumped the dependency to imap_mag_l2_norm-rtn_20260101_v001.0005.cdf, which caused the tests to fail OOM. I then bumped some of the rtol to 0.02 and they passed again. Could you check if the combination of dependency and tolerances currently in the repo works for you as well?

@jtniehof

Copy link
Copy Markdown
Collaborator
git switch 171-172-174-fix-swapi-integration-testing
git clean -nd
git clean -ndX
rm -rf .git/lfs/objects
git lfs pull
uv run --with pytest pytest tests/integration/test_swapi_processor_integration.py

Thanks. I did this cleanup and it still didn't work for me. The only other thing I can think of is that my imap_processing was a few commits behind, so I'll try one more time, but I think we should just go ahead and update the mag and relax the tolerance. I'm curious to see what changing the mag file version does to your results.

@leowerneck
leowerneck force-pushed the 171-172-174-fix-swapi-integration-testing branch 2 times, most recently from e9f0b9a to 58ce6cb Compare August 28, 2026 18:02
@leowerneck
leowerneck force-pushed the 171-172-174-fix-swapi-integration-testing branch from 58ce6cb to 74bea71 Compare August 28, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Data Release 2 Deadline: September 1, 2026 Ins: SWAPI Related to the SWAPI instrument

Projects

None yet

3 participants