Esempio n. 1
0
 def test_unknown_method(self):
     # EXEC
     canvas = Canvas()
     with self.assertRaisesRegex(
             AttributeError,
             "(Canvas instance|'Canvas' object) has no attribute 'create_wirple'"
     ):
         canvas.create_wirple(1, 'floop')
Esempio n. 2
0
    def test_bounds(self):
        # SETUP
        expected_width = 800
        expected_height = 600
        # EXEC
        canvas = Canvas(expected_width, expected_height)
        width = canvas.cget('width')
        height = canvas.cget('height')

        # VERIFY
        self.assertEqual(expected_width, width)
        self.assertEqual(expected_height, height)
    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)
Esempio n. 4
0
    def test_create_line(self):
        # SETUP
        expected_report = """\
create_line
    1
    2
    100
    200"""

        # EXEC
        canvas = Canvas()
        canvas.create_line(1, 2, 100, 200)
        report = canvas.report

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
Esempio n. 5
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()
Esempio n. 6
0
    def test_create_line(self):
        # SETUP
        expected_report = """\
create_line
    1
    2
    100
    200"""

        # EXEC
        canvas = Canvas()
        # noinspection PyUnresolvedReferences
        canvas.create_line(1, 2, 100, 200)
        report = canvas.build_report()

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
def test_bounds():
    expected_width = 800
    expected_height = 600

    t = MockTurtle(canvas=Canvas(expected_width, expected_height))
    width = t.window_width()
    height = t.window_height()

    assert width == expected_width
    assert height == expected_height
Esempio n. 8
0
def test_bounds():
    expected_width = 800
    expected_height = 600

    t = MockTurtle(canvas=Canvas(expected_width, expected_height))
    width = t.getscreen().window_width()
    height = t.getscreen().window_height()
    size = t.getscreen().screensize()

    assert width == expected_width
    assert height == expected_height
    assert size == (expected_width, expected_height)
Esempio n. 9
0
    def test_create_text(self):
        # SETUP
        expected_report = """\
create_text
    100
    200
    anchor='s'
    font=('Arial', 8, 'normal')
    text='foo'"""

        # EXEC
        canvas = Canvas()
        canvas.create_text(100,
                           200,
                           text='foo',
                           font=('Arial', 8, 'normal'),
                           anchor='s')
        report = canvas.report

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
def test_bounds_after_monkey_patch():
    expected_width = 300
    expected_height = 200

    MockTurtle.monkey_patch(canvas=Canvas(expected_width, expected_height))
    try:
        width = turtle.window_width()
        height = turtle.window_height()
    finally:
        MockTurtle.remove_monkey_patch()

    assert width == expected_width
    assert height == expected_height
Esempio n. 11
0
    def test_bounds_after_monkey_patch(self):
        # SETUP
        expected_width = 300
        expected_height = 200

        # EXEC
        MockTurtle.monkey_patch(canvas=Canvas(expected_width, expected_height))
        width = turtle.window_width()  # @UndefinedVariable
        height = turtle.window_height()  # @UndefinedVariable

        # VERIFY
        self.assertEqual(expected_width, width)
        self.assertEqual(expected_height, height)
Esempio n. 12
0
    def test_create_text(self):
        # SETUP
        expected_report = """\
create_text
    100
    200
    anchor='s'
    font=('Arial', 8, 'normal')
    text='foo'"""

        # EXEC
        canvas = Canvas()
        # noinspection PyUnresolvedReferences
        canvas.create_text(100,
                           200,
                           text='foo',
                           font=('Arial', 8, 'normal'),
                           anchor='s')
        report = canvas.build_report()

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
Esempio n. 13
0
    def test_bounds(self):
        # SETUP
        expected_width = 800
        expected_height = 600

        # EXEC
        t = MockTurtle(canvas=Canvas(expected_width, expected_height))
        width = t.window_width()
        height = t.window_height()

        # VERIFY
        self.assertEqual(expected_width, width)
        self.assertEqual(expected_height, height)
Esempio n. 14
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()
Esempio n. 15
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)
Esempio n. 16
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()
Esempio n. 17
0
def test_display_image_position_with_size():
    expected_report = """\
create_image
    110
    180
    image='UE5HX0lNQUdFX0RBVEE='
"""

    MockTurtle.monkey_patch(Canvas(width=200, height=400))
    try:
        t = MockTurtle()
        image_data = b'PNG_IMAGE_DATA'

        LivePng(image_data).display((10, 20))

        report = t.report
    finally:
        MockTurtle.remove_monkey_patch()

    assert report == expected_report.splitlines()
Esempio n. 18
0
    def test_offset_with_scale(self):
        """ The offset is applied BEFORE the scale. """

        # SETUP
        expected_report = """\
create_line
    400
    300
    500
    300
    fill='black'
    pensize=1
"""

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

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
Esempio n. 19
0
    def test_multiple_calls(self):
        # SETUP
        expected_report = """\
create_line
    1
    2
    100
    200
create_rectangle
    5
    10
    500
    1000"""

        # EXEC
        canvas = Canvas()
        # noinspection PyUnresolvedReferences
        canvas.create_line(1, 2, 100, 200)
        # noinspection PyUnresolvedReferences
        canvas.create_rectangle(5, 10, 500, 1000)
        report = canvas.build_report()

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
Esempio n. 20
0
    def test_multiple_calls(self):
        # SETUP
        expected_report = """\
create_line
    1
    2
    100
    200
create_rectangle
    5
    10
    500
    1000"""

        # EXEC
        canvas = Canvas()
        canvas.create_line(1, 2, 100, 200)
        canvas.create_rectangle(5, 10, 500, 1000)
        report = canvas.report

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)