|
| 1 | +import io |
| 2 | +import itertools |
| 3 | +import string |
| 4 | + |
| 5 | +import numpy as np |
| 6 | +import pytest |
| 7 | + |
| 8 | +import asdf |
| 9 | + |
| 10 | + |
| 11 | +SMALL_SET = string.ascii_lowercase[:3] |
| 12 | +LARGE_SET = string.ascii_lowercase[:26] |
| 13 | + |
| 14 | +DATA_GENS = ["no_data", "small_data", "large_data"] |
| 15 | +TREE_GENS = ["small_tree", "flat_tree", "deep_tree", "large_tree"] |
| 16 | + |
| 17 | + |
| 18 | +def no_data(i): |
| 19 | + return i |
| 20 | + |
| 21 | + |
| 22 | +def small_data(i): |
| 23 | + return np.full((3, 3), i) |
| 24 | + |
| 25 | + |
| 26 | +def large_data(i): |
| 27 | + return np.full((128, 128), i) |
| 28 | + |
| 29 | + |
| 30 | +def small_tree(data_gen): |
| 31 | + return {k: data_gen(ord(k)) for k in SMALL_SET} |
| 32 | + |
| 33 | + |
| 34 | +def flat_tree(data_gen): |
| 35 | + return {k: data_gen(ord(k)) for k in LARGE_SET} |
| 36 | + |
| 37 | + |
| 38 | +def deep_tree(data_gen): |
| 39 | + tree = {} |
| 40 | + for k in LARGE_SET: |
| 41 | + tree[k] = {"value": data_gen(k)} |
| 42 | + tree = tree[k] |
| 43 | + return tree |
| 44 | + |
| 45 | + |
| 46 | +def large_tree(data_gen): |
| 47 | + tree = {} |
| 48 | + for k in LARGE_SET: |
| 49 | + tree["value"] = {k: data_gen(ord(k)) for k in LARGE_SET} |
| 50 | + tree[k] = {} |
| 51 | + tree = tree[k] |
| 52 | + return tree |
| 53 | + |
| 54 | + |
| 55 | +@pytest.fixture(params=itertools.product(DATA_GENS, TREE_GENS)) |
| 56 | +def tree(request): |
| 57 | + data_gen_name, tree_gen_name = request.param |
| 58 | + # some gymnastics to work around pytest not allowing |
| 59 | + # getfixturevalue to use parametrized fixtures |
| 60 | + return globals()[tree_gen_name](globals()[data_gen_name]) |
| 61 | + |
| 62 | + |
| 63 | +@pytest.fixture |
| 64 | +def tree_bytes(tree): |
| 65 | + return asdf.dumps(tree) |
| 66 | + |
| 67 | + |
| 68 | +@pytest.fixture |
| 69 | +def asdf_file(tree): |
| 70 | + return asdf.AsdfFile(tree) |
0 commit comments