chore: initialize containerized Python learning workbook (2026 DevOps/SRE)

This commit is contained in:
soda64 committed 2026-11-30 22:55:56 +01:00
commit ae4c421815
63 files changed
+1273

No files matched your search

@@ -0,0 +1,10 @@
# 07 — Nowoczesne Typowanie (`Enum`, `TypedDict`, `mypy`)
## Zadania (`typing_ex.py`)
1. `parse_severity(raw: str) -> Severity` — zamień tekst (`"info"`, `"warn"`, `"error"`, case-insensitive) na `Severity` Enum (lub rzuć `ValueError`).
2. `summarize_incident(incident: IncidentRecord) -> str` — sformatuj `"[<SEVERITY>] <service>: <message>"`.
## Uruchomienie testów
```bash
make test MOD=01-core/07-typing-contracts
```
@@ -0,0 +1,18 @@
import pytest
from typing_ex import IncidentRecord, Severity, parse_severity, summarize_incident
def test_parse_severity() -> None:
assert parse_severity("warn") is Severity.WARN
assert parse_severity("ERROR") is Severity.ERROR
with pytest.raises(ValueError):
parse_severity("fatal")
def test_summarize_incident() -> None:
rec: IncidentRecord = {
"service": "ingress",
"severity": Severity.ERROR,
"message": "502 Bad Gateway",
}
assert summarize_incident(rec) == "[ERROR] ingress: 502 Bad Gateway"
@@ -0,0 +1,22 @@
from enum import Enum
from typing import TypedDict
class Severity(Enum):
INFO = "INFO"
WARN = "WARN"
ERROR = "ERROR"
class IncidentRecord(TypedDict):
service: str
severity: Severity
message: str
def parse_severity(raw: str) -> Severity:
raise NotImplementedError("Zmapuj tekst case-insensitive na Severity lub rzuć ValueError")
def summarize_incident(incident: IncidentRecord) -> str:
raise NotImplementedError("Zwróć '[<SEVERITY>] <service>: <message>'")