Exemple #1
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()
    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)
Exemple #3
0
def test_get_color_names():
    t = MockTurtle()
    t.color('blue')
    color = t.color()

    # Before Python 3.6, dicts were not ordered, and either name was possible.
    assert color in (('blue', 'blue'), ('blue1', 'blue1'))
Exemple #4
0
def test_get_color_rgb():
    t = MockTurtle()
    expected_color = (1.0, 0.0, 0.5)
    t.color(expected_color)
    color = t.color()

    assert color == (expected_color, expected_color)
    def test_get_color_rgb(self):
        t = MockTurtle()
        expected_color = (1.0, 0.0, 0.5)
        t.color(expected_color)
        color = t.color()

        self.assertEqual((expected_color, expected_color), color)
Exemple #6
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()
Exemple #7
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()
Exemple #8
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()
Exemple #9
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()
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()
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)):
        t.color(colour_in)
    report = t.report

    assert report == expected_report.splitlines()
    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)
    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)
    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)
    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)
Exemple #16
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()
Exemple #17
0
def test_forgotten_end_fill_with_stamp(patched_turtle):
    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
"""

    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()
    def test_get_default_color(self):
        t = MockTurtle()
        color = t.color()

        self.assertEqual(('black', 'black'), color)
    def test_get_color_names(self):
        t = MockTurtle()
        t.color('blue')
        color = t.color()

        self.assertIn(color, (('blue', 'blue'), ('blue1', 'blue1')))
Exemple #20
0
def test_get_default_color():
    t = MockTurtle()
    color = t.color()

    assert color == ('black', 'black')