Add pytest dependency and initial unit test

feature/interestingPoints
Matias Mas Viehl 2025-12-08 09:21:54 +01:00
parent 8a425c0741
commit 4479a3339f
6 changed files with 88 additions and 42 deletions

View File

@ -1,11 +1,11 @@
FROM python:3.11-slim
RUN apt-get update && apt-get install -y build-essential
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
USER $USERNAME
WORKDIR /workspace
FROM python:3.11-slim
RUN apt-get update && apt-get install -y build-essential
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
USER $USERNAME
WORKDIR /workspace

View File

@ -1,18 +1,19 @@
{
"name": "Python 3.11 Dev Container",
"dockerFile": "Dockerfile",
"mounts": [
"source=${localWorkspaceFolder},target=/workspace,type=bind"
],
"settings": {
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.provider": "black"
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance"
],
"postCreateCommand": "pip install --upgrade pip",
"remoteUser": "vscode"
}
{
"name": "Python 3.11 Dev Container",
"dockerFile": "Dockerfile",
"mounts": [
"source=${localWorkspaceFolder},target=/workspace,type=bind"
],
"settings": {
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.provider": "black"
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance"
],
"postCreateCommand": "pip install --upgrade pip && pip install pytest black",
"remoteUser": "vscode"
}

View File

@ -1,8 +1,8 @@
{
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash",
"icon": "terminal-bash"
}
}
{
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash",
"icon": "terminal-bash"
}
}
}

View File

@ -1,6 +1,6 @@
def main():
print("Hello, Dev Container World! 🚀")
print("Python Version:", __import__('sys').version)
if __name__ == "__main__":
main()
def main():
print("Hello, Dev Container World! 🚀")
print("Python Version:", __import__('sys').version)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,19 @@
# Datei: sum_calculator.py
def calculate_cumulative_sum(limit):
"""
Soll die kumulative Summe von 0 bis limit berechnen.
"""
total = 0
for i in range(limit):
total += i
return total
if __name__ == "__main__":
test_number = 5
result = calculate_cumulative_sum(test_number)
print(f"Die Zahl ist: {test_number}")
print(f"Ergebnis der Summe: {result}")

View File

@ -0,0 +1,26 @@
# Datei: test_sum_calculator.py
from sum_calculator import calculate_cumulative_sum
def test_sum_for_zero():
"""Testet den Randfall, wenn die Obergrenze 0 ist."""
# Arrange: Testdaten
limit = 0
# Act: Funktion aufrufen
result = calculate_cumulative_sum(limit)
# Assert: Überprüfen des Ergebnisses (0 erwartet)
assert result == 0
def test_sum_for_five():
"""Testet den allgemeinen Fall für die Zahl 5 (0+1+2+3+4+5 = 15)."""
# Arrange: Testdaten
limit = 5
# Act: Funktion aufrufen
result = calculate_cumulative_sum(limit)
# Assert: Überprüfen des Ergebnisses (15 erwartet)
assert result == 15
def test_sum_is_correct_type():
"""Testet, ob die Funktion einen Integer zurückgibt."""
# Arrange, Act, Assert
assert isinstance(calculate_cumulative_sum(3), int)