-
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
Showing
7 changed files
with
132 additions
and
60 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
import os | ||
import unittest | ||
|
||
# from unittest import mock | ||
from gradio_client import Client | ||
|
||
url = os.environ.get("GRADIO_URL", "http://localhost:7860") | ||
client = Client(url) | ||
|
||
class TestSuite(unittest.TestCase): | ||
|
||
def test_gradio_api(self): | ||
result = client.predict("Hi", api_name="/chat") | ||
self.assertGreater(len(result), 0) | ||
|
||
# def test_mock_response(self): | ||
# with mock.patch('app.client.stream_response', return_value=(char for char in "Mocked")) as mock_response: | ||
# result = client.predict("Hi", api_name="/chat") | ||
# # mock_response.assert_called_once_with("Hi", []) | ||
# self.assertEqual(result, "Mocked") | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,93 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
IMAGE_TAG="${1:-latest}" | ||
echo Testing image tag $IMAGE_TAG | ||
|
||
find_images() { | ||
images="" | ||
for dir in $(ls $1); do | ||
if [[ -f $1/$dir/Dockerfile ]]; then | ||
images+="$dir " | ||
fi | ||
done | ||
echo $images | ||
} | ||
|
||
image_name() { | ||
echo ghcr.io/stackhpc/azimuth-llm-$1-ui | ||
} | ||
|
||
build() { | ||
if [[ -f $1/Dockerfile ]]; then | ||
echo Building $1 docker image | ||
docker build . -t $(image_name $1) -f $1/Dockerfile | ||
else | ||
echo No Dockerfile found for $1 | ||
exit 1 | ||
fi | ||
} | ||
|
||
log () { | ||
echo | ||
echo $@ | ||
} | ||
|
||
test() { | ||
|
||
echo | ||
echo "----- Starting test process for $1 app -----" | ||
echo | ||
|
||
DOCKER_NET_NAME=azimuth-llm-shared | ||
if [[ ! $(docker network ls | grep $DOCKER_NET_NAME) ]]; then | ||
docker network create $DOCKER_NET_NAME | ||
fi | ||
|
||
if [[ -f $1/test.py ]]; then | ||
|
||
# Ensure app image is available | ||
IMAGE_NAME=$(image_name $1) | ||
if [[ $IMAGE_TAG == "latest" ]]; then | ||
build $1 | ||
else | ||
log "Pulling image $IMAGE_NAME:$IMAGE_TAG" | ||
docker pull $IMAGE_NAME:$IMAGE_TAG | ||
fi | ||
|
||
# Ensure Ollama instance is available | ||
if [[ $(curl -s localhost:11434) == "Ollama is running" ]]; then | ||
log "Using existing ollama process running on localhost:11434" | ||
else | ||
log "Ollama process not running - starting containerised server" | ||
docker run --rm --network $DOCKER_NET_NAME -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama | ||
sleep 3 | ||
docker exec -it ollama ollama pull smollm2:135m | ||
fi | ||
|
||
log "Starting Gradio app container" | ||
docker run --network $DOCKER_NET_NAME -d --name $1-app $IMAGE_NAME | ||
|
||
# Give the app time to start | ||
sleep 3 | ||
|
||
log "Running tests" | ||
docker run --network $DOCKER_NET_NAME --rm --name $1-test-suite -e GRADIO_URL=http://$1-app:7860 --entrypoint python $IMAGE_NAME test.py | ||
|
||
log "Removing containers:" | ||
docker rm -f ollama $1-app | ||
|
||
log "Removing docker network:" | ||
docker network rm $DOCKER_NET_NAME | ||
|
||
echo | ||
echo "----- Tests succeed -----" | ||
echo | ||
else | ||
echo No test.py file found for $1 app | ||
fi | ||
} | ||
|
||
for image in $(find_images .); do | ||
test $image | ||
done |