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,12 @@
|
||||
# 01 — Podstawy (zmienne, warunki, pętle, funkcje)
|
||||
|
||||
## Zadania (`basics.py`)
|
||||
1. `celsius_to_fahrenheit(c: float) -> float` — przelicz temperaturę ($F = C \cdot 1.8 + 32$).
|
||||
2. `classify_score(score: int) -> str` — `0..49` -> `"fail"`, `50..74` -> `"pass"`, `75..89` -> `"good"`, `90..100` -> `"excellent"`, inaczej `"invalid"`.
|
||||
3. `sum_up_to(n: int) -> int` — suma liczb od `1` do `n` włącznie (dla `<= 0` zwróć `0`).
|
||||
4. `fizzbuzz_label(n: int) -> str` — `"Fizz"`, `"Buzz"`, `"FizzBuzz"` lub `str(n)`.
|
||||
|
||||
## Uruchomienie testów
|
||||
```bash
|
||||
make test MOD=01-core/01-basics
|
||||
```
|
||||
@@ -0,0 +1,14 @@
|
||||
def celsius_to_fahrenheit(c: float) -> float:
|
||||
raise NotImplementedError("Przelicz Celsjusze na Fahrenheity: c * 1.8 + 32.0")
|
||||
|
||||
|
||||
def classify_score(score: int) -> str:
|
||||
raise NotImplementedError("Sklasyfikuj wynik 0..100 lub zwróć 'invalid'")
|
||||
|
||||
|
||||
def sum_up_to(n: int) -> int:
|
||||
raise NotImplementedError("Zsumuj liczby od 1 do n włącznie")
|
||||
|
||||
|
||||
def fizzbuzz_label(n: int) -> str:
|
||||
raise NotImplementedError("Zwróć Fizz / Buzz / FizzBuzz lub str(n)")
|
||||
@@ -0,0 +1,30 @@
|
||||
import pytest
|
||||
from basics import celsius_to_fahrenheit, classify_score, fizzbuzz_label, sum_up_to
|
||||
|
||||
|
||||
def test_celsius_to_fahrenheit() -> None:
|
||||
assert celsius_to_fahrenheit(0.0) == pytest.approx(32.0)
|
||||
assert celsius_to_fahrenheit(100.0) == pytest.approx(212.0)
|
||||
assert celsius_to_fahrenheit(-40.0) == pytest.approx(-40.0)
|
||||
|
||||
|
||||
def test_classify_score() -> None:
|
||||
assert classify_score(0) == "fail"
|
||||
assert classify_score(50) == "pass"
|
||||
assert classify_score(80) == "good"
|
||||
assert classify_score(95) == "excellent"
|
||||
assert classify_score(101) == "invalid"
|
||||
assert classify_score(-1) == "invalid"
|
||||
|
||||
|
||||
def test_sum_up_to() -> None:
|
||||
assert sum_up_to(0) == 0
|
||||
assert sum_up_to(-5) == 0
|
||||
assert sum_up_to(10) == 55
|
||||
|
||||
|
||||
def test_fizzbuzz_label() -> None:
|
||||
assert fizzbuzz_label(1) == "1"
|
||||
assert fizzbuzz_label(3) == "Fizz"
|
||||
assert fizzbuzz_label(5) == "Buzz"
|
||||
assert fizzbuzz_label(15) == "FizzBuzz"
|
||||
@@ -0,0 +1,11 @@
|
||||
# 02 — Kolekcje (`list`, `tuple`, `dict`, `set`, slicing)
|
||||
|
||||
## Zadania (`collections_ex.py`)
|
||||
1. `unique_sorted(items: list[int]) -> list[int]` — usuń duplikaty i posortuj rosnąco.
|
||||
2. `word_counts(text: str) -> dict[str, int]` — policz wystąpienia słów (lowercase).
|
||||
3. `first_and_last(items: list[str]) -> tuple[str, str] | None` — zwróć pierwszy i ostatni element lub `None` dla pustej listy.
|
||||
|
||||
## Uruchomienie testów
|
||||
```bash
|
||||
make test MOD=01-core/02-collections
|
||||
```
|
||||
@@ -0,0 +1,10 @@
|
||||
def unique_sorted(items: list[int]) -> list[int]:
|
||||
raise NotImplementedError("Zwróć posortowaną listę unikalnych elementów")
|
||||
|
||||
|
||||
def word_counts(text: str) -> dict[str, int]:
|
||||
raise NotImplementedError("Policz wystąpienia słów (case-insensitive)")
|
||||
|
||||
|
||||
def first_and_last(items: list[str]) -> tuple[str, str] | None:
|
||||
raise NotImplementedError("Zwróć (pierwszy, ostatni) lub None dla pustej listy")
|
||||
@@ -0,0 +1,18 @@
|
||||
from collections_ex import first_and_last, unique_sorted, word_counts
|
||||
|
||||
|
||||
def test_unique_sorted() -> None:
|
||||
assert unique_sorted([3, 1, 2, 3, 1]) == [1, 2, 3]
|
||||
assert unique_sorted([]) == []
|
||||
|
||||
|
||||
def test_word_counts() -> None:
|
||||
counts = word_counts("Python python is great and PYTHON works")
|
||||
assert counts["python"] == 3
|
||||
assert counts["is"] == 1
|
||||
|
||||
|
||||
def test_first_and_last() -> None:
|
||||
assert first_and_last([]) is None
|
||||
assert first_and_last(["only"]) == ("only", "only")
|
||||
assert first_and_last(["a", "b", "c"]) == ("a", "c")
|
||||
@@ -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
|
||||
@@ -0,0 +1,10 @@
|
||||
# 04 — Błędy i Wyjątki (`try`/`except`, własne wyjątki)
|
||||
|
||||
## Zadania (`errors_ex.py`)
|
||||
1. `parse_positive_int(raw: str) -> int` — rzuć `InvalidNumberError`, gdy nie da się sparsować do `int`, lub `NotPositiveError`, gdy `<= 0`.
|
||||
2. `safe_divide(a: float, b: float) -> float | None` — zwróć `None` zamiast `ZeroDivisionError`.
|
||||
|
||||
## Uruchomienie testów
|
||||
```bash
|
||||
make test MOD=01-core/04-errors-exceptions
|
||||
```
|
||||
@@ -0,0 +1,14 @@
|
||||
class InvalidNumberError(ValueError):
|
||||
"""Błąd parsowania liczby."""
|
||||
|
||||
|
||||
class NotPositiveError(ValueError):
|
||||
"""Liczba nie jest dodatnia."""
|
||||
|
||||
|
||||
def parse_positive_int(raw: str) -> int:
|
||||
raise NotImplementedError("Sparsuj raw do int lub rzuć InvalidNumberError / NotPositiveError")
|
||||
|
||||
|
||||
def safe_divide(a: float, b: float) -> float | None:
|
||||
raise NotImplementedError("Podziel a / b, zwracając None dla b == 0")
|
||||
@@ -0,0 +1,17 @@
|
||||
import pytest
|
||||
from errors_ex import InvalidNumberError, NotPositiveError, parse_positive_int, safe_divide
|
||||
|
||||
|
||||
def test_parse_positive_int() -> None:
|
||||
assert parse_positive_int("42") == 42
|
||||
with pytest.raises(NotPositiveError):
|
||||
parse_positive_int("0")
|
||||
with pytest.raises(NotPositiveError):
|
||||
parse_positive_int("-3")
|
||||
with pytest.raises(InvalidNumberError):
|
||||
parse_positive_int("abc")
|
||||
|
||||
|
||||
def test_safe_divide() -> None:
|
||||
assert safe_divide(10.0, 2.0) == 5.0
|
||||
assert safe_divide(10.0, 0.0) is None
|
||||
@@ -0,0 +1,11 @@
|
||||
# 05 — Comprehensions, Generatory i Styl Funkcyjny
|
||||
|
||||
## Zadania (`functional_ex.py`)
|
||||
1. `even_squares(nums: list[int]) -> list[int]` — kwadraty liczb parzystych przez list comprehension.
|
||||
2. `invert_dict(mapping: dict[str, int]) -> dict[int, str]` — odwrócenie słownika przez dict comprehension.
|
||||
3. `fibonacci_gen(limit: int) -> Iterator[int]` — generator zwracający `limit` pierwszych liczb Fibonacciego (`0, 1, 1, 2, 3, ...`).
|
||||
|
||||
## Uruchomienie testów
|
||||
```bash
|
||||
make test MOD=01-core/05-comprehensions-functional
|
||||
```
|
||||
@@ -0,0 +1,13 @@
|
||||
from collections.abc import Iterator
|
||||
|
||||
|
||||
def even_squares(nums: list[int]) -> list[int]:
|
||||
raise NotImplementedError("Zwróć listę kwadratów liczb parzystych")
|
||||
|
||||
|
||||
def invert_dict(mapping: dict[str, int]) -> dict[int, str]:
|
||||
raise NotImplementedError("Zamień klucze z wartościami w słowniku")
|
||||
|
||||
|
||||
def fibonacci_gen(limit: int) -> Iterator[int]:
|
||||
raise NotImplementedError("Wygeneruj limit liczb Fibonacciego używając yield")
|
||||
@@ -0,0 +1,14 @@
|
||||
from functional_ex import even_squares, fibonacci_gen, invert_dict
|
||||
|
||||
|
||||
def test_even_squares() -> None:
|
||||
assert even_squares([1, 2, 3, 4, 5]) == [4, 16]
|
||||
|
||||
|
||||
def test_invert_dict() -> None:
|
||||
assert invert_dict({"a": 1, "b": 2}) == {1: "a", 2: "b"}
|
||||
|
||||
|
||||
def test_fibonacci_gen() -> None:
|
||||
assert list(fibonacci_gen(0)) == []
|
||||
assert list(fibonacci_gen(6)) == [0, 1, 1, 2, 3, 5]
|
||||
@@ -0,0 +1,10 @@
|
||||
# 06 — Obiektowość, `@dataclass` i `Protocol`
|
||||
|
||||
## Zadania (`oop_ex.py`)
|
||||
1. `BankAccount` — enkapsulacja salda (`_balance`), metody `deposit`, `withdraw -> bool`, właściwość `balance`.
|
||||
2. `Notifier` (`Protocol`) + `EmailNotifier`, `SmsNotifier` + `AlertService` (kompozycja).
|
||||
|
||||
## Uruchomienie testów
|
||||
```bash
|
||||
make test MOD=01-core/06-oop-dataclasses
|
||||
```
|
||||
@@ -0,0 +1,45 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import Protocol
|
||||
|
||||
|
||||
class BankAccount:
|
||||
def __init__(self, initial_balance: int = 0) -> None:
|
||||
self._balance = initial_balance
|
||||
|
||||
@property
|
||||
def balance(self) -> int:
|
||||
return self._balance
|
||||
|
||||
def deposit(self, amount: int) -> None:
|
||||
raise NotImplementedError("Dodaj amount do _balance (odrzuć <= 0 przez ValueError)")
|
||||
|
||||
def withdraw(self, amount: int) -> bool:
|
||||
raise NotImplementedError("Wypłać jeśli _balance >= amount i zwróć True, inaczej False")
|
||||
|
||||
|
||||
class Notifier(Protocol):
|
||||
def format_message(self, msg: str) -> str: ...
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class EmailNotifier:
|
||||
address: str
|
||||
|
||||
def format_message(self, msg: str) -> str:
|
||||
raise NotImplementedError("Zwróć '[email] <msg>'")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class SmsNotifier:
|
||||
phone: str
|
||||
|
||||
def format_message(self, msg: str) -> str:
|
||||
raise NotImplementedError("Zwróć '[sms] <msg>'")
|
||||
|
||||
|
||||
class AlertService:
|
||||
def __init__(self, notifiers: list[Notifier]) -> None:
|
||||
self._notifiers = notifiers
|
||||
|
||||
def broadcast(self, msg: str) -> list[str]:
|
||||
raise NotImplementedError("Wywołaj format_message(msg) dla każdego notifiera")
|
||||
@@ -0,0 +1,16 @@
|
||||
from oop_ex import AlertService, BankAccount, EmailNotifier, SmsNotifier
|
||||
|
||||
|
||||
def test_bank_account() -> None:
|
||||
acc = BankAccount(100)
|
||||
acc.deposit(50)
|
||||
assert acc.balance == 150
|
||||
assert acc.withdraw(40) is True
|
||||
assert acc.balance == 110
|
||||
assert acc.withdraw(500) is False
|
||||
assert acc.balance == 110
|
||||
|
||||
|
||||
def test_alert_service_protocol_composition() -> None:
|
||||
svc = AlertService([EmailNotifier("ops@example.com"), SmsNotifier("+48123456789")])
|
||||
assert svc.broadcast("CPU 95%") == ["[email] CPU 95%", "[sms] CPU 95%"]
|
||||
@@ -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>'")
|
||||
@@ -0,0 +1,11 @@
|
||||
# 08 — Struktury Danych (`Stack`, `Queue`, `Counter`, `defaultdict`)
|
||||
|
||||
## Zadania (`ds_ex.py`)
|
||||
1. `Stack[T]` — generyczny stos (`push`, `pop`, `peek`, `is_empty`).
|
||||
2. `Queue[T]` — generyczna kolejka na `collections.deque` (`enqueue`, `dequeue`, `__len__`).
|
||||
3. `top_k_frequent(items: list[str], k: int) -> list[str]` — zwróć `k` najczęstszych elementów używając `Counter`.
|
||||
|
||||
## Uruchomienie testów
|
||||
```bash
|
||||
make test MOD=01-core/08-data-structures
|
||||
```
|
||||
@@ -0,0 +1,37 @@
|
||||
from collections import Counter, deque
|
||||
|
||||
|
||||
class Stack[T]:
|
||||
def __init__(self) -> None:
|
||||
self._items: list[T] = []
|
||||
|
||||
def push(self, value: T) -> None:
|
||||
raise NotImplementedError("Dodaj element na wierzch stosu")
|
||||
|
||||
def pop(self) -> T | None:
|
||||
raise NotImplementedError("Zdejmij element lub zwróć None gdy pusty")
|
||||
|
||||
def peek(self) -> T | None:
|
||||
raise NotImplementedError("Podgląd wierzchu stosu bez zdejmowania")
|
||||
|
||||
def is_empty(self) -> bool:
|
||||
raise NotImplementedError("Zwróć True jeśli stos jest pusty")
|
||||
|
||||
|
||||
class Queue[T]:
|
||||
def __init__(self) -> None:
|
||||
self._items: deque[T] = deque()
|
||||
|
||||
def enqueue(self, value: T) -> None:
|
||||
raise NotImplementedError("Dodaj na koniec kolejki")
|
||||
|
||||
def dequeue(self) -> T | None:
|
||||
raise NotImplementedError("Zdejmij z początku kolejki lub zwróć None")
|
||||
|
||||
def __len__(self) -> int:
|
||||
return len(self._items)
|
||||
|
||||
|
||||
def top_k_frequent(items: list[str], k: int) -> list[str]:
|
||||
_ = Counter
|
||||
raise NotImplementedError("Zwróć k najczęstszych elementów używając Counter.most_common(k)")
|
||||
@@ -0,0 +1,26 @@
|
||||
from ds_ex import Queue, Stack, top_k_frequent
|
||||
|
||||
|
||||
def test_stack() -> None:
|
||||
s: Stack[int] = Stack()
|
||||
assert s.is_empty()
|
||||
s.push(1)
|
||||
s.push(2)
|
||||
assert s.peek() == 2
|
||||
assert s.pop() == 2
|
||||
assert s.pop() == 1
|
||||
assert s.pop() is None
|
||||
|
||||
|
||||
def test_queue() -> None:
|
||||
q: Queue[str] = Queue()
|
||||
q.enqueue("a")
|
||||
q.enqueue("b")
|
||||
assert len(q) == 2
|
||||
assert q.dequeue() == "a"
|
||||
assert q.dequeue() == "b"
|
||||
assert q.dequeue() is None
|
||||
|
||||
|
||||
def test_top_k_frequent() -> None:
|
||||
assert top_k_frequent(["pod", "svc", "pod", "ing", "pod", "svc"], 2) == ["pod", "svc"]
|
||||
@@ -0,0 +1,10 @@
|
||||
# 09 — Wzorce Projektowe w Pythonie (Strategy, Context Manager, DI)
|
||||
|
||||
## Zadania (`patterns_ex.py`)
|
||||
1. `apply_discount(price_cents: int, strategy: Callable[[int], int]) -> int` — wzorzec Strategy (w Pythonie funkcje są obiektami pierwszej klasy).
|
||||
2. `ManagedFlag` — Context Manager (`__enter__` ustawia `active = True`, `__exit__` zawsze przywraca `active = False`, nawet przy wyjątku).
|
||||
|
||||
## Uruchomienie testów
|
||||
```bash
|
||||
make test MOD=01-core/09-design-patterns
|
||||
```
|
||||
@@ -0,0 +1,26 @@
|
||||
from collections.abc import Callable
|
||||
from types import TracebackType
|
||||
|
||||
|
||||
def percentage_discount(percent: int) -> Callable[[int], int]:
|
||||
raise NotImplementedError("Zwróć funkcję obliczającą cenę po rabacie percent%")
|
||||
|
||||
|
||||
def apply_discount(price_cents: int, strategy: Callable[[int], int]) -> int:
|
||||
raise NotImplementedError("Zastosuj strategy do price_cents (nie zwracaj wartości < 0)")
|
||||
|
||||
|
||||
class ManagedFlag:
|
||||
def __init__(self) -> None:
|
||||
self.active: bool = False
|
||||
|
||||
def __enter__(self) -> "ManagedFlag":
|
||||
raise NotImplementedError("Ustaw self.active = True i zwróć self")
|
||||
|
||||
def __exit__(
|
||||
self,
|
||||
exc_type: type[BaseException] | None,
|
||||
exc_val: BaseException | None,
|
||||
exc_tb: TracebackType | None,
|
||||
) -> None:
|
||||
raise NotImplementedError("Ustaw self.active = False")
|
||||
@@ -0,0 +1,16 @@
|
||||
import pytest
|
||||
from patterns_ex import ManagedFlag, apply_discount, percentage_discount
|
||||
|
||||
|
||||
def test_strategy_discount() -> None:
|
||||
discount_20 = percentage_discount(20)
|
||||
assert apply_discount(1000, discount_20) == 800
|
||||
|
||||
|
||||
def test_context_manager_cleans_up_even_on_error() -> None:
|
||||
flag = ManagedFlag()
|
||||
assert flag.active is False
|
||||
with pytest.raises(RuntimeError), flag as entered:
|
||||
assert entered.active is True
|
||||
raise RuntimeError("boom")
|
||||
assert flag.active is False
|
||||
@@ -0,0 +1,9 @@
|
||||
# 10 — CRUD w pamięci (`TaskStore`)
|
||||
|
||||
## Zadania (`crud_ex.py`)
|
||||
Zaimplementuj pełny CRUD w `TaskStore`: `create`, `get`, `list_all`, `update_title`, `mark_done`, `delete` z wyjątkami `InvalidTitleError` i `TaskNotFoundError`.
|
||||
|
||||
## Uruchomienie testów
|
||||
```bash
|
||||
make test MOD=01-core/10-crud-repository
|
||||
```
|
||||
@@ -0,0 +1,42 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
class InvalidTitleError(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
class TaskNotFoundError(KeyError):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Task:
|
||||
id: int
|
||||
title: str
|
||||
done: bool = False
|
||||
|
||||
|
||||
class TaskStore:
|
||||
def __init__(self) -> None:
|
||||
self._next_id = 1
|
||||
self._tasks: dict[int, Task] = {}
|
||||
|
||||
def create(self, title: str) -> Task:
|
||||
raise NotImplementedError("Zwaliduj tytuł, utwórz Task z auto-ID i zapisz")
|
||||
|
||||
def get(self, task_id: int) -> Task | None:
|
||||
raise NotImplementedError("Zwróć Task lub None")
|
||||
|
||||
def list_all(self) -> list[Task]:
|
||||
raise NotImplementedError("Zwróć wszystkie zadania posortowane po id")
|
||||
|
||||
def update_title(self, task_id: int, title: str) -> Task:
|
||||
raise NotImplementedError(
|
||||
"Zaktualizuj tytuł lub rzuć InvalidTitleError / TaskNotFoundError"
|
||||
)
|
||||
|
||||
def mark_done(self, task_id: int) -> Task:
|
||||
raise NotImplementedError("Ustaw done=True lub rzuć TaskNotFoundError")
|
||||
|
||||
def delete(self, task_id: int) -> Task:
|
||||
raise NotImplementedError("Usuń i zwróć zadanie lub rzuć TaskNotFoundError")
|
||||
@@ -0,0 +1,23 @@
|
||||
import pytest
|
||||
from crud_ex import InvalidTitleError, TaskNotFoundError, TaskStore
|
||||
|
||||
|
||||
def test_crud_lifecycle() -> None:
|
||||
store = TaskStore()
|
||||
with pytest.raises(InvalidTitleError):
|
||||
store.create(" ")
|
||||
|
||||
t1 = store.create("Learn Python")
|
||||
t2 = store.create("Automate K8s")
|
||||
assert t1.id == 1
|
||||
assert t2.id == 2
|
||||
assert len(store.list_all()) == 2
|
||||
|
||||
updated = store.update_title(1, "Master Python")
|
||||
assert updated.title == "Master Python"
|
||||
assert store.mark_done(1).done is True
|
||||
|
||||
deleted = store.delete(2)
|
||||
assert deleted.id == 2
|
||||
with pytest.raises(TaskNotFoundError):
|
||||
store.delete(2)
|
||||
Reference in new issue
Block a user