Skip to content

Commit

Permalink
improve test download script
Browse files Browse the repository at this point in the history
  • Loading branch information
jbohnslav committed Jan 12, 2025
1 parent fda76e2 commit 1b201a2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 23 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ jobs:
pip install pytest pytest-cov
python setup.py develop
- name: Setup test data
run: |
python setup_tests.py
- name: GPU Tests
run: |
pytest -v -m "gpu" tests/
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, windows-latest, macos-12]
os: [ubuntu-20.04, windows-latest, macos-13]

steps:
- uses: actions/checkout@v3
Expand All @@ -35,7 +35,7 @@ jobs:
choco install ffmpeg
- name: Install FFMPEG (macOS)
if: matrix.os == 'macos-12'
if: matrix.os == 'macos-13'
run: |
brew install ffmpeg
Expand All @@ -55,6 +55,10 @@ jobs:
pip install pytest pytest-cov
python setup.py develop
- name: Setup test data
run: |
python setup_tests.py
- name: Run CPU tests
run: |
pytest -v -m "not gpu" tests/
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ pytorch_lightning==1.6.5
ruff>=0.1.0
pre-commit>=2.20.0,<3.0.0
setuptools
gdown
4 changes: 4 additions & 0 deletions reset_venv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ uv pip install pytest pytest-cov
echo "Installing package in editable mode..."
uv pip install -e .

# Setup test data
echo "Setting up test data..."
python setup_tests.py

# Run tests
echo "Running tests..."
pytest -v tests/
52 changes: 31 additions & 21 deletions setup_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,39 +38,49 @@ def download_file(url, destination):

def setup_tests():
"""Sets up the testing environment for DeepEthogram."""

# Create tests/DATA directory if it doesn't exist
tests_dir = Path("tests")
data_dir = tests_dir / "DATA"
data_dir.mkdir(parents=True, exist_ok=True)

# Download the test archive
zip_path = data_dir / "testing_deepethogram_archive.zip"

try:
print("Downloading test data archive...")
gdown.download(id="1IFz4ABXppVxyuhYik8j38k9-Fl9kYKHo", output=str(zip_path), quiet=False)
# Create tests/DATA directory if it doesn't exist
tests_dir = Path("tests")
data_dir = tests_dir / "DATA"
data_dir.mkdir(parents=True, exist_ok=True)

print("Extracting archive...")
with zipfile.ZipFile(zip_path, "r") as zip_ref:
zip_ref.extractall(data_dir)

# Verify the extraction
# Define paths and requirements
archive_path = data_dir / "testing_deepethogram_archive"
zip_path = data_dir / "testing_deepethogram_archive.zip"
required_items = ["DATA", "models", "project_config.yaml"]

# Check if test data already exists and is complete
if archive_path.exists():
missing_items = [item for item in required_items if not (archive_path / item).exists()]
if not missing_items:
print("Test data already exists and appears complete. Skipping download.")
return True
print("Test data exists but is incomplete. Re-downloading...")

# Download and extract if needed
if not archive_path.exists() or not all((archive_path / item).exists() for item in required_items):
# Download if zip doesn't exist
if not zip_path.exists():
print("Downloading test data archive...")
gdown.download(id="1IFz4ABXppVxyuhYik8j38k9-Fl9kYKHo", output=str(zip_path), quiet=False)

# Extract archive
print("Extracting archive...")
with zipfile.ZipFile(zip_path, "r") as zip_ref:
zip_ref.extractall(data_dir)

# Clean up zip file after successful extraction
zip_path.unlink()

# Final verification
missing_items = [item for item in required_items if not (archive_path / item).exists()]

if missing_items:
print(f"Warning: The following items are missing: {missing_items}")
return False

print("Setup completed successfully!")
print("\nYou can now run the tests using: pytest tests/")
print("Note: The zz_commandline test module will take a few minutes to complete.")

# Clean up the zip file
zip_path.unlink()
print("Note: The gpu tests will take a few minutes to complete.")
return True

except Exception as e:
Expand Down

0 comments on commit 1b201a2

Please sign in to comment.