MORSECorp / snappiershot

Apache License 2.0
30 stars 2 forks source link

Handle Recursive Objects #72

Closed bbonenfant closed 3 years ago

bbonenfant commented 3 years ago

Describe the Changes Recursive objects are now caught and removed during the default_encode_value method.

Example Code If you have added to the public API, please provide a code sample of how to use these additions.

def test_recursive_object(snapshot):
    value = dict()
    value["value"] = value
    value["name"] = "recursive object"

    # This no longer errors and will make the snapshot: {"name": "recursive object"}
    snapshot.assert_match(value)

Additional Notes Originally I was planning on wrapping these values in a way that they could remain in the snapshots, but this seems to not be possible due to either: 1) We replace them with some "recursive object" tag, in which case we cannot tell if two recursive objects are the same during the assertion phase. 2) We wrap recursive objects and encode to which object they are recursive to, but this seemed to complicated and might confuse the user.

Closes #58