-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathtest_plugin_aware.py
49 lines (36 loc) · 1.42 KB
/
test_plugin_aware.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
import pytest
from pinecone.utils.plugin_aware import PluginAware
from pinecone.config import Config
from pinecone.openapi_support.configuration import Configuration as OpenApiConfig
class TestPluginAware:
def test_errors_when_required_attributes_are_missing(self):
class Foo(PluginAware):
def __init__(self):
# does not set config, openapi_config, or pool_threads
super().__init__()
with pytest.raises(AttributeError) as e:
Foo()
assert "config" in str(e.value)
assert "openapi_config" in str(e.value)
assert "pool_threads" in str(e.value)
def test_correctly_raise_attribute_errors(self):
class Foo(PluginAware):
def __init__(self):
self.config = Config()
self.openapi_config = OpenApiConfig()
self.pool_threads = 1
super().__init__()
foo = Foo()
with pytest.raises(AttributeError) as e:
foo.bar()
assert "bar" in str(e.value)
def test_plugins_are_lazily_loaded(self):
class Pinecone(PluginAware):
def __init__(self):
self.config = Config()
self.openapi_config = OpenApiConfig()
self.pool_threads = 10
super().__init__()
pc = Pinecone()
assert "assistant" not in dir(pc)
assert pc.assistant is not None