forked from strands-agents/harness-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
120 lines (80 loc) · 2.34 KB
/
Copy pathconftest.py
File metadata and controls
120 lines (80 loc) · 2.34 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
65
66
67
68
69
70
71
72
73
74
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
import configparser
import logging
import os
import sys
import warnings
import boto3
import moto
import pytest
## Moto
# Get the log level from the environment variable
log_level = os.environ.get("LOG_LEVEL", "INFO").upper()
logging.getLogger("strands").setLevel(log_level)
logging.basicConfig(
format="%(levelname)s | %(name)s | %(message)s", handlers=[logging.StreamHandler(stream=sys.stdout)]
)
@pytest.fixture
def moto_env(monkeypatch):
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "test")
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "test")
monkeypatch.setenv("AWS_SECURITY_TOKEN", "test")
monkeypatch.setenv("AWS_DEFAULT_REGION", "us-west-2")
monkeypatch.delenv("OTEL_EXPORTER_OTLP_ENDPOINT", raising=False)
monkeypatch.delenv("OTEL_EXPORTER_OTLP_HEADERS", raising=False)
@pytest.fixture
def moto_mock_aws():
with moto.mock_aws():
yield
@pytest.fixture
def moto_cloudwatch_client():
return boto3.client("cloudwatch")
## Boto3
@pytest.fixture
def boto3_profile_name():
return "test-profile"
@pytest.fixture
def boto3_profile(boto3_profile_name):
config = configparser.ConfigParser()
config[boto3_profile_name] = {
"aws_access_key_id": "test",
"aws_secret_access_key": "test",
}
return config
@pytest.fixture
def boto3_profile_path(boto3_profile, tmp_path, monkeypatch):
path = tmp_path / ".aws/credentials"
path.parent.mkdir(exist_ok=True)
with path.open("w") as fp:
boto3_profile.write(fp)
monkeypatch.setenv("AWS_SHARED_CREDENTIALS_FILE", str(path))
return path
## Async
@pytest.fixture(scope="session")
def agenerator():
async def agenerator(items):
for item in items:
yield item
return agenerator
@pytest.fixture(scope="session")
def alist():
async def alist(items):
return [item async for item in items]
return alist
## Itertools
@pytest.fixture(scope="session")
def generate():
def generate(generator):
events = []
try:
while True:
event = next(generator)
events.append(event)
except StopIteration as stop:
return events, stop.value
return generate
## Warnings
@pytest.fixture
def captured_warnings():
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
yield w