def test_update(patched_turtle):
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
create_line
    100
    0
    100
    200
    fill='black'
    pensize=1
"""
    t = turtle

    t.forward(100)
    t.tracer(10)
    t.right(90)
    t.forward(200)
    t.update()

    assert MockTurtle.get_all_reports() == expected_report.splitlines()
def test_cleared_screen(patched_turtle):
    """ Subclassing TurtleScreen can clear MockTurtle._pen object. """
    original = turtle.Turtle._pen
    turtle.Turtle._pen = None

    report = MockTurtle.get_all_reports()

    turtle.Turtle._pen = original
    assert report == []
Exemple #3
0
def test_monkey_patch_anonymous_turtle(patched_turtle):
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
"""

    turtle.fd(100)
    report = MockTurtle.get_all_reports()

    assert report == expected_report.splitlines()
    def test_monkey_patch_anonymous_turtle(self):
        MockTurtle.monkey_patch()
        expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
"""

        turtle.fd(100)  # @UndefinedVariable
        report = MockTurtle.get_all_reports()

        self.assertEqual(expected_report.splitlines(), report)
    def test_monkey_patch_multiple_turtles(self):
        MockTurtle.monkey_patch()
        expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
create_line
    100
    0
    100
    100
    fill='black'
    pensize=1
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
create_line
    100
    0
    100
    -100
    fill='black'
    pensize=1
"""

        t1 = turtle.Turtle()
        t1.begin_fill()
        t1.fd(100)
        t1.right(90)
        t1.fd(100)
        t2 = turtle.Turtle()
        t2.begin_fill()
        t2.fd(100)
        t2.left(90)
        t2.fd(100)
        report = MockTurtle.get_all_reports()

        self.maxDiff = None
        self.assertEqual(expected_report.splitlines(), report)
    def test_monkey_patch_new_turtle(self):
        MockTurtle.monkey_patch()
        expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
"""

        t = turtle.Turtle()
        t.fd(100)
        report = MockTurtle.get_all_reports()

        self.assertEqual(expected_report.splitlines(), report)
Exemple #7
0
def test_monkey_patch_multiple_turtles(patched_turtle):
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
create_line
    100
    0
    100
    100
    fill='black'
    pensize=1
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
create_line
    100
    0
    100
    -100
    fill='black'
    pensize=1
"""

    t1 = turtle.Turtle()
    t1.begin_fill()
    t1.fd(100)
    t1.right(90)
    t1.fd(100)
    t2 = turtle.Turtle()
    t2.begin_fill()
    t2.fd(100)
    t2.left(90)
    t2.fd(100)
    report = MockTurtle.get_all_reports()

    assert report == expected_report.splitlines()
def test_tracer(patched_turtle):
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
"""
    t = turtle

    default_tracer = t.tracer()
    t.forward(100)
    t.tracer(10)
    t.right(90)
    t.forward(200)

    assert default_tracer == 1
    assert MockTurtle.get_all_reports() == expected_report.splitlines()