Skip to content

Add SWXSOC Science Filename Parsing Test for Instrument Package Compliance#6

Merged
dbarrous merged 7 commits intoPADRESat:mainfrom
dbarrous:validate-science-filename-test
Apr 28, 2025
Merged

Add SWXSOC Science Filename Parsing Test for Instrument Package Compliance#6
dbarrous merged 7 commits intoPADRESat:mainfrom
dbarrous:validate-science-filename-test

Conversation

@dbarrous
Copy link
Contributor

@dbarrous dbarrous commented Feb 28, 2025

This PR refactors the padre_sharp instrument package to add back the create_science_filename functions and old util test suite so they can be managed by the instrument package team.

It also adds the test_validate_swxsoc_science_filename test to ensure that instrument teams can define their own create_science_filename implementations while maintaining compliance with the SWXSOC naming convention.

The test will be added to all other instrument packages after this PR, test for reference:

def test_validate_swxsoc_science_filename(
    expected_mission, expected_instrument, expected_time, expected_formatted_time,
    expected_level, expected_descriptor, expected_version, expected_file_extension, expected_filename
):
    """
    Validate that filenames generated by `create_science_filename` conform to the SWXSOC naming convention.

    This test ensures:
    - Instrument teams can define their own `create_science_filename` implementations.
    - Filenames adhere to SWXSOC's required format.
    - Handling of blank descriptors is correct.
    - Test files are properly labeled with "test" in their filename.
    """
    # Generate filename using the function under test
    created_filename = util.create_science_filename(
        expected_instrument,
        Time(expected_time),
        expected_level,
        expected_version,
        expected_descriptor,
        test="test" in expected_filename,
    )

    # Ensure generated filename matches expectation
    assert created_filename == expected_filename, f"Generated filename {created_filename} does not match expected {expected_filename}"

    # Define expected filename pattern
    pattern = r"^(\w+)_(\w+)(?:_(\w+))?_(l[0-4]|ql)(test)?(?:_(\w+(?:-\w+)*))?_(\d{8}T\d{6})_v(\d+\.\d+\.\d+)?\.(\w+)$"
    match = re.match(pattern, expected_filename)

    # Validate filename format
    assert match, f"Filename {expected_filename} does not match expected format"

    # Extract matched groups
    mission, instrument, mode, level, test_flag, descriptor, time_str, version, extension = match.groups()

    # Ensure parsed values align with expected values
    assert mission == expected_mission, f"Mission mismatch: expected {expected_mission}, got {mission}"
    assert instrument == expected_instrument, f"Instrument mismatch: expected {expected_instrument}, got {instrument}"
    assert level == expected_level, f"Level mismatch: expected {expected_level}, got {level}"
    assert (descriptor or "") == expected_descriptor, f"Descriptor mismatch: expected {expected_descriptor}, got {descriptor}"
    assert version == expected_version, f"Version mismatch: expected {expected_version}, got {version}"
    assert extension == expected_file_extension, f"File extension mismatch: expected {expected_file_extension}, got {extension}"
    assert time_str == expected_formatted_time, f"Time format mismatch: expected {expected_formatted_time}, got {time_str}"
    assert (test_flag == "test") == ("test" in expected_filename), f"Test flag mismatch in filename {expected_filename}"
# fmt: on

Also included:
Fixes to the SHARP faux processing so that it can handle the new file type and do a fake processing (just renaming the file) up to quicklook (ql). But it does do the file validation each time.

@dbarrous dbarrous merged commit 3250906 into PADRESat:main Apr 28, 2025
15 checks passed
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.

3 participants