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
|
"""
This packages contains affiliated package tests.
"""
import numpy as np
from .. import CustomType, util
from .helpers import get_test_data_path
class CustomTestType(CustomType):
"""This class is intended to be inherited by custom types that are used
purely for the purposes of testing. The methods ``from_tree_tagged`` and
``from_tree`` are implemented solely in order to avoid custom type
conversion warnings.
"""
@classmethod
def from_tree_tagged(cls, tree, ctx):
return cls.from_tree(tree.data, ctx)
@classmethod
def from_tree(cls, tree, ctx):
return tree
def create_small_tree():
x = np.arange(0, 10, dtype=float)
tree = {
"science_data": x,
"subset": x[3:-3],
"skipping": x[::2],
"not_shared": np.arange(10, 0, -1, dtype=np.uint8),
}
return tree
def create_large_tree():
# These are designed to be big enough so they don't fit in a
# single block, but not so big that RAM/disk space for the tests
# is enormous.
x = np.random.rand(256, 256)
y = np.random.rand(16, 16, 16)
tree = {"science_data": x, "more": y}
return tree
class CustomExtension:
"""
This is the base class that is used for extensions for custom tag
classes that exist only for the purposes of testing.
"""
@property
def types(self):
return []
@property
def tag_mapping(self):
return [("tag:nowhere.org:custom", "http://nowhere.org/schemas/custom{tag_suffix}")]
@property
def url_mapping(self):
return [
("http://nowhere.org/schemas/custom/", util.filepath_to_url(get_test_data_path("")) + "/{url_suffix}.yaml")
]
|