|
| 1 | +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE |
| 2 | + |
| 3 | +import os |
| 4 | + |
| 5 | +import uproot |
| 6 | + |
| 7 | + |
| 8 | +def test_mktree_repeated_same_subdir(tmp_path): |
| 9 | + newfile = os.path.join(tmp_path, "newfile.root") |
| 10 | + |
| 11 | + with uproot.recreate(newfile) as f: |
| 12 | + f.mktree("tree/x", {"x": [1, 2, 3]}) |
| 13 | + f.mktree("tree/y", {"x": [1, 2, 3]}) |
| 14 | + f.mktree("tree/z", {"x": [1, 2, 3]}) |
| 15 | + f.mktree("tree/w", {"x": [1, 2, 3]}) |
| 16 | + |
| 17 | + assert set(f.keys(cycle=False)) == { |
| 18 | + "tree", |
| 19 | + "tree/x", |
| 20 | + "tree/y", |
| 21 | + "tree/z", |
| 22 | + "tree/w", |
| 23 | + } |
| 24 | + |
| 25 | + with uproot.open(newfile) as fin: |
| 26 | + assert set(fin.keys(cycle=False)) == { |
| 27 | + "tree", |
| 28 | + "tree/x", |
| 29 | + "tree/y", |
| 30 | + "tree/z", |
| 31 | + "tree/w", |
| 32 | + } |
| 33 | + |
| 34 | + |
| 35 | +def test_mkrntuple_repeated_same_subdir(tmp_path): |
| 36 | + newfile = os.path.join(tmp_path, "newfile.root") |
| 37 | + |
| 38 | + with uproot.recreate(newfile) as f: |
| 39 | + f.mkrntuple("ntpl/x", {"x": [1, 2, 3]}) |
| 40 | + f.mkrntuple("ntpl/y", {"x": [1, 2, 3]}) |
| 41 | + f.mkrntuple("ntpl/z", {"x": [1, 2, 3]}) |
| 42 | + f.mkrntuple("ntpl/w", {"x": [1, 2, 3]}) |
| 43 | + |
| 44 | + assert set(f.keys(cycle=False)) == { |
| 45 | + "ntpl", |
| 46 | + "ntpl/x", |
| 47 | + "ntpl/y", |
| 48 | + "ntpl/z", |
| 49 | + "ntpl/w", |
| 50 | + } |
| 51 | + |
| 52 | + with uproot.open(newfile) as fin: |
| 53 | + assert set(fin.keys(cycle=False)) == { |
| 54 | + "ntpl", |
| 55 | + "ntpl/x", |
| 56 | + "ntpl/y", |
| 57 | + "ntpl/z", |
| 58 | + "ntpl/w", |
| 59 | + } |
0 commit comments