forked from redis/redis-vl-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
145 lines (122 loc) · 3.23 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import os
import pytest
import asyncio
from redisvl.redis.connection import RedisConnectionFactory
from testcontainers.compose import DockerCompose
@pytest.fixture(scope="session", autouse=True)
def redis_container():
# Set the default Redis version if not already set
os.environ.setdefault("REDIS_VERSION", "edge")
compose = DockerCompose("tests", compose_file_name="docker-compose.yml", pull=True)
compose.start()
redis_host, redis_port = compose.get_service_host_and_port("redis", 6379)
redis_url = f"redis://{redis_host}:{redis_port}"
os.environ["REDIS_URL"] = redis_url
yield compose
compose.stop()
@pytest.fixture(scope="session")
def redis_url():
return os.getenv("REDIS_URL", "redis://localhost:6379")
@pytest.fixture
async def async_client(redis_url):
client = await RedisConnectionFactory.get_async_redis_connection(redis_url)
yield client
try:
await client.aclose()
except RuntimeError as e:
if "Event loop is closed" not in str(e):
raise
@pytest.fixture
def client():
conn = RedisConnectionFactory.get_redis_connection(os.environ["REDIS_URL"])
yield conn
conn.close()
@pytest.fixture
def openai_key():
return os.getenv("OPENAI_API_KEY")
@pytest.fixture
def openai_version():
return os.getenv("OPENAI_API_VERSION")
@pytest.fixture
def azure_endpoint():
return os.getenv("AZURE_OPENAI_ENDPOINT")
@pytest.fixture
def cohere_key():
return os.getenv("COHERE_API_KEY")
@pytest.fixture
def mistral_key():
return os.getenv("MISTRAL_API_KEY")
@pytest.fixture
def gcp_location():
return os.getenv("GCP_LOCATION")
@pytest.fixture
def gcp_project_id():
return os.getenv("GCP_PROJECT_ID")
@pytest.fixture
def sample_data():
return [
{
"user": "john",
"age": 18,
"job": "engineer",
"credit_score": "high",
"location": "-122.4194,37.7749",
"user_embedding": [0.1, 0.1, 0.5]
},
{
"user": "mary",
"age": 14,
"job": "doctor",
"credit_score": "low",
"location": "-122.4194,37.7749",
"user_embedding": [0.1, 0.1, 0.5]
},
{
"user": "nancy",
"age": 94,
"job": "doctor",
"credit_score": "high",
"location": "-122.4194,37.7749",
"user_embedding": [0.7, 0.1, 0.5]
},
{
"user": "tyler",
"age": 100,
"job": "engineer",
"credit_score": "high",
"location": "-110.0839,37.3861",
"user_embedding": [0.1, 0.4, 0.5]
},
{
"user": "tim",
"age": 12,
"job": "dermatologist",
"credit_score": "high",
"location": "-110.0839,37.3861",
"user_embedding": [0.4, 0.4, 0.5]
},
{
"user": "taimur",
"age": 15,
"job": "CEO",
"credit_score": "low",
"location": "-110.0839,37.3861",
"user_embedding": [0.6, 0.1, 0.5]
},
{
"user": "joe",
"age": 35,
"job": "dentist",
"credit_score": "medium",
"location": "-110.0839,37.3861",
"user_embedding": [0.9, 0.9, 0.1]
},
]
@pytest.fixture
def clear_db(redis):
redis.flushall()
yield
redis.flushall()
@pytest.fixture
def app_name():
return "test_app"