def test_write_font_none(patched_turtle):
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
create_text
    100
    0
    anchor='sw'
    fill='black'
    font=('Arial', 8, 'normal')
    text='Bob'
"""

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

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

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

    assert report == expected_report.splitlines()
Пример #3
0
def test_fill(patched_turtle):
    expected_report = """\
create_polygon
    0
    0
    100
    0
    100
    100
    fill='#0000ff'
    outline=''
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)
    t.end_fill()
    report = t.report

    assert report == expected_report.splitlines()
Пример #4
0
def test_write_right(patched_turtle):
    expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'
    pensize=1
create_text
    99
    0
    anchor='se'
    fill='black'
    font=('Arial', 8, 'normal')
    text='Bob'
"""

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

    assert report == expected_report.splitlines()
Пример #5
0
    def test_forgotten_end_fill_with_stamp(self):
        # SETUP
        expected_report = """\
create_polygon
    0
    0
    -9
    -5
    -7
    0
    -9
    5
    0
    0
    fill='#000000'
    outline=''
create_line
    0
    0
    -9
    -5
    fill='#000000'
    pensize=1
create_line
    -9
    -5
    -7
    0
    fill='#000000'
    pensize=1
create_line
    -7
    0
    -9
    5
    fill='#000000'
    pensize=1
create_line
    -9
    5
    0
    0
    fill='#000000'
    pensize=1
create_line
    0
    0
    100
    0
    fill='#ff0000'
    pensize=1
create_line
    100
    0
    100
    100
    fill='#ff0000'
    pensize=1
"""

        # EXEC
        t = MockTurtle()
        t.stamp()
        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)
Пример #6
0
    def test_get_default_color(self):
        t = MockTurtle()
        color = t.color()

        self.assertEqual(('black', 'black'), color)
Пример #7
0
    def test_get_color_names(self):
        t = MockTurtle()
        t.color('blue')
        color = t.color()

        self.assertIn(color, (('blue', 'blue'), ('blue1', 'blue1')))
Пример #8
0
 def test_write_move(self):
     """ Not supported yet """
     t = MockTurtle()
     with self.assertRaises(NotImplementedError):
         t.write('Bob', move=True)
Пример #9
0
def test_screen_methods_exist():
    """ Test that a couple of methods exist, but don't do anything. """
    t = MockTurtle()

    t.screen.tracer()
    t.screen.update()
Пример #10
0
def test_bad_attribute():
    t = MockTurtle()

    assert not hasattr(t, 'bogus')
Пример #11
0
def test_get_default_color():
    t = MockTurtle()
    color = t.color()

    assert color == ('black', 'black')
Пример #12
0
def test_write_bad_size():
    t = MockTurtle()
    with pytest.raises(ValueError):
        t.write('Bob', font=('Arial', 'eight', 'normal'))
Пример #13
0
def test_write_move():
    """ Not supported yet """
    t = MockTurtle()
    with pytest.raises(NotImplementedError):
        t.write('Bob', move=True)
Пример #14
0
def test_stamp_while_filling(patched_turtle):
    expected_report = """\
create_polygon
    0
    0
    40
    0
    40
    40
    0
    40
    fill='#008000'
    outline=''
create_line
    0
    0
    40
    0
    fill='black'
    pensize=4
create_line
    40
    0
    40
    40
    fill='black'
    pensize=4
create_line
    40
    40
    0
    40
    fill='black'
    pensize=4
create_polygon
    40
    0
    45
    -9
    40
    -7
    35
    -9
    fill='#008000'
    outline=''
create_line
    40
    0
    45
    -9
    fill='black'
    pensize=1
create_line
    45
    -9
    40
    -7
    fill='black'
    pensize=1
create_line
    40
    -7
    35
    -9
    fill='black'
    pensize=1
create_line
    35
    -9
    40
    0
    fill='black'
    pensize=1
"""

    t = MockTurtle()
    t.pensize(4)
    t.fillcolor('green')
    t.begin_fill()
    t.forward(40)
    t.right(90)
    t.stamp()
    t.forward(40)
    t.right(90)
    t.forward(40)
    t.end_fill()
    report = t.report

    assert report == expected_report.splitlines()
Пример #15
0
def test_forgotten_end_fill_with_stamp(patched_turtle):
    expected_report = """\
create_polygon
    0
    0
    -9
    -5
    -7
    0
    -9
    5
    fill='black'
    outline=''
create_line
    0
    0
    -9
    -5
    fill='black'
    pensize=1
create_line
    -9
    -5
    -7
    0
    fill='black'
    pensize=1
create_line
    -7
    0
    -9
    5
    fill='black'
    pensize=1
create_line
    -9
    5
    0
    0
    fill='black'
    pensize=1
create_line
    0
    0
    100
    0
    fill='#ff0000'
    pensize=1
create_line
    100
    0
    100
    100
    fill='#ff0000'
    pensize=1
"""

    t = MockTurtle()
    t.stamp()
    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()
Пример #16
0
def test_write_bad_size():
    t = MockTurtle()
    with pytest.raises(ValueError):
        # noinspection PyTypeChecker
        t.write('Bob', font=('Arial', 'eight', 'normal'))