Skip to content
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

add support for object comparison #2182

Merged
merged 1 commit into from Oct 3, 2023

Conversation

ITProKyle
Copy link
Contributor

@ITProKyle ITProKyle commented Sep 18, 2023

Summary

Adds support to compare objects.

Why This Is Needed

An advantage to using troposphere is being able to unit test various iterations of a dynamic template. However, the lack of support for being able to compare objects with one another makes these test cumbersome to write.

Resolves #1821

What Changed

Added

  • added .to_json() method to base classes
  • added .__eq__() and .__ne__() methods to base classes
    • these use the newly added .to_json() method for comparison of same objects created from the same class to ensure properties are sorted in the same order
    • comparing against a dict (or list for AWSHelperFn to support Tags) uses .to_dict() instead of converting both to a JSON string
  • added AWSHelperFn.__hash__()
    • tests/test_tags.py:TestTags.test_Unsortable was failing with TypeError: unhashable type: 'Sub' without it

@markpeek markpeek merged commit 4e065c2 into cloudtools:main Oct 3, 2023
4 of 5 checks passed
@markpeek
Copy link
Member

markpeek commented Oct 3, 2023

Thank you for adding this functionality.

@ITProKyle ITProKyle deleted the feat/object-comparison branch October 9, 2023 17:11
markpeek added a commit that referenced this pull request Nov 10, 2023
 #2204)

PR #2182 added support for troposphere object comparison. Upon release
there was an issue (#2196) where Parameter was not hashable and fixed in
PR #2200. This fix was a minimal one just for Parameter but PR #2204
showed use cases for the base object to be hashable as well.
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.

add comparison capability to CloudFormation intrinsic function objects
2 participants