-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: working TList serialization (#763)
* fix: initialize empty `TObject` members on `to_TObjString` * add test for serialization of `TObjString` * remove unused dependency on test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add `tojson` method to `TObjString` * add additional check to `TObjString` write test * fix bad field in `TList` tojson conversion * add inexpensive `assert` to `TList` serialization * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix bad serialization of non-empty TList due to options (#763 (comment)) * add tests for TList serialization * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixed bad `__repr__` for `TObject` * add serialization of `fUniqueID` to `TObject` * add `empty` method to `TObject` * remove redundant `TObject` member initialization * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update src/uproot/writing/identify.py Co-authored-by: Jim Pivarski <jpivarski@users.noreply.github.com> * moved `TList` serialization list to `serialize` method * add helper serialization method `bytestring` as suggested in #763 (comment) by @agoose77 * keep `TList` `_options` as python `bytes` and update serialization to use the new `bytestring` helper * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * reset `serialization.py` to `main` branch status * Revert "keep `TList` `_options` as python `bytes` and update serialization to use the new `bytestring` helper" This reverts commit 8e6ad2e. * Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks" This reverts commit 897972f. # Conflicts: # src/uproot/serialization.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Revert "reset `serialization.py` to `main` branch status" This reverts commit 9a500c1. * Revert "Revert "keep `TList` `_options` as python `bytes` and update serialization to use the new `bytestring` helper"" This reverts commit 884ec4d. * Update src/uproot/models/TObject.py Co-authored-by: Angus Hollands <goosey15@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jim Pivarski <jpivarski@users.noreply.github.com> Co-authored-by: Angus Hollands <goosey15@gmail.com>
- Loading branch information
1 parent
33777b1
commit cb8c776
Showing
7 changed files
with
124 additions
and
16 deletions.
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
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
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
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,64 @@ | ||
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/main/LICENSE | ||
|
||
import os | ||
|
||
import pytest | ||
|
||
import uproot | ||
import uproot.writing | ||
|
||
|
||
def test_write_empty(tmp_path): | ||
filename = os.path.join(tmp_path, "whatever.root") | ||
|
||
tlist = uproot.writing.identify.to_TList([]) | ||
|
||
with uproot.recreate(filename) as f: | ||
f["test"] = tlist | ||
|
||
with uproot.open(filename) as f2: | ||
assert len(f2["test"]) == 0 | ||
|
||
|
||
def test_write_single_key(tmp_path): | ||
filename = os.path.join(tmp_path, "whatever.root") | ||
|
||
tlist = uproot.writing.identify.to_TList( | ||
[uproot.writing.identify.to_TObjString("test string")] | ||
) | ||
|
||
with uproot.recreate(filename) as f: | ||
f["test"] = tlist | ||
|
||
with uproot.open(filename) as f2: | ||
assert len(f2["test"]) == 1 | ||
|
||
|
||
def test_write_nested(tmp_path): | ||
filename = os.path.join(tmp_path, "whatever.root") | ||
|
||
tlist_child = uproot.writing.identify.to_TList( | ||
[uproot.writing.identify.to_TObjString(s) for s in "this is a test".split()] | ||
) | ||
|
||
entries = [ | ||
uproot.writing.identify.to_TObjString("this string goes in the front"), | ||
tlist_child, | ||
uproot.writing.identify.to_TObjString("test string"), | ||
] | ||
|
||
tlist = uproot.writing.identify.to_TList(entries) | ||
|
||
with uproot.recreate(filename) as f: | ||
f["test"] = tlist | ||
|
||
with uproot.open(filename) as f2: | ||
parent_list = f2["test"] | ||
assert len(parent_list) == 3 | ||
assert isinstance(parent_list[0], uproot.models.TObjString.Model_TObjString) | ||
assert str(parent_list[0]) == "this string goes in the front" | ||
assert str(parent_list[2]) == "test string" | ||
child_list = parent_list[1] | ||
assert isinstance(child_list, uproot.models.TList.Model_TList) | ||
assert len(child_list) == 4 | ||
assert " ".join([str(s) for s in child_list]) == "this is a test" |