Skip to content

Commit

Permalink
Fixing pytest failures
Browse files Browse the repository at this point in the history
  • Loading branch information
SYusupov committed Sep 17, 2024
1 parent be11953 commit 46e375b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 45 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ on:
# Runs the pipeline on every push or a pull request to the main branch
push:
branches:
- main
- main
paths-ignore:
- '**.md' # no need if just README.md update
pull_request:
branches:
- main
Expand Down
84 changes: 40 additions & 44 deletions app/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@

client = TestClient(app)

long_instruction = """
Babe was a professional baseball player who was known both for his prowess
at the plate and his perceived "heart of gold." One day, Babe was
visiting a sick boy named Jimmy in the hospital. Babe was touched by
Jimmy's will to live despite a very poor prognosis. In a moment of
weakness, Babe told Jimmy that in consideration of Jimmy's courage, he
would do anything that Jimmy asked. Jimmy's eyes momentarily gleamed as
he asked Babe to "hit a homer for me in your next game." Babe replied,
"Sure kid." As Babe was leaving Jimmy's hospital room, Jimmy's father,
Joe, pulled Babe aside and told Babe, "It would mean a lot to Jimmy if
you would hit a home run for him in your next game. The medicinal value
of raising Jimmy's spirits would be priceless." Babe replied, "Hey man,
we all have problems. I don't work for the Make a Wish Foundation."
Undaunted, Joe repeated that it would really raise Jimmy's spirits if
Babe would hit a homer, and as incentive, Joe told Babe that he would pay
Babe $ 5,000$ if Babe did hit a home run in his next game. Babe replied,
"You've got a deal." To raise his chances of collecting the $ 5,000$ from
Joe, Babe took extra batting practice before his next game, and the
practice paid off because in his next game, Babe hit two home runs.
During a post-game interview, Babe explained, "I did it for little Jimmy,
who is in the hospital." After showering, Babe went directly to Joe's
house and asked Joe for $ 5,000$. Babe's contract with his ball club
does not forbid him from accepting money from fans for good performance.
If Joe refuses to pay and Babe brings an action against Joe for damages,
which of the following is correct under the modern trend in contract law?
A. Babe can recover the $ 5,000$ because the preexisting duty rule does
not apply where the duty is owed to a third person. B. Babe can recover
the $ 5,000$ if he can prove that the value of the home run to Jimmy is
at least $ 5,000$. C. Babe cannot recover from Joe because Babe had a
preexisting duty to use his best efforts to hit home runs. D. Babe cannot
recover from Joe because, even under the modern trend, moral
consideration is not valid."""

long_instruction = ''\
'Babe was a baseball player known for his prowess at the plate and '\
'his '\
'"heart of gold." One day, he visited a sick boy Jimmy in the hospital. '\
"Touched by Jimmy's courage despite a poor prognosis, Babe told Jimmy "\
"he "\
"would do anything Jimmy asked. Jimmy asked Babe to 'hit a homer for me "\
"in your next game.' Babe replied, 'Sure.' As he left, Jimmy's father, "\
'Joe, pulled Babe aside, saying, "It would mean a lot to Jimmy if you '\
'hit'\
" a home run in your next game. The medicinal value of raising Jimmy's "\
'spirits would be priceless." Babe replied, "We all have problems. I '\
'dont'\
' work for the Make a Wish Foundation." Joe insisted it would help '\
'Jimmy '\
'and offered Babe $5,000 if he hit a home run. Babe agreed. Babe '\
'practiced'\
'extra before the next game and hit two home runs. During a post-game '\
'interview, Babe said, "I did it for little Jimmy." Afterward, Babe '\
'went '\
"to Joe's house to ask for the $5,000. Babe's contract with his ball "\
"club "\
"does not forbid accepting money from fans for good performance. If Joe "\
'refuses to pay and Babe sues for damages, which of the following is '\
'correct under modern contract law?'\
'A. Babe can recover the $5,000 because the preexisting duty rule does '\
'not apply where the duty is owed to a third person.'\
'B. Babe can recover the $5,000 if he proves the value of the home run '\
'to Jimmy is at least $5,000.'\
'C. Babe cannot recover because he had a preexisting duty to use his '\
'best'\
'efforts to hit home runs.'\
'D. Babe cannot recover because moral consideration is not valid.'\

# Test the root endpoint
def test_read_root():
Expand All @@ -46,11 +46,10 @@ def test_read_root():

# Test valid model inference
def test_valid_inference():
# failed, 422
instruction = """
How many four-digit numbers greater than 2999 can be formed such that the
product of the middle two digits exceeds 5?"""
response = client.get(
response = client.post(
"/ask",
params={"instruction": instruction}
)
Expand All @@ -67,10 +66,9 @@ def test_valid_inference():

# Test inference with input provided
def test_inference_with_long_instruction_and_input():
# failed, 422

input_text = "Choose A, B, C or D as your solution."
response = client.get(
response = client.post(
"/ask",
params={"instruction": long_instruction, "input": input_text}
)
Expand All @@ -87,9 +85,9 @@ def test_inference_with_long_instruction_and_input():
# Test inference with missing instruction
def test_inference_missing_instruction():
input_text = "Choose A, B, C or D as your solution."
response = client.get(
response = client.post(
"/ask",
params={"instruction": "", "input": input_text}
params={"input": input_text}
)

# FastAPI will return a 422 if required fields are missing or invalid
Expand All @@ -98,8 +96,7 @@ def test_inference_missing_instruction():

# Test inference with a long input text
def test_inference_with_long_input():
# failed, 422
response = client.get(
response = client.post(
"/ask",
params={"instruction": long_instruction}
)
Expand All @@ -115,7 +112,7 @@ def test_inference_with_long_input():

# Test an invalid request structure
def test_invalid_request_structure():
response = client.get(
response = client.post(
"/ask",
params={"invalid_field": "test"}
)
Expand All @@ -126,10 +123,9 @@ def test_invalid_request_structure():

# Test when model returns no tokens (edge case)
def test_empty_model_response():
# failed, 422
instruction = ""
input_text = ""
response = client.get(
response = client.post(
"/ask",
params={"instruction": instruction, "input": input_text}
)
Expand Down

0 comments on commit 46e375b

Please sign in to comment.