Add pytest dependency and initial unit test
parent
8a425c0741
commit
4479a3339f
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"terminal.integrated.profiles.linux": {
|
||||
"bash": {
|
||||
"path": "bash",
|
||||
"icon": "terminal-bash"
|
||||
}
|
||||
}
|
||||
{
|
||||
"terminal.integrated.profiles.linux": {
|
||||
"bash": {
|
||||
"path": "bash",
|
||||
"icon": "terminal-bash"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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}")
|
||||
|
|
@ -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)
|
||||
Loading…
Reference in New Issue