This repository was archived by the owner on Sep 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
80 lines (58 loc) · 2.24 KB
/
conftest.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""PyTest configuration."""
from pathlib import Path
import boto3
import pytest
from beartype import beartype
from beartype.typing import Dict, Union
from moto import mock_s3
from pytest_cache_assert import AssertConfig, CacheAssertContainerKeys, Converter, register
from pytest_cache_assert._check_assert.constants import DEF_CACHE_DIR_NAME
from .configuration import TEST_TMP_CACHE, clear_test_cache
@pytest.fixture()
@beartype
def fix_cache_path() -> Path:
"""Fixture to clear and return the test cache directory for use.
Returns:
Path: Path to the test cache directory
"""
clear_test_cache()
return TEST_TMP_CACHE
@pytest.fixture()
@beartype
def fix_tmp_assert(fix_cache_path: Path) -> Dict[str, Union[str, Path]]:
"""Fixture to temporary assert directory and keyword arguments.
Args:
fix_cache_path: pytest fixture for temporary directory
Returns:
Path: Path to the test cache directory
"""
return {
'path_cache_dir': fix_cache_path,
'cache_name': 'test_assert_against_cache.json',
}
# https://github.com/beartype/bearboto3/blob/c212ca885623dd3b0c45868ec2ed66e8c5b8043c/tests/s3/s3_fixtures.py#L7-L10
@pytest.fixture()
def gen_s3_client():
with mock_s3():
yield boto3.client('s3')
class CustomType: # noqa: PIE798
"""Arbitrary custom type used for testing user configuration.
Note: I previously tested the `to_json(origin='records')` version of the pandas dataframe serializer to override the default, but this test suite was sometimes restoring the default and sometimes not, which was hard to troubleshoot
""" # noqa: E501
@staticmethod
@beartype
def to_str(_arg) -> str:
"""Custom serialization method."""
return 'Serialized!'
@pytest.fixture(autouse=True) # FYI: This is a workaround since other internal tests register a different config
@beartype
def register_custom_cache_assert_config() -> None:
"""Register a new AssertConfig."""
assert_config = AssertConfig(
always_write=False,
cache_dir_rel_path=f'{DEF_CACHE_DIR_NAME}-custom',
converters=[
Converter(types=[CustomType], func=CustomType.to_str),
],
)
register(CacheAssertContainerKeys.CONFIG, assert_config)