eyedentify3d 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. eyedentify3d-1.0.0/LICENSE +21 -0
  2. eyedentify3d-1.0.0/PKG-INFO +57 -0
  3. eyedentify3d-1.0.0/README.md +30 -0
  4. eyedentify3d-1.0.0/eyedentify3d/__init__.py +16 -0
  5. eyedentify3d-1.0.0/eyedentify3d/error_type.py +30 -0
  6. eyedentify3d-1.0.0/eyedentify3d/time_range.py +56 -0
  7. eyedentify3d-1.0.0/eyedentify3d/version.py +1 -0
  8. eyedentify3d-1.0.0/eyedentify3d.egg-info/PKG-INFO +57 -0
  9. eyedentify3d-1.0.0/eyedentify3d.egg-info/SOURCES.txt +31 -0
  10. eyedentify3d-1.0.0/eyedentify3d.egg-info/dependency_links.txt +1 -0
  11. eyedentify3d-1.0.0/eyedentify3d.egg-info/requires.txt +9 -0
  12. eyedentify3d-1.0.0/eyedentify3d.egg-info/top_level.txt +1 -0
  13. eyedentify3d-1.0.0/pyproject.toml +53 -0
  14. eyedentify3d-1.0.0/setup.cfg +4 -0
  15. eyedentify3d-1.0.0/setup.py +21 -0
  16. eyedentify3d-1.0.0/tests/test_abstract_data.py +209 -0
  17. eyedentify3d-1.0.0/tests/test_blink.py +128 -0
  18. eyedentify3d-1.0.0/tests/test_data_utils.py +8 -0
  19. eyedentify3d-1.0.0/tests/test_error_type.py +84 -0
  20. eyedentify3d-1.0.0/tests/test_event.py +272 -0
  21. eyedentify3d-1.0.0/tests/test_fixation.py +241 -0
  22. eyedentify3d-1.0.0/tests/test_htc_vive_pro_data.py +337 -0
  23. eyedentify3d-1.0.0/tests/test_inter_saccades.py +500 -0
  24. eyedentify3d-1.0.0/tests/test_invalid.py +115 -0
  25. eyedentify3d-1.0.0/tests/test_original_code.py +370 -0
  26. eyedentify3d-1.0.0/tests/test_reduced_data.py +231 -0
  27. eyedentify3d-1.0.0/tests/test_rotation_utils.py +277 -0
  28. eyedentify3d-1.0.0/tests/test_saccade.py +268 -0
  29. eyedentify3d-1.0.0/tests/test_sequence_utils.py +329 -0
  30. eyedentify3d-1.0.0/tests/test_signal_utils.py +158 -0
  31. eyedentify3d-1.0.0/tests/test_smooth_pursuit.py +256 -0
  32. eyedentify3d-1.0.0/tests/test_time_range.py +119 -0
  33. eyedentify3d-1.0.0/tests/test_visual_scanning.py +217 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 EveCharbie
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.4
2
+ Name: eyedentify3d
3
+ Version: 1.0.0
4
+ Summary: A package to identify gaze behavior from 3D eye-tracking data.
5
+ Home-page: https://github.com/EveCharbie/EyeDentify3D
6
+ Author: Eve Charbonneau
7
+ Author-email: EveCharbie <eve.charbie@gmail.com>
8
+ Project-URL: Documentation, https://github.com/EveCharbie/EyeDentify3d/tree/main#readme
9
+ Project-URL: Source, https://github.com/EveCharbie/EyeDentify3d
10
+ Project-URL: Tracker, https://github.com/EveCharbie/EyeDentify3d/issues
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python
13
+ Requires-Python: >=3.11
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: scipy
17
+ Requires-Dist: numpy
18
+ Requires-Dist: matplotlib
19
+ Requires-Dist: pandas
20
+ Requires-Dist: pingouin
21
+ Provides-Extra: test
22
+ Requires-Dist: pytest; extra == "test"
23
+ Requires-Dist: black; extra == "test"
24
+ Dynamic: author
25
+ Dynamic: home-page
26
+ Dynamic: license-file
27
+
28
+ # EyeDentify3D: A Python package for gaze behavior classification of 3D eye-tracking data
29
+
30
+ <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-success" alt="License"/></a>
31
+ [![Build status](https://github.com/EveCharbie/EyeDentify3d/actions/workflows/run_tests.yml/badge.svg)](https://github.com/EveCharbie/EyeDentify3d/actions)
32
+ [![codecov](https://codecov.io/gh/EveCharbie/EyeDentify3d/graph/badge.svg?token=BP4B2TCZXI)](https://codecov.io/gh/EveCharbie/EyeDentify3d)
33
+ [![DOI](https://zenodo.org/badge/821504006.svg)](https://doi.org/10.5281/zenodo.14718072)
34
+ [![Maintainability](https://qlty.sh/gh/EveCharbie/projects/EyeDentify3d/maintainability.svg)](https://qlty.sh/gh/EveCharbie/projects/EyeDentify3d)
35
+
36
+ ## Installation
37
+ The easiest way to install `EyeDentify3D` is to use pip:
38
+ ```bash
39
+ pip install eyedentify3d
40
+ ```
41
+ or conda-forge:
42
+ ```bash
43
+ conda install -c conda-forge eyedentify3d
44
+ ```
45
+
46
+ If you prefer to install from source, you can clone the repository and create a conda environment with the required dependencies:
47
+ ```bash
48
+ conda env create -f environment.yml
49
+ ```
50
+
51
+ ## Documentation
52
+ you can find the paper accompanying our JOSS submission [here](paper/paper.pdf) and a deeper documentation of the
53
+ package features and underlying mathematical choices [here](https://evecharbie.github.io/EyeDentify3d).
54
+
55
+ ## Examples
56
+ Examples of usage can be found in the [examples](examples/) directory.
57
+
@@ -0,0 +1,30 @@
1
+ # EyeDentify3D: A Python package for gaze behavior classification of 3D eye-tracking data
2
+
3
+ <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-success" alt="License"/></a>
4
+ [![Build status](https://github.com/EveCharbie/EyeDentify3d/actions/workflows/run_tests.yml/badge.svg)](https://github.com/EveCharbie/EyeDentify3d/actions)
5
+ [![codecov](https://codecov.io/gh/EveCharbie/EyeDentify3d/graph/badge.svg?token=BP4B2TCZXI)](https://codecov.io/gh/EveCharbie/EyeDentify3d)
6
+ [![DOI](https://zenodo.org/badge/821504006.svg)](https://doi.org/10.5281/zenodo.14718072)
7
+ [![Maintainability](https://qlty.sh/gh/EveCharbie/projects/EyeDentify3d/maintainability.svg)](https://qlty.sh/gh/EveCharbie/projects/EyeDentify3d)
8
+
9
+ ## Installation
10
+ The easiest way to install `EyeDentify3D` is to use pip:
11
+ ```bash
12
+ pip install eyedentify3d
13
+ ```
14
+ or conda-forge:
15
+ ```bash
16
+ conda install -c conda-forge eyedentify3d
17
+ ```
18
+
19
+ If you prefer to install from source, you can clone the repository and create a conda environment with the required dependencies:
20
+ ```bash
21
+ conda env create -f environment.yml
22
+ ```
23
+
24
+ ## Documentation
25
+ you can find the paper accompanying our JOSS submission [here](paper/paper.pdf) and a deeper documentation of the
26
+ package features and underlying mathematical choices [here](https://evecharbie.github.io/EyeDentify3d).
27
+
28
+ ## Examples
29
+ Examples of usage can be found in the [examples](examples/) directory.
30
+
@@ -0,0 +1,16 @@
1
+ from .data_parsers.htc_vive_pro_data import HtcViveProData
2
+ from .data_parsers.reduced_data import ReducedData
3
+ from .error_type import ErrorType
4
+ from .identification.gaze_behavior_identifier import GazeBehaviorIdentifier
5
+ from .time_range import TimeRange
6
+ from .version import __version__
7
+
8
+
9
+ __all__ = [
10
+ "HtcViveProData",
11
+ "ReducedData",
12
+ "ErrorType",
13
+ "GazeBehaviorIdentifier",
14
+ "TimeRange",
15
+ "__version__",
16
+ ]
@@ -0,0 +1,30 @@
1
+ from enum import Enum
2
+
3
+
4
+ class ErrorType(Enum):
5
+ """This enum defines the way errors are handled"""
6
+
7
+ SKIP = "continues silently on errors"
8
+ PRINT = "prints the error message to the console"
9
+ FILE = "print the error message to a file"
10
+ RAISE = "raises an exception on errors"
11
+
12
+ def __call__(self, error_str: str) -> None:
13
+ """
14
+ Handle the error based on the enum type
15
+
16
+ Parameters
17
+ ----------
18
+ error_str: The error message to handle
19
+ """
20
+ if self == ErrorType.FILE:
21
+ with open("bad_data_files.txt", "a") as bad_data_file:
22
+ bad_data_file.write(error_str + "\n")
23
+ elif self == ErrorType.PRINT:
24
+ print(error_str, end="")
25
+ elif self == ErrorType.SKIP:
26
+ pass
27
+ elif self == ErrorType.RAISE:
28
+ raise RuntimeError(error_str)
29
+ else:
30
+ raise ValueError(f"Unknown error type: {self}")
@@ -0,0 +1,56 @@
1
+ import numpy as np
2
+
3
+
4
+ class TimeRange:
5
+ """A class to represent a time range for data processing in trials."""
6
+
7
+ def __init__(self, min_time: float = 0, max_time: float = float("inf")) -> None:
8
+ """
9
+ Parameters
10
+ ----------
11
+ min_time: The time at which to start considering the data in the trial.
12
+ max_time: The time at which to stop considering the data in the trial.
13
+ """
14
+ if min_time > max_time:
15
+ raise ValueError("The min_time must be less than or equal to the max_time.")
16
+
17
+ self.min_time = min_time
18
+ self.max_time = max_time
19
+
20
+ def get_indices(self, time_vector: np.ndarray):
21
+ """
22
+ Get the indices of the time vector that fall within the specified time range.
23
+
24
+ Parameters
25
+ ----------
26
+ time_vector: A numpy array of time values.
27
+
28
+ Returns
29
+ -------
30
+ A numpy array of indices where the time values are within the specified range.
31
+ """
32
+ if np.any(time_vector[-1:] - time_vector[:-1] < 0):
33
+ raise ValueError("The time vector must be strictly increasing.")
34
+
35
+ if np.all(time_vector < self.min_time) or np.all(time_vector > self.max_time):
36
+ # If all values are outside the range, return an empty array
37
+ return np.array([], dtype=int)
38
+
39
+ # This approach is less clean but is robust no NaNs in the time_vector
40
+ beginning_idx = np.where(time_vector >= self.min_time)[0]
41
+ end_idx = np.where(time_vector > self.max_time)[0]
42
+
43
+ if len(beginning_idx) == 0:
44
+ beginning_idx = 0
45
+ else:
46
+ beginning_idx = beginning_idx[0]
47
+
48
+ if len(end_idx) == 0:
49
+ end_idx = len(time_vector)
50
+ else:
51
+ end_idx = end_idx[0]
52
+
53
+ if beginning_idx >= end_idx:
54
+ return np.array([], dtype=int)
55
+ else:
56
+ return np.arange(beginning_idx, end_idx)
@@ -0,0 +1 @@
1
+ __version__ = "1.0.0"
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.4
2
+ Name: eyedentify3d
3
+ Version: 1.0.0
4
+ Summary: A package to identify gaze behavior from 3D eye-tracking data.
5
+ Home-page: https://github.com/EveCharbie/EyeDentify3D
6
+ Author: Eve Charbonneau
7
+ Author-email: EveCharbie <eve.charbie@gmail.com>
8
+ Project-URL: Documentation, https://github.com/EveCharbie/EyeDentify3d/tree/main#readme
9
+ Project-URL: Source, https://github.com/EveCharbie/EyeDentify3d
10
+ Project-URL: Tracker, https://github.com/EveCharbie/EyeDentify3d/issues
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python
13
+ Requires-Python: >=3.11
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: scipy
17
+ Requires-Dist: numpy
18
+ Requires-Dist: matplotlib
19
+ Requires-Dist: pandas
20
+ Requires-Dist: pingouin
21
+ Provides-Extra: test
22
+ Requires-Dist: pytest; extra == "test"
23
+ Requires-Dist: black; extra == "test"
24
+ Dynamic: author
25
+ Dynamic: home-page
26
+ Dynamic: license-file
27
+
28
+ # EyeDentify3D: A Python package for gaze behavior classification of 3D eye-tracking data
29
+
30
+ <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-success" alt="License"/></a>
31
+ [![Build status](https://github.com/EveCharbie/EyeDentify3d/actions/workflows/run_tests.yml/badge.svg)](https://github.com/EveCharbie/EyeDentify3d/actions)
32
+ [![codecov](https://codecov.io/gh/EveCharbie/EyeDentify3d/graph/badge.svg?token=BP4B2TCZXI)](https://codecov.io/gh/EveCharbie/EyeDentify3d)
33
+ [![DOI](https://zenodo.org/badge/821504006.svg)](https://doi.org/10.5281/zenodo.14718072)
34
+ [![Maintainability](https://qlty.sh/gh/EveCharbie/projects/EyeDentify3d/maintainability.svg)](https://qlty.sh/gh/EveCharbie/projects/EyeDentify3d)
35
+
36
+ ## Installation
37
+ The easiest way to install `EyeDentify3D` is to use pip:
38
+ ```bash
39
+ pip install eyedentify3d
40
+ ```
41
+ or conda-forge:
42
+ ```bash
43
+ conda install -c conda-forge eyedentify3d
44
+ ```
45
+
46
+ If you prefer to install from source, you can clone the repository and create a conda environment with the required dependencies:
47
+ ```bash
48
+ conda env create -f environment.yml
49
+ ```
50
+
51
+ ## Documentation
52
+ you can find the paper accompanying our JOSS submission [here](paper/paper.pdf) and a deeper documentation of the
53
+ package features and underlying mathematical choices [here](https://evecharbie.github.io/EyeDentify3d).
54
+
55
+ ## Examples
56
+ Examples of usage can be found in the [examples](examples/) directory.
57
+
@@ -0,0 +1,31 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ eyedentify3d/__init__.py
6
+ eyedentify3d/error_type.py
7
+ eyedentify3d/time_range.py
8
+ eyedentify3d/version.py
9
+ eyedentify3d.egg-info/PKG-INFO
10
+ eyedentify3d.egg-info/SOURCES.txt
11
+ eyedentify3d.egg-info/dependency_links.txt
12
+ eyedentify3d.egg-info/requires.txt
13
+ eyedentify3d.egg-info/top_level.txt
14
+ tests/test_abstract_data.py
15
+ tests/test_blink.py
16
+ tests/test_data_utils.py
17
+ tests/test_error_type.py
18
+ tests/test_event.py
19
+ tests/test_fixation.py
20
+ tests/test_htc_vive_pro_data.py
21
+ tests/test_inter_saccades.py
22
+ tests/test_invalid.py
23
+ tests/test_original_code.py
24
+ tests/test_reduced_data.py
25
+ tests/test_rotation_utils.py
26
+ tests/test_saccade.py
27
+ tests/test_sequence_utils.py
28
+ tests/test_signal_utils.py
29
+ tests/test_smooth_pursuit.py
30
+ tests/test_time_range.py
31
+ tests/test_visual_scanning.py
@@ -0,0 +1,9 @@
1
+ scipy
2
+ numpy
3
+ matplotlib
4
+ pandas
5
+ pingouin
6
+
7
+ [test]
8
+ pytest
9
+ black
@@ -0,0 +1 @@
1
+ eyedentify3d
@@ -0,0 +1,53 @@
1
+ [build-system]
2
+ requires = [
3
+ "setuptools",
4
+ "setuptools-scm",
5
+ "scipy",
6
+ "numpy",
7
+ "matplotlib",
8
+ "pandas",
9
+ "pingouin",
10
+ ]
11
+ build-backend = "setuptools.build_meta"
12
+
13
+ [project]
14
+ name = "eyedentify3d"
15
+ description = "A package to identify gaze behavior from 3D eye-tracking data."
16
+ dynamic = ["version"]
17
+ authors = [
18
+ {name = "EveCharbie", email = "eve.charbie@gmail.com"},
19
+ ]
20
+ readme = "README.md"
21
+ classifiers = [
22
+ "License :: OSI Approved :: MIT License",
23
+ "Programming Language :: Python"
24
+ ]
25
+ requires-python = ">=3.11"
26
+ dependencies = [
27
+ "scipy",
28
+ "numpy",
29
+ "matplotlib",
30
+ "pandas",
31
+ "pingouin",
32
+ ]
33
+
34
+ [project.optional-dependencies]
35
+ test = [
36
+ "pytest",
37
+ "black",
38
+ ]
39
+
40
+ [project.urls]
41
+ Documentation = "https://github.com/EveCharbie/EyeDentify3d/tree/main#readme"
42
+ Source = "https://github.com/EveCharbie/EyeDentify3d"
43
+ Tracker = "https://github.com/EveCharbie/EyeDentify3d/issues"
44
+
45
+ [tool.setuptools]
46
+ packages = ["eyedentify3d"]
47
+
48
+ [tool.setuptools.dynamic]
49
+ version = {attr = "eyedentify3d.__version__"}
50
+
51
+ [tool.pytest.ini_options]
52
+ pythonpath = "."
53
+ testpaths = "tests"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,21 @@
1
+ import setuptools
2
+
3
+ with open("README.md", "r") as fh:
4
+ long_description = fh.read()
5
+
6
+ setuptools.setup(
7
+ name="eyedentify3d",
8
+ version="1.0.0",
9
+ author="Eve Charbonneau",
10
+ author_email="eve.charbie@gmail.com",
11
+ description="Identify gaze behaviors from 3D eye-trakcing data",
12
+ long_description=long_description,
13
+ long_description_content_type="text/markdown",
14
+ url="https://github.com/EveCharbie/EyeDentify3D",
15
+ packages=setuptools.find_packages(),
16
+ classifiers=[
17
+ "Programming Language :: Python :: 3",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ ],
21
+ )
@@ -0,0 +1,209 @@
1
+ import pytest
2
+ import numpy as np
3
+ from unittest.mock import patch, MagicMock
4
+
5
+ from eyedentify3d.data_parsers.abstract_data import Data, destroy_on_fail
6
+ from eyedentify3d import ErrorType, TimeRange
7
+
8
+
9
+ class MockData(Data):
10
+ """Mock implementation of the abstract Data class for testing"""
11
+
12
+ def _check_validity(self):
13
+ pass
14
+
15
+ def _set_time_vector(self):
16
+ self.time_vector = np.array([0.0, 0.1, 0.2, 0.3, 0.4])
17
+
18
+ def _discard_data_out_of_range(self):
19
+ pass
20
+
21
+ def _set_eye_openness(self):
22
+ pass
23
+
24
+ def _set_eye_direction(self):
25
+ pass
26
+
27
+ def _set_head_angles(self):
28
+ pass
29
+
30
+ def _set_head_angular_velocity(self):
31
+ pass
32
+
33
+ def _set_data_invalidity(self):
34
+ pass
35
+
36
+
37
+ def test_data_init():
38
+ """Test initialization of Data class with default parameters"""
39
+ data = MockData()
40
+ assert data.error_type == ErrorType.PRINT
41
+ assert isinstance(data.time_range, TimeRange)
42
+ assert data._validity_flag is True
43
+ assert data.dt is None
44
+
45
+
46
+ def test_data_init_with_params():
47
+ """Test initialization of Data class with custom parameters"""
48
+ error_type = ErrorType.SKIP
49
+ time_range = TimeRange(1.0, 5.0)
50
+ data = MockData(error_type=error_type, time_range=time_range)
51
+
52
+ assert data.error_type == error_type
53
+ assert data.time_range == time_range
54
+
55
+
56
+ def test_error_type_setter_valid():
57
+ """Test setting a valid error type"""
58
+ data = MockData()
59
+ data.error_type = ErrorType.SKIP
60
+ assert data.error_type == ErrorType.SKIP
61
+
62
+
63
+ def test_error_type_setter_invalid():
64
+ """Test setting an invalid error type"""
65
+ data = MockData()
66
+ with pytest.raises(ValueError, match="The error type must be an ErrorType, got INVALID."):
67
+ data.error_type = "INVALID"
68
+
69
+
70
+ @patch("builtins.open", new_callable=MagicMock)
71
+ def test_error_type_setter_file(mock_open):
72
+ """Test setting error type to FILE creates a file"""
73
+ data = MockData()
74
+ data.error_type = ErrorType.FILE
75
+
76
+ mock_open.assert_called_once()
77
+ assert "bad_data_files.txt" in mock_open.call_args[0][0]
78
+ assert "w" in mock_open.call_args[0][1]
79
+
80
+
81
+ def test_time_range_setter_valid():
82
+ """Test setting a valid time range"""
83
+ data = MockData()
84
+ time_range = TimeRange(2.0, 8.0)
85
+ data.time_range = time_range
86
+ assert data.time_range == time_range
87
+
88
+
89
+ def test_time_range_setter_invalid():
90
+ """Test setting an invalid time range"""
91
+ data = MockData()
92
+ with pytest.raises(ValueError, match="The time range must be an TimeRange, got INVALID."):
93
+ data.time_range = "INVALID"
94
+
95
+
96
+ def test_trial_duration():
97
+ """Test getting trial duration"""
98
+ data = MockData()
99
+ data._set_time_vector()
100
+ assert data.trial_duration == 0.4 # 0.4 - 0.0
101
+
102
+
103
+ def test_trial_duration_no_time_vector():
104
+ """Test getting trial duration without time vector"""
105
+ data = MockData()
106
+ with pytest.raises(
107
+ RuntimeError,
108
+ match=r"The trial_duration property can only be called after the time_vector has been set \(i.e., after the data objects has been instantiated\).",
109
+ ):
110
+ _ = data.trial_duration
111
+
112
+
113
+ def test_set_dt():
114
+ """Test setting dt"""
115
+ data = MockData()
116
+ data._set_time_vector()
117
+ data._set_dt()
118
+ assert data.dt == 0.1 # (0.1 - 0.0 + 0.2 - 0.1 + 0.3 - 0.2 + 0.4 - 0.3) / 4
119
+
120
+
121
+ def test_set_dt_no_time_vector():
122
+ """Test setting dt without time vector"""
123
+ data = MockData()
124
+ with pytest.raises(
125
+ RuntimeError,
126
+ match=r"The dt property can only be called after the time_vector has been set \(i.e., after the data objects has been instantiated\).",
127
+ ):
128
+ data._set_dt()
129
+
130
+
131
+ def test_set_dt_twice():
132
+ """Test setting dt twice"""
133
+ data = MockData()
134
+ data._set_time_vector()
135
+ data._set_dt()
136
+ with pytest.raises(
137
+ RuntimeError,
138
+ match="dt can only be set once at the very beginning of the data processing, because the time vector will be modified later.",
139
+ ):
140
+ data._set_dt()
141
+
142
+
143
+ def test_file_name():
144
+ """Test getting file name"""
145
+ data = MockData()
146
+ data.data_file_path = "/path/to/file.csv"
147
+ assert data.file_name == "file.csv"
148
+
149
+
150
+ def test_file_name_no_path():
151
+ """Test getting file name without path"""
152
+ data = MockData()
153
+ with pytest.raises(AttributeError, match="The data file path is not set."):
154
+ _ = data.file_name
155
+
156
+
157
+ def test_destroy_on_fail_decorator():
158
+ """Test the destroy_on_fail decorator"""
159
+
160
+ class TestData(MockData):
161
+ @destroy_on_fail
162
+ def failing_method(self):
163
+ self._validity_flag = False
164
+
165
+ data = TestData()
166
+ assert data._validity_flag is True
167
+
168
+ data.failing_method()
169
+
170
+ assert data.time_vector is None
171
+ assert data.right_eye_openness is None
172
+ assert data.left_eye_openness is None
173
+ assert data.eye_direction is None
174
+ assert data.head_angles is None
175
+ assert data.head_angular_velocity is None
176
+ assert data.head_velocity_norm is None
177
+
178
+
179
+ def test_destroy_on_error():
180
+ """Test the destroy_on_error method"""
181
+ data = MockData()
182
+ data._set_time_vector() # Set time_vector to non-None
183
+
184
+ data.destroy_on_error()
185
+
186
+ assert data.time_vector is None
187
+ assert data.right_eye_openness is None
188
+ assert data.left_eye_openness is None
189
+ assert data.eye_direction is None
190
+ assert data.head_angles is None
191
+ assert data.head_angular_velocity is None
192
+ assert data.head_velocity_norm is None
193
+
194
+
195
+ def test_nb_frames():
196
+ """Test getting the number of frames"""
197
+ data = MockData()
198
+ data._set_time_vector()
199
+ assert data.nb_frames == 5 # 5 time points in the time vector
200
+
201
+
202
+ def test_nb_frames_error():
203
+ """Test getting the number of frames when time_vector is not set"""
204
+ data = MockData()
205
+ with pytest.raises(
206
+ RuntimeError,
207
+ match=r"The nb_frames property can only be called after the time_vector has been set \(i.e., after the data objects has been instantiated\).",
208
+ ):
209
+ data.nb_frames