-
Notifications
You must be signed in to change notification settings - Fork 255
Expand file tree
/
Copy pathtest_repo_viewer_tool.py
More file actions
135 lines (125 loc) · 6.08 KB
/
test_repo_viewer_tool.py
File metadata and controls
135 lines (125 loc) · 6.08 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
#
# SPDX-License-Identifier: Apache-2.0
from haystack_integrations.prompts.github.repo_viewer_prompt import REPO_VIEWER_PROMPT, REPO_VIEWER_SCHEMA
from haystack_integrations.tools.github.repo_viewer_tool import GitHubRepoViewerTool
from haystack_integrations.tools.github.utils import message_handler
class TestGitHubRepoViewerTool:
def test_init(self, monkeypatch):
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
tool = GitHubRepoViewerTool()
assert tool.name == "repo_viewer"
assert tool.description == REPO_VIEWER_PROMPT
assert tool.parameters == REPO_VIEWER_SCHEMA
assert tool.max_file_size == 1_000_000
assert tool.github_token is None
assert tool.repo is None
assert tool.branch == "main"
assert tool.raise_on_failure
assert tool.outputs_to_string == {"source": "documents", "handler": message_handler}
assert tool.inputs_from_state == {}
assert tool.outputs_to_state == {"documents": {"source": "documents"}}
def test_from_dict(self, monkeypatch):
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
tool_dict = {
"type": "haystack_integrations.tools.github.repo_viewer_tool.GitHubRepoViewerTool",
"data": {
"name": "repo_viewer",
"description": REPO_VIEWER_PROMPT,
"parameters": REPO_VIEWER_SCHEMA,
"github_token": None,
"repo": None,
"branch": "main",
"raise_on_failure": True,
"max_file_size": 1_000_000,
"outputs_to_string": {
"source": "documents",
"handler": "haystack_integrations.tools.github.utils.message_handler",
},
"inputs_from_state": {},
"outputs_to_state": {"documents": {"source": "documents"}},
},
}
tool = GitHubRepoViewerTool.from_dict(tool_dict)
assert tool.name == "repo_viewer"
assert tool.description == REPO_VIEWER_PROMPT
assert tool.parameters == REPO_VIEWER_SCHEMA
assert tool.github_token is None
assert tool.repo is None
assert tool.branch == "main"
assert tool.raise_on_failure
assert tool.max_file_size == 1_000_000
assert tool.outputs_to_string["source"] == "documents"
assert tool.outputs_to_string["handler"] == message_handler
assert tool.inputs_from_state == {}
assert tool.outputs_to_state == {"documents": {"source": "documents"}}
def test_to_dict(self, monkeypatch):
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
tool = GitHubRepoViewerTool()
tool_dict = tool.to_dict()
assert tool_dict["type"] == "haystack_integrations.tools.github.repo_viewer_tool.GitHubRepoViewerTool"
assert tool_dict["data"]["name"] == "repo_viewer"
assert tool_dict["data"]["description"] == REPO_VIEWER_PROMPT
assert tool_dict["data"]["parameters"] == REPO_VIEWER_SCHEMA
assert tool_dict["data"]["github_token"] is None
assert tool_dict["data"]["repo"] is None
assert tool_dict["data"]["branch"] == "main"
assert tool_dict["data"]["raise_on_failure"]
assert tool_dict["data"]["max_file_size"] == 1_000_000
assert tool_dict["data"]["outputs_to_string"] == {
"source": "documents",
"handler": "haystack_integrations.tools.github.utils.message_handler",
}
assert tool_dict["data"]["inputs_from_state"] == {}
assert tool_dict["data"]["outputs_to_state"] == {"documents": {"source": "documents"}}
def test_to_dict_with_extra_params(self, monkeypatch):
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
tool = GitHubRepoViewerTool(
outputs_to_string={"source": "result", "handler": message_handler},
inputs_from_state={"repo_state": "repo"},
outputs_to_state={"file_content": {"source": "documents", "handler": message_handler}},
)
tool_dict = tool.to_dict()
assert tool_dict["data"]["outputs_to_string"] == {
"source": "result",
"handler": "haystack_integrations.tools.github.utils.message_handler",
}
assert tool_dict["data"]["inputs_from_state"] == {"repo_state": "repo"}
assert tool_dict["data"]["outputs_to_state"] == {
"file_content": {
"source": "documents",
"handler": "haystack_integrations.tools.github.utils.message_handler",
},
}
def test_from_dict_with_extra_params(self, monkeypatch):
monkeypatch.setenv("GITHUB_TOKEN", "test-token")
tool_dict = {
"type": "haystack_integrations.tools.github.repo_viewer_tool.GitHubRepoViewerTool",
"data": {
"name": "repo_viewer",
"description": REPO_VIEWER_PROMPT,
"parameters": REPO_VIEWER_SCHEMA,
"github_token": None,
"repo": None,
"branch": "main",
"raise_on_failure": True,
"max_file_size": 1_000_000,
"outputs_to_string": {
"source": "result",
"handler": "haystack_integrations.tools.github.utils.message_handler",
},
"inputs_from_state": {"repo_state": "repo"},
"outputs_to_state": {
"file_content": {
"source": "documents",
"handler": "haystack_integrations.tools.github.utils.message_handler",
},
},
},
}
tool = GitHubRepoViewerTool.from_dict(tool_dict)
assert tool.outputs_to_string["source"] == "result"
assert tool.outputs_to_string["handler"] == message_handler
assert tool.inputs_from_state == {"repo_state": "repo"}
assert tool.outputs_to_state["file_content"]["source"] == "documents"
assert tool.outputs_to_state["file_content"]["handler"] == message_handler