aws-solutions-library-samples / osml-model-runner

MIT No Attribution
7 stars 1 forks source link

refactor: refatoring updating image_request.py and updating tests #108

Closed drduhe closed 2 weeks ago

drduhe commented 3 weeks ago

Issue #, if available: n/a

Notes

This PR introduces several improvements to the ImageRequest class, focusing on enhanced initialization, validation, and backward compatibility, along with updated unit tests to ensure robust functionality.

Key Changes:

  1. Initialization Improvements:

    • Updated the class to ensure sensible defaults (e.g., post_processing) are only applied when attributes are not explicitly set.
    • Added support for legacy fields like outputBucket and outputPrefix to ensure backward compatibility for outputs initialization.
  2. Refactoring and Cleaner Structure:

    • Decomposed complex logic into private helper methods (e.g., _parse_outputs, _parse_post_processing) to improve readability and maintainability.
    • Enhanced the from_external_message method to correctly handle both modern and legacy input formats, ensuring reliable parsing of attributes.
  3. Enhanced Validation Logic:

    • Improved the is_valid() method to check for valid SinkType values in outputs, ensuring that only recognized sink types (e.g., S3, KINESIS) are allowed. This prevents configuration errors.
    • Replaced direct access to protected enum members with a cleaner, safer approach using public methods.
  4. Updated and Expanded Unit Tests:

    • Added new tests to cover legacy output handling, including cases where outputBucket and outputPrefix are used instead of modern outputs fields.
    • Introduced tests for invalid sink types, ensuring the class correctly raises exceptions for unsupported configurations.
    • Improved tests for handling None values and verifying correct application of defaults.

Checklist

Before you submit a pull request, please make sure you have the following:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.