From 3a2d03f356fe4a8de2768db3484546c00d282c0a Mon Sep 17 00:00:00 2001 From: Bappadala Rohith Kumar Naidu <198095685+rohitkumarnaidu@users.noreply.github.com> Date: Mon, 27 Jul 2026 19:32:18 +0530 Subject: [PATCH] feat: add Dockerfile for containerized development (#37) --- .dockerignore | 48 +++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 26 ++++++++++++++++++++++++ tests/test_utils.py | 38 +++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 tests/test_utils.py diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6289b52 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,48 @@ +# Git +.git +.gitignore + +# Python +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg +.pytest_cache/ +.coverage +htmlcov/ + +# Logs and Backups +logs/ +backups/ + +# Node +node_modules/ +package-lock.json + +# Environment +.env +.venv +venv/ +ENV/ + +# IDEs +.vscode/ +.idea/ +*.swp +*.swo diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e1ed09a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM python:3.12-slim + +# Prevent Python from writing .pyc files and enable unbuffered output +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 + +# Set working directory +WORKDIR /app + +# Install system dependencies (git is required for the agent to commit/push) +RUN apt-get update && apt-get install -y --no-install-recommends \ + git \ + && rm -rf /var/lib/apt/lists/* + +# Install python dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the rest of the application +COPY . . + +# Ensure the entrypoint is executable +RUN chmod +x main.py + +# Entry command +ENTRYPOINT ["python", "main.py"] diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..39c3703 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,38 @@ +import pytest +from utils import calculate_average, find_max, normalize, parse_int_list + +def test_calculate_average(): + assert calculate_average([1, 2, 3, 4, 5]) == 3.0 + assert calculate_average([10, 20]) == 15.0 + with pytest.raises(ValueError, match="Cannot calculate average of an empty list"): + calculate_average([]) + +def test_find_max(): + assert find_max([1, 5, 3, 9, 2]) == 9 + assert find_max([-10, -5, -20]) == -5 + with pytest.raises(ValueError, match="Cannot find max of an empty list"): + find_max([]) + +def test_normalize(): + assert normalize([0, 5, 10]) == [0.0, 0.5, 1.0] + assert normalize([10, 20, 30, 40, 50]) == [0.0, 0.25, 0.5, 0.75, 1.0] + + with pytest.raises(ValueError, match="Cannot normalize an empty list"): + normalize([]) + + with pytest.raises(ValueError, match="Cannot normalize a constant list"): + normalize([5, 5, 5]) + +def test_parse_int_list(): + assert parse_int_list("1,2,3,4") == [1, 2, 3, 4] + assert parse_int_list(" 10 , 20, 30 ") == [10, 20, 30] + assert parse_int_list("-5,0,5") == [-5, 0, 5] + + with pytest.raises(ValueError, match="Input string is empty"): + parse_int_list("") + + with pytest.raises(ValueError, match="Input string is empty"): + parse_int_list(" ") + + with pytest.raises(ValueError, match="invalid integer in input"): + parse_int_list("1,2,abc,4")