Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ def _get_positional_body(*args, **kwargs):
"""Verify args and kwargs are valid, and then return the positional body, if users passed it in."""
if len(args) > 1:
raise TypeError("There can only be one positional argument, which is the POST body of this request.")
if args and "options" in kwargs:
if "options" in kwargs:
raise TypeError(
"You have already supplied the request body as a positional parameter, "
"you can not supply it as a keyword argument as well."
"The 'options' parameter is positional only."
)
return args[0] if args else None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,19 @@ def test_query_knowledgebase_overload_positional_and_kwarg(self):
client.get_answers("positional_one", "positional_two")
with pytest.raises(TypeError):
client.get_answers("positional_options_bag", options="options bag by name")
with pytest.raises(TypeError):
client.get_answers(
options={'qnaId': 15},
project_name="hello",
deployment_name='test'
)
with pytest.raises(TypeError):
client.get_answers(
{'qnaId': 15},
question='Why?',
project_name="hello",
deployment_name='test'
)

def test_query_knowledgebase_question_or_qna_id(self):
with QuestionAnsweringClient("http://fake.com", AzureKeyCredential("123")) as client:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,29 @@ def test_query_text_overload_positional_and_kwarg(self):
client.get_answers_from_text("positional_one", "positional_two")
with pytest.raises(TypeError):
client.get_answers_from_text("positional_options_bag", options="options bag by name")

params = AnswersFromTextOptions(
question="What is the meaning of life?",
text_documents=[
TextDocument(
text="foo",
id="doc1"
),
TextDocument(
text="bar",
id="doc2"
)
],
language="en"
)
with pytest.raises(TypeError):
client.get_answers_from_text(options=params)

with pytest.raises(TypeError):
client.get_answers_from_text(
question="why?",
text_documents=["foo", "bar"],
options=params)

with pytest.raises(TypeError):
client.get_answers_from_text(params, question="Why?")