def do_drawer(self, arg): """Select graphics library to draw with. Available drawers: text, turtle -----""" if self.drawer: self.drawer.shutdown() if arg.lower() == 'text': self.setup(TextDrawer()) elif arg.lower() == 'turtle': self.setup(TurtleDrawer()) else: print('Please select a valid drawer.')
def setUp(self): self.parser = Parser(TurtleDrawer()) self.source = ["p 3"]
def setUp(self): self.drawer = TurtleDrawer()
class DrawerTestCase(unittest.TestCase): def setUp(self): self.drawer = TurtleDrawer() def test_select_pen_exists(self): """Test to confirm that the drawer has a method called select_pen""" self.assertTrue("select_pen" in dir(TurtleDrawer)) def test_pen_down_exists(self): """Test to confirm that the drawer has a method called pen_down""" self.assertTrue("pen_down" in dir(TurtleDrawer)) def test_pen_up_exists(self): """Test to confirm that the drawer has a method called pen_up""" self.assertTrue("pen_up" in dir(TurtleDrawer)) def test_go_along_exists(self): """Test to confirm that the drawer has a method called go_along""" self.assertTrue("go_along" in dir(TurtleDrawer)) def test_go_down_exists(self): """Test to confirm that the drawer has a method called go_down""" self.assertTrue("go_down" in dir(TurtleDrawer)) def test_draw_line_exists(self): """Test to confirm that the drawer has a method called draw_line""" self.assertTrue("draw_line" in dir(TurtleDrawer)) def test_select_pen_executes(self): """Test to confirm that the drawer's method select_pen runs without error""" raised = False # noinspection PyBroadException try: self.drawer.select_pen(1) except Exception: raised = True self.assertFalse(raised, "Error Raised") def test_pen_up_executes(self): """Test to confirm that the drawer's method pen_up runs without error""" raised = False # noinspection PyBroadException try: self.drawer.pen_up() except Exception: raised = True self.assertFalse(raised, "Error Raised") def test_pen_down_executes(self): """Test to confirm that the drawer's method pen_down runs without error""" raised = False # noinspection PyBroadException try: self.drawer.pen_down() except Exception: raised = True self.assertFalse(raised, "Error Raised") def test_go_along_executes(self): """Test to confirm that the drawer's method go_along runs without error""" raised = False # noinspection PyBroadException try: self.drawer.go_along(20) except Exception: raised = True self.assertFalse(raised, "Error Raised") def test_go_down_executes(self): """Test to confirm that the drawer's method go_down runs without error""" raised = False # noinspection PyBroadException try: self.drawer.go_down(20) except Exception: raised = True self.assertFalse(raised, "Error Raised") def test_draw_line_executes(self): """Test to confirm that the drawer's method draw_line runs without error""" raised = False # noinspection PyBroadException try: self.drawer.draw_line(20, 20) except Exception: raised = True self.assertFalse(raised, "Error Raised")
def setUp(self): self.source_reader = SourceReader(Parser(TurtleDrawer()))
>>> source_reader.source = ['p 3', 'x 5', 'y 5', 'd' ,'e 5' ,'n 5' ,'w 5' ,'s 5' ,'u'] >>> source_reader.go() Selected pen 3.0 Gone to X=5.0 Gone to Y=5.0 Pen down drawing line of length 5.0 at 0 degrees drawing line of length 5.0 at 90 degrees drawing line of length 5.0 at 180 degrees drawing line of length 5.0 at 270 degrees Pen lifted End doctest """ def __init__(self, parser): super().__init__(parser) self.script_extension = '.tigr' def go(self): self.parser.parse(self.source) if __name__ == '__main__': import doctest from TIGrExParser import Parser from TIGrExTurtleDrawer import TurtleDrawer source_reader = SourceReader(Parser(TurtleDrawer())) doctest.testmod(verbose=3)