-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6a95ba
commit 637bfd5
Showing
3 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Run API tests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.12] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
- name: Static Code Linting with flake8 | ||
run: | | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Unit Testing with pytest | ||
env: | ||
# add environment variables for tests | ||
run: | | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from os import link | ||
from fastapi.testclient import TestClient | ||
|
||
from .main import app | ||
|
||
client = TestClient(app) | ||
|
||
|
||
SMALL_PROGRAM = '''"""Hello world""" | ||
def main(): | ||
"""Hello world""" | ||
print("hi" + "bye") | ||
main() | ||
''' | ||
|
||
SMALL_PROGRAM_MIN = """def main(): | ||
print("hi"+"bye") | ||
main()""" | ||
|
||
SMALL_PROGRAM_MIN_TINY = """def main(): | ||
print("hi"+"bye") | ||
main()""" | ||
|
||
|
||
def test_minimise_code(): | ||
response = client.post( | ||
url="/minimise/", | ||
json={"code": SMALL_PROGRAM, "lang": "python3", "indentation": " "}, | ||
) | ||
assert response.status_code == 200 | ||
assert response.json().code == {"lang": "python3", "code": SMALL_PROGRAM_MIN} | ||
|
||
response = client.post( | ||
url="/minimise/", | ||
json={"code": SMALL_PROGRAM, "lang": "python3", "indentation": " "}, | ||
) | ||
assert response.status_code == 200 | ||
assert response.json().code == {"lang": "python3", "code": SMALL_PROGRAM_MIN_TINY} | ||
|
||
|
||
def test_minimise_code_and_get_link(): | ||
response = client.post( | ||
url="/minimise/", | ||
json={"code": SMALL_PROGRAM, "lang": "python3", "indentation": " "}, | ||
) | ||
assert response.status_code == 200 | ||
assert response.json().code == { | ||
"lang": "python3", | ||
"code": SMALL_PROGRAM_MIN, | ||
"link": "https://pythontutor.com/visualize.html#cumulative=false&heapPrimitives=nevernest&mode=edit&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false&code=def+main%28%29%3A%0A++++print%28%22hi%22%2B%22bye%22%29%0Amain%28%29", | ||
} | ||
|
||
response = client.post( | ||
url="/minimise/", | ||
json={ | ||
"code": SMALL_PROGRAM, | ||
"lang": "python3", | ||
"indentation": " ", | ||
}, | ||
) | ||
assert response.status_code == 200 | ||
assert response.json().code == { | ||
"lang": "python3", | ||
"code": SMALL_PROGRAM_MIN_TINY, | ||
"link": "https://pythontutor.com/visualize.html#cumulative=false&heapPrimitives=nevernest&mode=edit&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false&code=def+main%28%29%3A%0A+print%28%22hi%22%2B%22bye%22%29%0Amain%28%29", | ||
} |
637bfd5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deployment failed with the following error: