test_preprocess.py 5.5 KB
Newer Older
1
2
3
4
5
# @author lucasmiranda42

from hypothesis import given
from hypothesis import settings
from hypothesis import strategies as st
lucas_miranda's avatar
lucas_miranda committed
6
from collections import defaultdict
7
8
9
from deepof.utils import *
import deepof.preprocess
import pytest
lucas_miranda's avatar
lucas_miranda committed
10
11


lucas_miranda's avatar
lucas_miranda committed
12
13
14
15
16
17
@settings(deadline=None)
@given(
    table_type=st.integers(min_value=0, max_value=2),
    arena_type=st.integers(min_value=0, max_value=1),
)
def test_project_init(table_type, arena_type):
lucas_miranda's avatar
lucas_miranda committed
18
19

    table_type = [".h5", ".csv", ".foo"][table_type]
lucas_miranda's avatar
lucas_miranda committed
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
    arena_type = ["circular", "foo"][arena_type]

    if arena_type == "foo":
        with pytest.raises(NotImplementedError):
            prun = deepof.preprocess.project(
                path=os.path.join(".", "tests", "test_examples"),
                arena=arena_type,
                arena_dims=[380],
                angles=False,
                video_format=".mp4",
                table_format=table_type,
            )
    else:
        prun = deepof.preprocess.project(
            path=os.path.join(".", "tests", "test_examples"),
            arena=arena_type,
            arena_dims=[380],
            angles=False,
            video_format=".mp4",
            table_format=table_type,
        )

    if table_type != ".foo" and arena_type != "foo":

        assert type(prun) == deepof.preprocess.project
        assert type(prun.load_tables(verbose=True)) == tuple
        assert type(prun.get_scale) == np.ndarray
        print(prun)

    elif table_type == ".foo" and arena_type != "foo":
        with pytest.raises(NotImplementedError):
            prun.load_tables(verbose=True)


@settings(deadline=None)
@given(
    nodes=st.integers(min_value=0, max_value=1),
    ego=st.integers(min_value=0, max_value=2),
)
def test_get_distances(nodes, ego):

    nodes = ["All", ["Center", "Nose", "Tail_base"]][nodes]
    ego = [False, "Center", "Nose"][ego]
lucas_miranda's avatar
lucas_miranda committed
63
64
65
66
67
68
69

    prun = deepof.preprocess.project(
        path=os.path.join(".", "tests", "test_examples"),
        arena="circular",
        arena_dims=[380],
        angles=False,
        video_format=".mp4",
lucas_miranda's avatar
lucas_miranda committed
70
71
72
        table_format=".h5",
        distances=nodes,
        ego=ego,
lucas_miranda's avatar
lucas_miranda committed
73
74
    )

lucas_miranda's avatar
lucas_miranda committed
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
    prun = prun.get_distances(prun.load_tables()[0], verbose=True)

    assert type(prun) == dict


@settings(deadline=None)
@given(
    nodes=st.integers(min_value=0, max_value=1),
    ego=st.integers(min_value=0, max_value=2),
)
def test_get_angles(nodes, ego):

    nodes = ["All", ["Center", "Nose", "Tail_base"]][nodes]
    ego = [False, "Center", "Nose"][ego]

    prun = deepof.preprocess.project(
        path=os.path.join(".", "tests", "test_examples"),
        arena="circular",
        arena_dims=[380],
        video_format=".mp4",
        table_format=".h5",
        distances=nodes,
        ego=ego,
    )

    prun = prun.get_angles(prun.load_tables()[0], verbose=True)

    assert type(prun) == dict


@settings(deadline=None)
@given(
    nodes=st.integers(min_value=0, max_value=1),
    ego=st.integers(min_value=0, max_value=2),
)
def test_run(nodes, ego):

    nodes = ["All", ["Center", "Nose", "Tail_base"]][nodes]
    ego = [False, "Center", "Nose"][ego]

    prun = deepof.preprocess.project(
        path=os.path.join(".", "tests", "test_examples"),
        arena="circular",
        arena_dims=[380],
        video_format=".mp4",
        table_format=".h5",
        distances=nodes,
        ego=ego,
    ).run(verbose=True)

    assert type(prun) == deepof.preprocess.coordinates
lucas_miranda's avatar
lucas_miranda committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188


@settings(deadline=None)
@given(
    nodes=st.integers(min_value=0, max_value=1),
    ego=st.integers(min_value=0, max_value=2),
    sampler=st.data(),
)
def test_get_table_dicts(nodes, ego, sampler):

    nodes = ["All", ["Center", "Nose", "Tail_base"]][nodes]
    ego = [False, "Center", "Nose"][ego]

    prun = deepof.preprocess.project(
        path=os.path.join(".", "tests", "test_examples"),
        arena="circular",
        arena_dims=[380],
        video_format=".mp4",
        table_format=".h5",
        distances=nodes,
        ego=ego,
    ).run(verbose=True)

    coords = prun.get_coords(
        center=sampler.draw(st.one_of(st.just("arena"), st.just("Center"))),
        polar=sampler.draw(st.booleans()),
        length=sampler.draw(st.one_of(st.just(False), st.just("00:10:00"))),
        align=sampler.draw(st.one_of(st.just(False), st.just("Nose"))),
    )
    speeds = prun.get_coords(
        center=sampler.draw(st.one_of(st.just("arena"), st.just("Center"))),
        polar=sampler.draw(st.booleans()),
        length=sampler.draw(st.one_of(st.just(False), st.just("00:10:00"))),
        speed=sampler.draw(st.integers(min_value=0, max_value=5)),
    )
    distances = prun.get_distances(
        length=sampler.draw(st.one_of(st.just(False), st.just("00:10:00"))),
        speed=sampler.draw(st.integers(min_value=0, max_value=5)),
    )
    angles = prun.get_angles(
        degrees=sampler.draw(st.booleans()),
        length=sampler.draw(st.one_of(st.just(False), st.just("00:10:00"))),
        speed=sampler.draw(st.integers(min_value=0, max_value=5)),
    )

    # deepof.coordinates testing

    assert type(coords) == deepof.preprocess.table_dict
    assert type(speeds) == deepof.preprocess.table_dict
    assert type(distances) == deepof.preprocess.table_dict
    assert type(angles) == deepof.preprocess.table_dict
    assert type(prun.get_videos()) == list
    assert prun.get_exp_conditions is None
    assert type(prun.get_quality()) == defaultdict
    assert type(prun.get_arenas) == tuple

    # deepof.table_dict testing

    table = sampler.draw(
        st.one_of(st.just(coords), st.just(speeds), st.just(distances), st.just(angles))
    )

    #table.filter()