Add the Pen protocol, window helpers and a recording fake turtle
The drawing functions take a Pen, the part of turtle.Turtle they use, so a test can pass a fake that records every call. window.py is the only module that imports turtle, and it does so inside the functions so that importing the package needs no Tk. Task: MIL-002#1 Task: MIL-002#2
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from turtle_challenges.window import (
|
||||
TURTLE_UNAVAILABLE_MESSAGE,
|
||||
TurtleUnavailableError,
|
||||
create_pen,
|
||||
create_window,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def without_turtle(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Make `import turtle` fail, as on a Python without Tk."""
|
||||
monkeypatch.setitem(sys.modules, "turtle", None)
|
||||
|
||||
|
||||
def test_create_window_reports_a_missing_turtle(without_turtle: None) -> None:
|
||||
with pytest.raises(TurtleUnavailableError) as error_info:
|
||||
create_window()
|
||||
|
||||
assert str(error_info.value) == TURTLE_UNAVAILABLE_MESSAGE
|
||||
assert isinstance(error_info.value.__cause__, ImportError)
|
||||
|
||||
|
||||
def test_create_pen_reports_a_missing_turtle(without_turtle: None) -> None:
|
||||
with pytest.raises(TurtleUnavailableError):
|
||||
create_pen()
|
||||
|
||||
|
||||
def test_the_missing_turtle_message_names_the_debian_package() -> None:
|
||||
assert "python3-tk" in TURTLE_UNAVAILABLE_MESSAGE
|
||||
Reference in New Issue
Block a user