Exemplo n.º 1
0
    def test_forgotten_end_fill(self):
        # SETUP
        expected_report = """\
create_line
    0
    0
    100
    0
    fill='#ff0000'
    pensize=1
create_line
    100
    0
    100
    100
    fill='#ff0000'
    pensize=1
"""

        # EXEC
        t = MockTurtle()
        t.color('red', 'blue')
        t.begin_fill()
        for _ in range(2):
            t.fd(100)
            t.right(90)
        report = t.report

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
Exemplo n.º 2
0
    def test_bgcolor(self):
        # SETUP
        expected_report = """\
bgcolor
    fill='#00ff00'
    outline=''
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1"""

        # EXEC
        t = MockTurtle()
        t.fd(100)
        color1 = t.screen.bgcolor()
        t.screen.bgcolor('green')
        color2 = t.screen.bgcolor()
        report = t.report

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
        self.assertEqual('white', color1)
        self.assertEqual('green', color2)
Exemplo n.º 3
0
def test_scale(patched_turtle):
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
create_line
    100
    0
    100
    150
    fill='black'
    pensize=1
"""

    t = MockTurtle(canvas=Canvas())
    t.screen.xscale = 100.0
    t.screen.yscale = 50
    t.fd(1)
    t.right(90)
    t.fd(3)
    report = t.report

    assert report == expected_report.splitlines()
Exemplo n.º 4
0
def test_write_font_list(patched_turtle):
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
create_text
    99
    0
    anchor='sw'
    fill='black'
    font=('Courier', 14, 'italic')
    text='Bob'
"""

    t = MockTurtle()
    t.fd(100)
    # noinspection PyTypeChecker
    t.write('Bob', font=['Courier', 14, 'italic'])
    report = t.report

    assert report == expected_report.splitlines()
Exemplo n.º 5
0
    def test_write_right(self):
        # SETUP
        expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
create_text
    100
    0
    anchor='se'
    fill='black'
    font=('Arial', 8, 'normal')
    text='Bob'
"""

        # EXEC
        t = MockTurtle()
        t.fd(100)
        t.write('Bob', align='right')
        report = t.report

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
Exemplo n.º 6
0
def test_write_font_none(patched_turtle):
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
create_text
    99
    0
    anchor='sw'
    fill='black'
    font=('Arial', 8, 'normal')
    text='Bob'
"""

    t = MockTurtle()
    t.fd(100)
    # noinspection PyTypeChecker
    t.write('Bob', font=None)
    report = t.report

    assert report == expected_report.splitlines()
Exemplo n.º 7
0
    def test_scale(self):
        # SETUP
        expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
create_line
    100
    0
    100
    150
    fill='black'
    pensize=1
"""

        # EXEC
        t = MockTurtle(canvas=Canvas())
        t.screen.xscale = 100.0
        t.screen.yscale = 50
        t.fd(1)
        t.right(90)
        t.fd(3)
        report = t.report

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
Exemplo n.º 8
0
def test_forgotten_end_fill(patched_turtle):
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='#ff0000'
    pensize=1
create_line
    100
    0
    100
    100
    fill='#ff0000'
    pensize=1
"""

    t = MockTurtle()
    t.color('red', 'blue')
    t.begin_fill()
    for _ in range(2):
        t.fd(100)
        t.right(90)
    report = t.report

    assert report == expected_report.splitlines()
Exemplo n.º 9
0
def test_repr():
    expected_text = "MockTurtle(100, 0, 10)"

    t = MockTurtle(25, 0, -7)
    t.left(7)
    t.fd(75)
    t.left(10)
    text = repr(t)

    assert text == expected_text
Exemplo n.º 10
0
    def test_repr(self):
        # SETUP
        expected_text = "MockTurtle(100, 0, 10)"

        # EXEC
        t = MockTurtle(25, 0, -7)
        t.left(7)
        t.fd(75)
        t.left(10)
        text = repr(t)

        # VERIFY
        self.assertEqual(expected_text, text)
Exemplo n.º 11
0
def test_color(patched_turtle):
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='#ff0080'
    pensize=1"""

    t = MockTurtle()
    t.color(1.0, 0.0, 0.5)
    t.fd(100)
    report = t.report

    assert report == expected_report.splitlines()
Exemplo n.º 12
0
def test_forward(patched_turtle):
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
"""

    t = MockTurtle()
    t.fd(100)
    report = t.report

    assert report == expected_report.splitlines()
Exemplo n.º 13
0
def test_pen_dict(patched_turtle):
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='#0000ff'
    pensize=1"""

    t = MockTurtle()
    t.pen(pencolor=(0, 0, 1.0))
    t.fd(100)
    report = t.report

    assert report == expected_report.splitlines()
Exemplo n.º 14
0
def test_color_bad_range(patched_turtle):
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='#000000'
    pensize=1"""

    t = MockTurtle()
    t.color(1.0, 0.0, 1.5)  # Over 1.0 not allowed, fails to black.
    t.fd(100)
    report = t.report

    assert report == expected_report.splitlines()
Exemplo n.º 15
0
def test_color_name(patched_turtle):
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='#0000ff'
    pensize=1"""

    t = MockTurtle()
    t.color('blue')
    t.fd(100)
    report = t.report

    assert report == expected_report.splitlines()
Exemplo n.º 16
0
def test_colormode():
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='#007fff'
    pensize=1"""

    t = MockTurtle()
    t.getscreen().colormode(255)
    t.color(0, 127, 255)
    t.fd(100)
    report = t.report

    assert report == expected_report.splitlines()
Exemplo n.º 17
0
def test_offset():
    MockTurtle.remove_monkey_patch()
    expected_report = """\
create_line
    400
    300
    500
    300
    fill='black'
    pensize=1
"""

    t = MockTurtle(canvas=Canvas(800, 600))
    t.fd(100)
    report = t.report

    assert report == expected_report.splitlines()
Exemplo n.º 18
0
def test_color_bad(patched_turtle):
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='#000000'
    pensize=1"""

    t = MockTurtle()
    # noinspection PyTypeChecker
    t.color((1.0, 0.0))  # Only two numbers, fails to black.
    t.fd(100)
    report = t.report

    assert report == expected_report.splitlines()
Exemplo n.º 19
0
def test_bad_colour(patched_turtle, colour_in, expected_error):
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1"""

    t = MockTurtle()
    t.fd(100)
    with pytest.raises(TurtleGraphicsError, match=re.escape(expected_error)):
        turtle.color(colour_in)
    report = t.report

    assert report == expected_report.splitlines()
Exemplo n.º 20
0
    def test_pen_dict(self):
        # SETUP
        expected_report = """\
create_line
    0
    0
    100
    0
    fill='#0000ff'
    pensize=1"""

        # EXEC
        t = MockTurtle()
        t.pen(pencolor=(0, 0, 1.0))
        t.fd(100)
        report = t.report

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
Exemplo n.º 21
0
    def test_color_bad(self):
        # SETUP
        expected_report = """\
create_line
    0
    0
    100
    0
    fill='#000000'
    pensize=1"""

        # EXEC
        t = MockTurtle()
        t.color((1.0, 0.0))  # Only two numbers, fails to black.
        t.fd(100)
        report = t.report

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
Exemplo n.º 22
0
    def test_color_bad_range(self):
        # SETUP
        expected_report = """\
create_line
    0
    0
    100
    0
    fill='#000000'
    pensize=1"""

        # EXEC
        t = MockTurtle()
        t.color(1.0, 0.0, 1.5)  # Over 1.0 not allowed, fails to black.
        t.fd(100)
        report = t.report

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
Exemplo n.º 23
0
    def test_color_name(self):
        # SETUP
        expected_report = """\
create_line
    0
    0
    100
    0
    fill='#0000ff'
    pensize=1"""

        # EXEC
        t = MockTurtle()
        t.color('blue')
        t.fd(100)
        report = t.report

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
Exemplo n.º 24
0
    def test_color(self):
        # SETUP
        expected_report = """\
create_line
    0
    0
    100
    0
    fill='#ff0080'
    pensize=1"""

        # EXEC
        t = MockTurtle()
        t.color(1.0, 0.0, 0.5)
        t.fd(100)
        report = t.report

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
Exemplo n.º 25
0
    def test_forward(self):
        # SETUP
        expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
"""

        # EXEC
        t = MockTurtle()
        t.fd(100)
        report = t.report

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
Exemplo n.º 26
0
    def test_offset(self):
        # SETUP
        expected_report = """\
create_line
    400
    300
    500
    300
    fill='black'
    pensize=1
"""

        # EXEC
        t = MockTurtle(canvas=Canvas(800, 600))
        t.fd(100)
        report = t.report

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
Exemplo n.º 27
0
def test_offset_with_scale():
    """ The offset is applied BEFORE the scale. """

    MockTurtle.remove_monkey_patch()
    expected_report = """\
create_line
    400
    300
    500
    300
    fill='black'
    pensize=1
"""

    t = MockTurtle(canvas=Canvas(800, 600))
    t.screen.xscale = 100
    t.fd(1)
    report = t.report

    assert report == expected_report.splitlines()
Exemplo n.º 28
0
def test_reset(patched_turtle):
    expected_report = """\
create_line
    0
    0
    0
    100
    fill='black'
    pensize=1
"""

    t = MockTurtle()
    t.color('blue')
    t.fd(100)
    t.reset()
    t.right(90)
    t.fd(100)
    report = t.report

    assert report == expected_report.splitlines()
Exemplo n.º 29
0
    def test_penup(self):
        # SETUP
        expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
create_line
    150
    0
    350
    0
    fill='#000000'
    pensize=1
"""

        # EXEC
        t = MockTurtle()
        t.fd(100)
        t.penup()
        t.fd(50)
        t.pendown()
        t.fd(200)
        report = t.report

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
Exemplo n.º 30
0
def test_penup(patched_turtle):
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
create_line
    150
    0
    350
    0
    fill='#000000'
    pensize=1
"""

    t = MockTurtle()
    t.fd(100)
    t.penup()
    t.fd(50)
    t.pendown()
    t.fd(200)
    report = t.report

    assert report == expected_report.splitlines()