chore: initialize containerized Python learning workbook (2026 DevOps/SRE)
This commit is contained in:
commit
ae4c421815
63 files changed
+1273
No files matched your search
@@ -0,0 +1,10 @@
|
||||
# 03 — Napisy i pliki (`f-string`, `pathlib.Path`, `with open`)
|
||||
|
||||
## Zadania (`strings_files.py`)
|
||||
1. `parse_key_value_lines(raw: str) -> dict[str, str]` — sparsuj linie `KEY=VALUE`, ignorując puste linie i komentarze `#`.
|
||||
2. `count_non_empty_lines(path: Path) -> int` — policz niepuste linie w pliku tekstowym (użyj `with path.open(...)` lub `read_text`).
|
||||
|
||||
## Uruchomienie testów
|
||||
```bash
|
||||
make test MOD=01-core/03-strings-files
|
||||
```
|
||||
@@ -0,0 +1,9 @@
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def parse_key_value_lines(raw: str) -> dict[str, str]:
|
||||
raise NotImplementedError("Sparsuj linie KEY=VALUE, pomiń puste i zaczynające się od '#'")
|
||||
|
||||
|
||||
def count_non_empty_lines(path: Path) -> int:
|
||||
raise NotImplementedError("Policz niepuste (po strip) linie w pliku")
|
||||
@@ -0,0 +1,24 @@
|
||||
from pathlib import Path
|
||||
|
||||
from strings_files import count_non_empty_lines, parse_key_value_lines
|
||||
|
||||
|
||||
def test_parse_key_value_lines() -> None:
|
||||
raw = """
|
||||
# konfiguracja
|
||||
HOST=127.0.0.1
|
||||
PORT = 8080
|
||||
|
||||
DEBUG=true
|
||||
"""
|
||||
assert parse_key_value_lines(raw) == {
|
||||
"HOST": "127.0.0.1",
|
||||
"PORT": "8080",
|
||||
"DEBUG": "true",
|
||||
}
|
||||
|
||||
|
||||
def test_count_non_empty_lines(tmp_path: Path) -> None:
|
||||
sample = tmp_path / "sample.txt"
|
||||
sample.write_text("line1\n\n \nline2\nline3\n", encoding="utf-8")
|
||||
assert count_non_empty_lines(sample) == 3
|
||||
Reference in new issue
Block a user