| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4c4d5b4 commit 4ea6a32
186 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,9 +1,26 @@ | |||
| 1 | + import importlib | ||
| 1 | 2 | from decimal import Decimal | |
| 2 | - from unittest.mock import patch | ||
| 3 | + from types import ModuleType | ||
| 3 | 4 | ||
| 5 | + import pytest | ||
| 4 | 6 | from sqlmodel import create_engine | |
| 5 | 7 | ||
| 6 | - from ...conftest import get_testing_print_function | ||
| 8 | + from ...conftest import PrintMock, needs_py310 | ||
| 9 | + | ||
| 10 | + | ||
| 11 | + @pytest.fixture( | ||
| 12 | + name="mod", | ||
| 13 | + params=[ | ||
| 14 | + "tutorial001", | ||
| 15 | + pytest.param("tutorial001_py310", marks=needs_py310), | ||
| 16 | + ], | ||
| 17 | + ) | ||
| 18 | + def get_module(request: pytest.FixtureRequest) -> ModuleType: | ||
| 19 | + mod = importlib.import_module(f"docs_src.advanced.decimal.{request.param}") | ||
| 20 | + mod.sqlite_url = "sqlite://" | ||
| 21 | + mod.engine = create_engine(mod.sqlite_url) | ||
| 22 | + return mod | ||
| 23 | + | ||
| 7 | 24 | ||
| 8 | 25 | expected_calls = [ | |
| 9 | 26 | [ | |
@@ -30,15 +47,6 @@ | |||
| 30 | 47 | ] | |
| 31 | 48 | ||
| 32 | 49 | ||
| 33 | - def test_tutorial(): | ||
| 34 | - from docs_src.advanced.decimal import tutorial001 as mod | ||
| 35 | - | ||
| 36 | - mod.sqlite_url = "sqlite://" | ||
| 37 | - mod.engine = create_engine(mod.sqlite_url) | ||
| 38 | - calls = [] | ||
| 39 | - | ||
| 40 | - new_print = get_testing_print_function(calls) | ||
| 41 | - | ||
| 42 | - with patch("builtins.print", new=new_print): | ||
| 43 | - mod.main() | ||
| 44 | - assert calls == expected_calls | ||
| 50 | + def test_tutorial(print_mock: PrintMock, mod: ModuleType): | ||
| 51 | + mod.main() | ||
| 52 | + assert print_mock.calls == expected_calls | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,31 +1,38 @@ | |||
| 1 | - from unittest.mock import patch | ||
| 1 | + import importlib | ||
| 2 | + from types import ModuleType | ||
| 2 | 3 | ||
| 4 | + import pytest | ||
| 3 | 5 | from dirty_equals import IsUUID | |
| 4 | 6 | from sqlmodel import create_engine | |
| 5 | 7 | ||
| 6 | - from ...conftest import get_testing_print_function | ||
| 8 | + from ...conftest import PrintMock, needs_py310 | ||
| 7 | 9 | ||
| 8 | 10 | ||
| 9 | - def test_tutorial() -> None: | ||
| 10 | - from docs_src.advanced.uuid import tutorial001 as mod | ||
| 11 | - | ||
| 11 | + @pytest.fixture( | ||
| 12 | + name="mod", | ||
| 13 | + params=[ | ||
| 14 | + "tutorial001", | ||
| 15 | + pytest.param("tutorial001_py310", marks=needs_py310), | ||
| 16 | + ], | ||
| 17 | + ) | ||
| 18 | + def get_module(request: pytest.FixtureRequest) -> ModuleType: | ||
| 19 | + mod = importlib.import_module(f"docs_src.advanced.uuid.{request.param}") | ||
| 12 | 20 | mod.sqlite_url = "sqlite://" | |
| 13 | 21 | mod.engine = create_engine(mod.sqlite_url) | |
| 14 | - calls = [] | ||
| 22 | + return mod | ||
| 15 | 23 | ||
| 16 | - new_print = get_testing_print_function(calls) | ||
| 17 | 24 | ||
| 18 | - with patch("builtins.print", new=new_print): | ||
| 19 | - mod.main() | ||
| 20 | - first_uuid = calls[1][0]["id"] | ||
| 25 | + def test_tutorial(print_mock: PrintMock, mod: ModuleType) -> None: | ||
| 26 | + mod.main() | ||
| 27 | + first_uuid = print_mock.calls[1][0]["id"] | ||
| 21 | 28 | assert first_uuid == IsUUID(4) | |
| 22 | 29 | ||
| 23 | - second_uuid = calls[7][0]["id"] | ||
| 30 | + second_uuid = print_mock.calls[7][0]["id"] | ||
| 24 | 31 | assert second_uuid == IsUUID(4) | |
| 25 | 32 | ||
| 26 | 33 | assert first_uuid != second_uuid | |
| 27 | 34 | ||
| 28 | - assert calls == [ | ||
| 35 | + assert print_mock.calls == [ | ||
| 29 | 36 | ["The hero before saving in the DB"], | |
| 30 | 37 | [ | |
| 31 | 38 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,31 +1,38 @@ | |||
| 1 | - from unittest.mock import patch | ||
| 1 | + import importlib | ||
| 2 | + from types import ModuleType | ||
| 2 | 3 | ||
| 4 | + import pytest | ||
| 3 | 5 | from dirty_equals import IsUUID | |
| 4 | 6 | from sqlmodel import create_engine | |
| 5 | 7 | ||
| 6 | - from ...conftest import get_testing_print_function | ||
| 8 | + from ...conftest import PrintMock, needs_py310 | ||
| 7 | 9 | ||
| 8 | 10 | ||
| 9 | - def test_tutorial() -> None: | ||
| 10 | - from docs_src.advanced.uuid import tutorial002 as mod | ||
| 11 | - | ||
| 11 | + @pytest.fixture( | ||
| 12 | + name="mod", | ||
| 13 | + params=[ | ||
| 14 | + "tutorial002", | ||
| 15 | + pytest.param("tutorial002_py310", marks=needs_py310), | ||
| 16 | + ], | ||
| 17 | + ) | ||
| 18 | + def get_module(request: pytest.FixtureRequest) -> ModuleType: | ||
| 19 | + mod = importlib.import_module(f"docs_src.advanced.uuid.{request.param}") | ||
| 12 | 20 | mod.sqlite_url = "sqlite://" | |
| 13 | 21 | mod.engine = create_engine(mod.sqlite_url) | |
| 14 | - calls = [] | ||
| 22 | + return mod | ||
| 15 | 23 | ||
| 16 | - new_print = get_testing_print_function(calls) | ||
| 17 | 24 | ||
| 18 | - with patch("builtins.print", new=new_print): | ||
| 19 | - mod.main() | ||
| 20 | - first_uuid = calls[1][0]["id"] | ||
| 25 | + def test_tutorial(print_mock: PrintMock, mod: ModuleType) -> None: | ||
| 26 | + mod.main() | ||
| 27 | + first_uuid = print_mock.calls[1][0]["id"] | ||
| 21 | 28 | assert first_uuid == IsUUID(4) | |
| 22 | 29 | ||
| 23 | - second_uuid = calls[7][0]["id"] | ||
| 30 | + second_uuid = print_mock.calls[7][0]["id"] | ||
| 24 | 31 | assert second_uuid == IsUUID(4) | |
| 25 | 32 | ||
| 26 | 33 | assert first_uuid != second_uuid | |
| 27 | 34 | ||
| 28 | - assert calls == [ | ||
| 35 | + assert print_mock.calls == [ | ||
| 29 | 36 | ["The hero before saving in the DB"], | |
| 30 | 37 | [ | |
| 31 | 38 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments