20
20
"""Test public dataset definitions."""
21
21
from __future__ import annotations
22
22
23
+ from pathlib import Path
24
+
23
25
import pytest
24
26
25
27
import pymovements as pm
26
28
27
29
28
30
@pytest .mark .parametrize (
29
- ('definition_class' , 'dataset_name' ),
31
+ ('public_dataset' , 'dataset_name' ),
32
+ # XXX: add public dataset in alphabetical order
30
33
[
31
- pytest .param (pm .datasets .ToyDataset , 'ToyDataset' , id = 'ToyDataset' ),
32
34
pytest .param (pm .datasets .GazeBase , 'GazeBase' , id = 'GazeBase' ),
33
35
pytest .param (pm .datasets .GazeBaseVR , 'GazeBaseVR' , id = 'GazeBaseVR' ),
34
36
pytest .param (pm .datasets .GazeOnFaces , 'GazeOnFaces' , id = 'GazeOnFaces' ),
35
37
pytest .param (pm .datasets .HBN , 'HBN' , id = 'HBN' ),
36
38
pytest .param (pm .datasets .JuDo1000 , 'JuDo1000' , id = 'JuDo1000' ),
37
39
pytest .param (pm .datasets .PoTeC , 'PoTeC' , id = 'PoTeC' ),
38
40
pytest .param (pm .datasets .SBSAT , 'SBSAT' , id = 'SBSAT' ),
41
+ pytest .param (pm .datasets .ToyDataset , 'ToyDataset' , id = 'ToyDataset' ),
42
+ pytest .param (pm .datasets .ToyDatasetEyeLink , 'ToyDatasetEyeLink' , id = 'ToyDatasetEyeLink' ),
39
43
],
40
44
)
41
- def test_public_dataset_registered (definition_class , dataset_name ):
42
- assert dataset_name in pm .DatasetLibrary .definitions
43
- assert pm .DatasetLibrary .get (dataset_name ) == definition_class
44
- assert pm .DatasetLibrary .get (dataset_name )().name == dataset_name
45
-
45
+ @pytest .mark .parametrize (
46
+ ('dataset_path' ),
47
+ [
48
+ pytest .param (
49
+ None ,
50
+ id = 'dataset_path_None' ,
51
+ ),
52
+ pytest .param (
53
+ '.' ,
54
+ id = 'dataset_path_dot' ,
55
+ ),
56
+ pytest .param (
57
+ 'dataset_path' ,
58
+ id = 'dataset_path_dataset' ,
59
+ ),
60
+ ],
61
+ )
62
+ @pytest .mark .parametrize (
63
+ ('downloads' ),
64
+ [
65
+ pytest .param (
66
+ 'downloads' ,
67
+ id = 'downloads_None' ,
68
+ ),
69
+ pytest .param (
70
+ 'custom_downloads' ,
71
+ id = 'downloads_custom_downloads' ,
72
+ ),
46
73
74
+ ],
75
+ )
47
76
@pytest .mark .parametrize (
48
- 'dataset_definition_class' ,
77
+ ( 'str_root' ) ,
49
78
[
50
- pytest .param (pm . datasets . ToyDataset , id = 'ToyDataset' ),
51
- pytest . param ( pm . datasets . GazeBase , id = 'GazeBase' ) ,
52
- pytest . param ( pm . datasets . GazeBaseVR , id = 'GazeBaseVR' ) ,
53
- pytest . param ( pm . datasets . GazeOnFaces , id = 'GazeOnFaces' ),
54
- pytest .param (pm . datasets . HBN , id = 'HBN' ),
55
- pytest . param ( pm . datasets . JuDo1000 , id = 'JuDo1000' ) ,
56
- pytest . param ( pm . datasets . PoTeC , id = 'PoTeC' ) ,
57
- pytest . param ( pm . datasets . SBSAT , id = 'SBSAT' ),
79
+ pytest .param (
80
+ True ,
81
+ id = 'path_str' ,
82
+ ),
83
+ pytest .param (
84
+ False ,
85
+ id = 'path_DatasetPaths' ,
86
+ ),
58
87
],
59
88
)
60
- def test_public_dataset_registered_correct_attributes (dataset_definition_class ):
61
- dataset_definition = dataset_definition_class ()
89
+ def test_public_dataset_registered (public_dataset , dataset_name , dataset_path , downloads , str_root ):
90
+ assert dataset_name in pm .DatasetLibrary .definitions
91
+ assert pm .DatasetLibrary .get (dataset_name ) == public_dataset
92
+ assert pm .DatasetLibrary .get (dataset_name )().name == dataset_name
62
93
94
+ dataset_definition = public_dataset ()
63
95
registered_definition = pm .DatasetLibrary .get (dataset_definition .name )()
64
-
65
96
assert dataset_definition .gaze_mirrors == registered_definition .gaze_mirrors
66
97
assert dataset_definition .gaze_resources == registered_definition .gaze_resources
67
98
assert dataset_definition .experiment == registered_definition .experiment
@@ -70,3 +101,48 @@ def test_public_dataset_registered_correct_attributes(dataset_definition_class):
70
101
assert dataset_definition .has_gaze_files == registered_definition .has_gaze_files
71
102
assert dataset_definition .has_precomputed_event_files == registered_definition .has_precomputed_event_files # noqa: E501
72
103
assert dataset_definition .custom_read_kwargs == registered_definition .custom_read_kwargs
104
+
105
+ dataset , expected_paths = construct_public_dataset (
106
+ public_dataset ,
107
+ dataset_path ,
108
+ downloads ,
109
+ str_root ,
110
+ )
111
+ assert dataset .paths .root == expected_paths ['root' ]
112
+ assert dataset .path == expected_paths ['dataset' ]
113
+ assert dataset .paths .dataset == expected_paths ['dataset' ]
114
+ assert dataset .paths .downloads == expected_paths ['downloads' ]
115
+
116
+
117
+ def construct_public_dataset (
118
+ public_dataset ,
119
+ dataset_path ,
120
+ downloads ,
121
+ str_root ,
122
+ ):
123
+ expected = {}
124
+ expected ['root' ] = Path ('/data/set/path' )
125
+
126
+ if str_root :
127
+ init_path = '/data/set/path'
128
+ expected ['dataset' ] = Path ('/data/set/path' )
129
+ expected ['downloads' ] = Path ('/data/set/path/downloads' )
130
+
131
+ dataset = pm .Dataset (public_dataset , path = init_path )
132
+ return dataset , expected
133
+ init_path = pm .DatasetPaths (
134
+ root = '/data/set/path' ,
135
+ dataset = dataset_path ,
136
+ downloads = downloads ,
137
+ )
138
+
139
+ if dataset_path == '.' :
140
+ expected ['dataset' ] = Path ('/data/set/path' )
141
+ elif dataset_path == 'dataset_path' :
142
+ expected ['dataset' ] = Path ('/data/set/path/dataset_path' )
143
+ else :
144
+ expected ['dataset' ] = Path (f'/data/set/path/{ public_dataset .__name__ } ' )
145
+ expected ['downloads' ] = expected ['dataset' ] / Path (downloads )
146
+
147
+ dataset = pm .Dataset (public_dataset , path = init_path )
148
+ return dataset , expected
0 commit comments