-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathsetup_tests.py
More file actions
92 lines (71 loc) · 3.27 KB
/
setup_tests.py
File metadata and controls
92 lines (71 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""This script downloads the test data archive and sets up the testing environment for DeepEthogram.
`gdown` is included in the `dev` dependency group, so run `uv sync --dev` first.
"""
import sys
import zipfile
from pathlib import Path
import gdown
import requests
def download_file(url, destination):
"""Downloads a file from a URL to a destination with progress indication."""
response = requests.get(url, stream=True)
total_size = int(response.headers.get("content-length", 0))
block_size = 8192
if total_size == 0:
print("Warning: Content length not provided by server")
print(f"Downloading to: {destination}")
with open(destination, "wb") as f:
downloaded = 0
for data in response.iter_content(block_size):
downloaded += len(data)
f.write(data)
# Print progress
if total_size > 0:
progress = int(50 * downloaded / total_size)
sys.stdout.write(f"\r[{'=' * progress}{' ' * (50 - progress)}] {downloaded}/{total_size} bytes")
sys.stdout.flush()
print("\nDownload completed!")
def setup_tests():
"""Sets up the testing environment for DeepEthogram."""
try:
# 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)
# 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 gpu tests will take a few minutes to complete.")
return True
except Exception as e:
print(f"Error during setup: {str(e)}")
return False
if __name__ == "__main__":
setup_tests()