File: conftest.py

package info (click to toggle)
python-asdf 4.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,060 kB
  • sloc: python: 24,224; makefile: 123
file content (69 lines) | stat: -rw-r--r-- 1,418 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import itertools
import string

import numpy as np
import pytest

import asdf

SMALL_SET = string.ascii_lowercase[:3]
LARGE_SET = string.ascii_lowercase[:26]

DATA_GENS = ["no_data", "small_data", "large_data"]
TREE_GENS = ["small_tree", "flat_tree", "deep_tree", "large_tree"]
ALL_TREES = list(itertools.product(DATA_GENS, TREE_GENS))


def no_data(i):
    return i


def small_data(i):
    return np.full((3, 3), i)


def large_data(i):
    return np.full((128, 128), i)


def small_tree(data_gen):
    return {k: data_gen(ord(k)) for k in SMALL_SET}


def flat_tree(data_gen):
    return {k: data_gen(ord(k)) for k in LARGE_SET}


def deep_tree(data_gen):
    tree = {}
    for k in LARGE_SET:
        tree[k] = {"value": data_gen(k)}
        tree = tree[k]
    return tree


def large_tree(data_gen):
    tree = {}
    for k in LARGE_SET:
        tree["value"] = {k: data_gen(ord(k)) for k in LARGE_SET}
        tree[k] = {}
        tree = tree[k]
    return tree


@pytest.fixture(params=ALL_TREES, ids=["-".join(t) for t in ALL_TREES])
def tree(request):
    data_gen_name, tree_gen_name = request.param
    # some gymnastics to work around pytest not allowing
    # getfixturevalue to use parametrized fixtures
    return globals()[tree_gen_name](globals()[data_gen_name])


@pytest.fixture
def tree_bytes(tree):
    return asdf.dumps(tree)


@pytest.fixture
def asdf_file(tree):
    return asdf.AsdfFile(tree)