Skip to content

Commit

Permalink
new files/tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aus10powell committed Sep 14, 2024
1 parent abc79bf commit ff4151a
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
51 changes: 51 additions & 0 deletions code/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Project Name

## Running `run_pipeline.py`

To run the `run_pipeline.py` script directly, use the following command:

```bash
python code/src/run_pipeline.py
```

Make sure you have all the necessary dependencies installed. You can install them using:

```pip install -r requirements.txt```

Running Tests
To run the tests, you can use pytest. Run the following command:

To run the tests with coverage, use:

```pytest code/tests```

This will execute all the tests and provide a coverage report.

```pytest code/tests --cov=code/src```

## Example: Using pipeline.py in a new script

To use the `pipeline.py` in another script, follow these steps:

1. Create a new Python file (e.g., `new_script.py`) in your project directory.

2. Add the following code to `new_script.py`:

```python
from src.pipeline import main as pipeline_main

# Define your parameters
params = {
"video_path": "/path/to/your/video.mp4",
"OUTPUT_DIR": "/path/to/output/directory",
"tracker": "/path/to/tracker/config.yaml",
"model_path": "/path/to/model/weights.pt",
"write_to_local": True
}

# Run the pipeline and get the processed data
processed_data = pipeline_main(params)

# Now you can use processed_data as needed
print(processed_data)
```
23 changes: 23 additions & 0 deletions code/tests/test_utils/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pytest
from src.utils import video_utils


def test_extract_datetime_from_filename():
filename = "2_2018-04-14_10-06-19.mp4"
datetime = video_utils.extract_datetime_from_filename(filename)
assert str(datetime) == "2018-04-14 10:06:19"


def test_write_counts_to_json():
"""Expected behavior for output inference"""
data = {
"out_count": 10,
"in_count": 5,
"net_count": 5,
"frame_rate": 30,
"duration_seconds": 30,
"relative_frame_times": [0, 1, 2, 3, 4],
"frame_detections": [0, 1, 2, 3, 4],
}
video_utils.write_counts_to_json(data, "/tmp")
assert True
19 changes: 19 additions & 0 deletions code/tests/test_utils/test_video_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
from datetime import datetime
from src.utils.video_utils import extract_datetime_from_filename

def test_extract_datetime_from_filename_valid():
filename = "1234_2023-10-05_14-30-00.mp4"
expected_datetime = datetime(2023, 10, 5, 14, 30, 0)
result = extract_datetime_from_filename(filename)
assert result == expected_datetime

def test_extract_datetime_from_filename_invalid_format():
filename = "invalid_filename.mp4"
with pytest.raises(ValueError, match="Filename format doesn't match expected pattern"):
extract_datetime_from_filename(filename)

def test_extract_datetime_from_filename_invalid_date():
filename = "1234_2023-13-05_14-30-00.mp4" # Invalid month
with pytest.raises(ValueError, match="Invalid date or time format in filename"):
extract_datetime_from_filename(filename)

0 comments on commit ff4151a

Please sign in to comment.