-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix __asdf_traverse__ for non-tagged object
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import asdf | ||
|
||
|
||
def test_info_on_non_tagged_asdf_traverse_object(): | ||
""" | ||
Calling info with a tree containing an object that implements | ||
__asdf_traverse__ but does not have a _tag results in an | ||
error | ||
https://github.com/asdf-format/asdf/issues/1738 | ||
""" | ||
|
||
class MyContainer: | ||
def __init__(self, data): | ||
self.data = data | ||
|
||
def __asdf_traverse__(self): | ||
return self.data | ||
|
||
c = MyContainer([1, 2, 3]) | ||
af = asdf.AsdfFile() | ||
af["c"] = c | ||
|
||
# info should not error out | ||
af.info() | ||
|
||
# and search should work with the container | ||
assert af.search(type_=int).paths == ["root['c'][0]", "root['c'][1]", "root['c'][2]"] | ||
|
||
# this should work even if _tag exists (and is not a tag) | ||
c._tag = {} | ||
assert af.search(type_=int).paths == ["root['c'][0]", "root['c'][1]", "root['c'][2]"] | ||
c._tag = "a" | ||
assert af.search(type_=int).paths == ["root['c'][0]", "root['c'][1]", "root['c'][2]"] |