Skip to content

Commit

Permalink
Add new tests suiteS
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelPeczek-Roboflow committed Nov 27, 2024
1 parent e26727a commit f669696
Show file tree
Hide file tree
Showing 7 changed files with 610 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: INTEGRATION TESTS - inference CLI + inference CORE

on:
pull_request:
branches: [main]
push:
branches: [main]
workflow_dispatch:

jobs:
call_is_mergeable:
uses: ./.github/workflows/is_mergeable.yml
secrets: inherit
build-dev-test:
needs: call_is_mergeable
if: ${{ github.event_name != 'pull_request' || needs.call_is_mergeable.outputs.mergeable_state != 'not_clean' }}
runs-on:
labels: depot-ubuntu-22.04-small
group: public-depot
timeout-minutes: 30
strategy:
matrix:
python-version: ["3.9", "3.10"]
steps:
- name: 🛎️ Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: 🐍 Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
check-latest: true
- name: 📦 Cache Python packages
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements/**') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
- name: 📦 Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools
pip install --extra-index-url https://download.pytorch.org/whl/cpu -r requirements/_requirements.txt -r requirements/requirements.cpu.txt -r requirements/requirements.sdk.http.txt -r requirements/requirements.test.unit.txt -r requirements/requirements.http.txt -r requirements/requirements.yolo_world.txt -r requirements/requirements.doctr.txt -r requirements/requirements.sam.txt -r requirements/requirements.transformers.txt -r requirements/requirements.cli.txt -r requirements/requirements.sdk.http.txt
- name: 🧪 Integration Tests of Inference CLI
run: RUN_TESTS_WITH_INFERENCE_PACKAGE=True INFERENCE_CLI_TESTS_API_KEY=${{ secrets.LOAD_TEST_PRODUCTION_API_KEY }} python -m pytest tests/inference_cli/integration_tests/test_workflows.py
2 changes: 1 addition & 1 deletion .github/workflows/integration_tests_inference_cli_x86.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
pip install --upgrade setuptools
pip install -r requirements/requirements.cli.txt -r requirements/requirements.sdk.http.txt -r requirements/requirements.test.unit.txt
- name: 🧪 Integration Tests of Inference CLI
run: python -m pytest tests/inference_cli/integration_tests
run: RUN_TESTS_EXPECTING_ERROR_WHEN_INFERENCE_NOT_INSTALLED=True INFERENCE_CLI_TESTS_API_KEY=${{ secrets.LOAD_TEST_PRODUCTION_API_KEY }} python -m pytest tests/inference_cli/integration_tests
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,6 @@ docs/workflows/gallery/*
!tests/workflows/integration_tests/execution/assets/rock_paper_scissors/*.jpg
!tests/workflows/unit_tests/core_steps/models/third_party/assets/*.png
!tests/workflows/integration_tests/execution/assets/*.png

tests/inference_cli/integration_tests/assets/test_images/
inference_profiling
tests/inference_sdk/unit_tests/http/inference_profiling
7 changes: 7 additions & 0 deletions inference_cli/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ def ensure_inference_is_installed() -> None:
try:
from inference import get_model
except Exception as error:
if (
os.getenv("ALLOW_INTERACTIVE_INFERENCE_INSTALLATION", "True").lower()
== "false"
):
raise InferencePackageMissingError(
"You need to install `inference` package to use this feature. Run `pip install inference`"
) from error
print(
"You need to have `inference` package installed. Do you want the package to be installed? [YES/no]"
)
Expand Down
13 changes: 3 additions & 10 deletions inference_cli/lib/workflows/video_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _flush_stream_buffer(self, stream_idx: int) -> None:
content = self._structured_results_buffer[stream_idx]
if len(content) == 0:
return None
file_path = generate_results_chunk_file_name(
file_path = generate_results_file_name(
output_directory=self._output_directory,
results_log_type=self._output_file_type,
stream_id=stream_idx,
Expand All @@ -119,22 +119,15 @@ def __del__(self):
self.flush()


def generate_results_chunk_file_name(
def generate_results_file_name(
output_directory: str,
results_log_type: OutputFileType,
stream_id: int,
) -> str:
output_directory = os.path.abspath(output_directory)
chunks = glob(
os.path.join(
output_directory,
f"workflow_results_source_{stream_id}_part_*.{results_log_type.value}",
)
)
chunk_id = len(chunks)
return os.path.join(
output_directory,
f"workflow_results_source_{stream_id}_part_{chunk_id}.{results_log_type.value}",
f"workflow_results_source_{stream_id}.{results_log_type.value}",
)


Expand Down
66 changes: 66 additions & 0 deletions tests/inference_cli/integration_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,76 @@
import os.path
import tempfile
from typing import Generator

import pytest
import requests

ASSETS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "assets"))
IMAGES_URLS = [
"https://source.roboflow.com/BTRTpB7nxxjUchrOQ9vT/aFq7tthQAK6d4pvtupX7/original.jpg",
"https://source.roboflow.com/BTRTpB7nxxjUchrOQ9vT/KmFskd2RQMfcnDNjzeeA/original.jpg",
"https://source.roboflow.com/BTRTpB7nxxjUchrOQ9vT/3FBCYL5SX7VPrg0OVkdN/original.jpg",
"https://source.roboflow.com/BTRTpB7nxxjUchrOQ9vT/K2KrTzjxYu0kJCScGcoH/original.jpg",
"https://source.roboflow.com/BTRTpB7nxxjUchrOQ9vT/XzDB9zVrIxJm17iVKleP/original.jpg",
"https://source.roboflow.com/BTRTpB7nxxjUchrOQ9vT/0fsReHjmHk3hBadXdNk4/original.jpg",
"https://source.roboflow.com/BTRTpB7nxxjUchrOQ9vT/t23lZ0inksJwRRLd3J1b/original.jpg",
"https://source.roboflow.com/BTRTpB7nxxjUchrOQ9vT/3iCH40NuJxcf8l2tXgQn/original.jpg",
]
VIDEO_URL = "https://media.roboflow.com/inference/people-walking.mp4"

INFERENCE_CLI_TESTS_API_KEY = os.getenv("INFERENCE_CLI_TESTS_API_KEY")
RUN_TESTS_WITH_INFERENCE_PACKAGE = (
os.getenv("RUN_TESTS_WITH_INFERENCE_PACKAGE", "False").lower() == "true"
)
RUN_TESTS_EXPECTING_ERROR_WHEN_INFERENCE_NOT_INSTALLED = (
os.getenv("RUN_TESTS_EXPECTING_ERROR_WHEN_INFERENCE_NOT_INSTALLED", "False").lower()
== "true"
)


@pytest.fixture(scope="function")
def empty_directory() -> Generator[str, None, None]:
with tempfile.TemporaryDirectory() as tmp_dir:
yield tmp_dir


@pytest.fixture(scope="function")
def example_env_file_path() -> str:
return os.path.abspath(
os.path.join(os.path.dirname(__file__), "assets", "example.env")
)


@pytest.fixture
def dataset_directory() -> str:
dataset_directory = os.path.join(ASSETS_DIR, "test_images")
os.makedirs(dataset_directory, exist_ok=True)
expected_video_name = "video.mp4"
current_content = set(os.listdir(dataset_directory))
all_images_present = all(
f"{i}.jpg" in current_content for i in range(len(IMAGES_URLS))
)
if all_images_present and expected_video_name in current_content:
return dataset_directory
for i, image_url in enumerate(IMAGES_URLS):
response = requests.get(image_url)
response.raise_for_status()
image_bytes = response.content
with open(os.path.join(dataset_directory, f"{i}.jpg"), "wb") as f:
f.write(image_bytes)
response = requests.get(VIDEO_URL)
response.raise_for_status()
video_bytes = response.content
with open(os.path.join(dataset_directory, "video.mp4"), "wb") as f:
f.write(video_bytes)
return dataset_directory


@pytest.fixture
def video_to_be_processed(dataset_directory: str) -> str:
return os.path.join(dataset_directory, "video.mp4")


@pytest.fixture
def image_to_be_processed(dataset_directory: str) -> str:
return os.path.join(dataset_directory, "0.jpg")
Loading

0 comments on commit f669696

Please sign in to comment.