当前位置: 首页>>代码示例>>Python>>正文


Python mock_turtle.MockTurtle类代码示例

本文整理汇总了Python中mock_turtle.MockTurtle的典型用法代码示例。如果您正苦于以下问题:Python MockTurtle类的具体用法?Python MockTurtle怎么用?Python MockTurtle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MockTurtle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_write

    def test_write(self):
        # SETUP
        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'
"""
        
        # EXEC
        t = MockTurtle()
        t.fd(100)
        t.write('Bob')
        report = t.report
        
        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
开发者ID:Amirus,项目名称:live-py-plugin,代码行数:27,代码来源:mock_turtle_test.py

示例2: test_bgcolor

    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)
开发者ID:donkirkby,项目名称:live-py-plugin,代码行数:26,代码来源:test_mock_turtle.py

示例3: test_get_color_rgb

    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)
开发者ID:ajinkyakulkarni,项目名称:live-py-plugin,代码行数:7,代码来源:mock_turtle_test.py

示例4: test_forgotten_end_fill

    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)
开发者ID:Amirus,项目名称:live-py-plugin,代码行数:30,代码来源:mock_turtle_test.py

示例5: test_stamp

    def test_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
"""

        # EXEC
        t = MockTurtle()
        t.stamp()
        report = t.report

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
开发者ID:ajinkyakulkarni,项目名称:live-py-plugin,代码行数:53,代码来源:mock_turtle_test.py

示例6: test_bounds

 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)
开发者ID:Amirus,项目名称:live-py-plugin,代码行数:13,代码来源:mock_turtle_test.py

示例7: test_bounds_after_monkey_patch

    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()
        height = turtle.window_height()

        # VERIFY
        self.assertEqual(expected_width, width)
        self.assertEqual(expected_height, height)
开发者ID:ajinkyakulkarni,项目名称:live-py-plugin,代码行数:13,代码来源:mock_turtle_test.py

示例8: main

def main():
    parser = argparse.ArgumentParser(description='Trace Python code.')
    parser.add_argument('-c',
                        '--canvas',
                        action='store_true',
                        help='Should canvas commands be printed?')
    parser.add_argument('-x',
                        '--width',
                        type=int,
                        default=800,
                        help='width of the canvas in pixels')
    parser.add_argument('-y',
                        '--height',
                        type=int,
                        default=600,
                        help='height of the canvas in pixels')
    parser.add_argument('-m',
                        '--module',
                        help='install traced code as a module with this name')

    args = parser.parse_args()
    code = sys.stdin.read()
    canvas = Canvas(args.width, args.height)
    tracer = CodeTracer(canvas)
    tracer.max_width = 200000
    code_report = tracer.trace_code(code, module_name=args.module)
    turtle_report = MockTurtle.get_all_reports()
    if turtle_report and args.canvas:
        print('start_canvas')
        print('\n'.join(turtle_report))
        print('end_canvas')
        print('.')
    print(code_report)
开发者ID:dgentry,项目名称:myDotfiles,代码行数:33,代码来源:code_tracer.py

示例9: test_monkey_patch_anonymous_turtle

    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)
        report = MockTurtle.get_all_reports()

        self.assertEqual(expected_report.splitlines(), report)
开发者ID:ajinkyakulkarni,项目名称:live-py-plugin,代码行数:16,代码来源:mock_turtle_test.py

示例10: test_monkey_patch_multiple_turtles

    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)
开发者ID:ajinkyakulkarni,项目名称:live-py-plugin,代码行数:47,代码来源:mock_turtle_test.py

示例11: test_forward

    def test_forward(self):
        # SETUP
        expected_report = """\
create_line
    0
    0
    100
    0
    fill='black'"""
        
        # EXEC
        t = MockTurtle()
        t.fd(100)
        report = t.report
        
        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
开发者ID:rohitkoul,项目名称:live-py-plugin,代码行数:17,代码来源:mock_turtle_test.py

示例12: test_scale

    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)
开发者ID:Amirus,项目名称:live-py-plugin,代码行数:31,代码来源:mock_turtle_test.py

示例13: test_color

    def test_color(self):
        # SETUP
        expected_report = """\
create_line
    0
    0
    100
    0
    fill='#ff0080'"""
        
        # EXEC
        t = MockTurtle()
        t.color(1.0, 0.0, 0.5)
        t.fd(100)
        report = t.report
        
        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
开发者ID:rohitkoul,项目名称:live-py-plugin,代码行数:18,代码来源:mock_turtle_test.py

示例14: test_offset

    def test_offset(self):
        # SETUP
        expected_report = """\
create_line
    400
    300
    500
    300
    fill='black'"""

        
        # EXEC
        t = MockTurtle(canvas=Canvas(800, 600))
        t.fd(100)
        report = t.report
        
        # VERIFY
        self.assertEqual(expected_report.splitlines(), report)
开发者ID:rohitkoul,项目名称:live-py-plugin,代码行数:18,代码来源:mock_turtle_test.py

示例15: test_color_bad_range

    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)
开发者ID:donkirkby,项目名称:live-py-plugin,代码行数:19,代码来源:test_mock_turtle.py


注:本文中的mock_turtle.MockTurtle类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。