-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdictionary_regression.py
More file actions
64 lines (53 loc) · 2.41 KB
/
dictionary_regression.py
File metadata and controls
64 lines (53 loc) · 2.41 KB
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
"""Implementation of the ``dictionary_regression`` fixture."""
import os
from typing import Optional
import ee
from pytest_regressions.data_regression import DataRegressionFixture
from .utils import build_fullpath, check_serialized, round_data
class DictionaryFixture(DataRegressionFixture):
"""Fixture for regression testing of :py:class:`ee.Dictionary`."""
def check(
self,
data_dict: ee.Dictionary,
basename: Optional[str] = None,
fullpath: Optional[os.PathLike] = None,
prescision: int = 6,
):
"""Check the given list against a previously recorded version, or generate a new file.
Parameters:
data_dict: The dictionary to check.
basename: The basename of the file to test/record. If not given the name of the test is used.
fullpath: complete path to use as a reference file. This option will ignore ``datadir`` fixture when reading *expected* files but will still use it to write *obtained* files. Useful if a reference file is located in the session data dir for example.
precision: The number of decimal places to round to when comparing floats.
"""
# build the different filename to be consistent between our 3 checks
data_name = build_fullpath(
datadir=self.original_datadir,
request=self.request,
extension=".yml",
basename=basename,
fullpath=fullpath,
with_test_class_names=self.with_test_class_names,
)
serialized_name = data_name.with_stem(f"serialized_{data_name.stem}").with_suffix(".yml")
is_serialized_equal = check_serialized(
object=data_dict,
path=serialized_name,
datadir=self.datadir,
request=self.request,
)
if is_serialized_equal:
# serialized is equal? -> pass test
# TODO: add proper logging
return
else:
data = round_data(data_dict.getInfo(), prescision)
super().check(data, fullpath=data_name)
# if we are here it means that the query result is equal but the serialized is not -> regenerate serialized
serialized_name.unlink(missing_ok=True)
check_serialized(
object=data_dict,
path=serialized_name,
datadir=self.datadir,
request=self.request,
)