Example #1
0
 def do_square(self, arg):
     """Draw Square"""
     self.results.writeToFile("Drawing a square")
     command = IntegerParser.parse(self, arg)
     directions = [0, 90, 180, 270]
     for i in directions:
         TurtleDrawer.draw_line(self, i, command)
Example #2
0
 def action(self):
     new_exception_handling = ExceptionHandler(
         "TIGr went wrong and stopped")
     argument = arg_parser()
     if argument.file:
         self.r.reader.set_file(argument.file)
         self.r.reader.set_parser(
             TigrParser(TurtleDrawer(), new_exception_handling))
     else:
         # read from input at prompt
         print("Enter your commands. Ctrl + Z to exit or finish.")
         # only on windows, if this was portable we should add the linux interrupt command x3
         print(
             "If no commands are entered, you will be prompted for a file name."
         )
         source = sys.stdin.readlines()
         self.r.reader.set_parser(
             TigrParser(TurtleDrawer(), new_exception_handling))
         self.r.reader.set_source(source)
     self.r.go()
     time.sleep(10)
Example #3
0
 def do_W(self, arg):
     """Draw line 270 degrees : W 100"""
     command = IntegerParser.parse(self, arg)
     TurtleDrawer.draw_line(self, 270, command)
 > Enter your commands. Ctrl + Z to exit
 > If no commands are entered, you will be prompted for a file name.
 
 '''
 arg_parser = argparse.ArgumentParser(
     description="Extract filename if present")
 arg_parser.add_argument("-f",
                         "--file",
                         help="Name of the file",
                         default=None)
 args = arg_parser.parse_args()
 exception_handling = ExceptionHandler("TIGr went wrong and stopped")
 #have file condition
 if args.file:
     # file name provided - read input from file
     TigrReader(TigrParser(TurtleDrawer(), exception_handling),
                exception_handling,
                optional_file_name=args.file).go()
 # emptyfilecondition
 if args.file == '':
     TigrReader(TigrParser(TurtleDrawer(), exception_handling),
                exception_handling,
                optional_file_name=args.file).go()
 #no file condition
 else:
     # read from stdin
     # TODO examine if this section of the code can be incorporated within the class structure
     source = None
     if sys.stdin.isatty():
         # read from input at prompt
         print("Enter your commands. Ctrl + Z to exit or finish.")
Example #5
0
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
        try:
            self.drawer.select_pen(1)
        except:
            raised = True
        self.assertFalse(raised, "Error Raised")

    def test_select_pen_executes_range(self):
        """Test to confirm that the drawer's method select_pen runs without error"""
        raised = False
        try:
            self.drawer.select_pen(-10)
        except:
            raised = True
        self.assertTrue(raised, "Error Raised")

    def test_pen_down_executes(self):
        """Test to confirm that the drawer's method pen_down runs without error"""
        raised = False
        try:
            self.drawer.pen_down()
        except:
            raised = True
        self.assertFalse(raised, "Error Raised")

    def test_pen_up_executes(self):
        """Test to confirm that the drawer's method pen_down runs without error"""
        raised = False
        try:
            self.drawer.pen_up()
        except:
            raised = True
        self.assertFalse(raised, "Error Raised")

    def test_draw_line_executes_range(self):
        """Test to confirm that Method does not take value over its limits"""
        raised = False
        try:
            self.drawer.draw_line(400, 10)
        except:
            raised = True
        self.assertTrue(raised, "Error Raised")

    def test_go_along_executes(self):
        """Test to confirm that the drawer's method go_along runs without error"""
        raised = False
        try:
            self.drawer.go_along(20)
        except:
            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
        try:
            self.drawer.go_down(20)
        except:
            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
        try:
            self.drawer.draw_line(20, 20)
        except:
            raised = True
        self.assertFalse(raised, "Error Raised")

    def test_draw_line_executes_range(self):
        """Test to confirm that Method does not take value over its limits"""
        raised = False
        try:
            self.drawer.draw_line(400, 10)
        except:
            raised = True
        self.assertTrue(raised, "Error Raised")
Example #6
0
 def setUp(self):
     self.parser = TigrParser(TurtleDrawer())
     self.source = ["p 3", "-34 HJwA 232"]
     self.raw_source = "N 12"
Example #7
0
    > If no commands are entered, you will be prompted for a file name.
    
    '''
    arg_parser = argparse.ArgumentParser(
        description="Extract filename if present")
    arg_parser.add_argument("-f",
                            "--file",
                            help="Name of the file",
                            default=None)
    args = arg_parser.parse_args()
    the_exception_handler = TigrExceptionHandler(
        "TIGr encountered an error and had to exit")

    if args.file:
        # file name provided - read input from file
        TigrReader(RegexParser(CommandFactory(TurtleDrawer()),
                               the_exception_handler),
                   the_exception_handler,
                   optional_file_name=args.file).go()
    else:
        # read from stdin
        # TODO examine if this section of the code can be incorporated within the class structure
        source = None
        if sys.stdin.isatty():
            # read from input at prompt
            print("Enter your commands. Ctrl + Z to exit or finish.")
            # only on windows, if this was portable we should add the linux interrupt command x3
            print(
                "If no commands are entered, you will be prompted for a file name."
            )
            source = sys.stdin.readlines()
Example #8
0
 def do_S(self, arg):
     """Draw line 120 degrees : S 100"""
     self.results.writeToFile("Draw line 120 degrees : S", arg)
     command = IntegerParser.parse(self, arg)
     TurtleDrawer.draw_line(self, 180, command)
 def setUp(self):
     self.tkinterIntParser = IntegerParser(TurtleDrawer())
     self.source = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
 def setUp(self):
     self.tkinterParser = ArgumentParser(TurtleDrawer())
     self.source = ['-c', '-e', '-t', '-k', '-g']
Example #11
0
 def setUp(self):
     self.parser = TigrParser(TurtleDrawer())
     self.source = ["p 3"]
Example #12
0
 def setUp(self):
     self.source_reader = TigrReader(TigrParser(TurtleDrawer()))
Example #13
0
 def do_circle(self,arg):
     """Draw Circle"""
     command = IntegerParser.parse(self, arg)
     TurtleDrawer.draw_circle(self,command)
Example #14
0
 def do_square(self, arg):
     """Draw Square"""
     command = IntegerParser.parse(self, arg)
     directions = [0, 90, 180, 270]
     for i in directions:
         TurtleDrawer.draw_line(self, i, command)
Example #15
0
 def do_Y(self, arg):
     """Go Down : Y 100"""
     self.results.writeToFile("Go Along : Y", arg)
     command = IntegerParser.parse(self, arg)
     TurtleDrawer.go_down(self, command)
 def setUp(self):
     self.tkinterStrParser = StringParser(TurtleDrawer())
     self.source = ['-c', '-e', '-t', '-k', '-g']
Example #17
0
 def do_E(self, arg):
     """Draw line 90 degrees : E 100"""
     self.results.writeToFile("Draw line 90 degrees : E", arg)
     command = IntegerParser.parse(self, arg)
     TurtleDrawer.draw_line(self, 90, command)
 def setUp(self):
     self.Reader = ArgumentSourceReader(ArgumentParser(TurtleDrawer()))
     self.source = ['-e', '-t', '-k', '-g']
Example #19
0
 def do_W(self, arg):
     """Draw line 270 degrees : W 100"""
     self.results.writeToFile("Draw line 270 degrees : W", arg)
     command = IntegerParser.parse(self, arg)
     TurtleDrawer.draw_line(self, 270, command)
Example #20
0
    > If no commands are entered, you will be prompted for a file name.
    
    '''
    arg_parser = argparse.ArgumentParser(
        description="Extract filename if present")
    arg_parser.add_argument("-f",
                            "--file",
                            help="Name of the file",
                            default=None)
    args = arg_parser.parse_args()
    the_exception_handler = TigrExceptionHandler(
        "TIGr encountered an error and had to exit")

    if args.file:
        # file name provided - read input from file
        TigrReader(TigrParser(TurtleDrawer(), the_exception_handler),
                   the_exception_handler,
                   optional_file_name=args.file).go()
    else:
        # read from stdin
        # TODO examine if this section of the code can be incorporated within the class structure
        source = None
        if sys.stdin.isatty():
            # read from input at prompt
            print("Enter your commands. Ctrl + Z to exit or finish.")
            # only on windows, if this was portable we should add the linux interrupt command x3
            print(
                "If no commands are entered, you will be prompted for a file name."
            )
            source = sys.stdin.readlines()
        else:
Example #21
0
 def do_circle(self, arg):
     """Draw Circle"""
     self.results.writeToFile("Drawing a circle")
     command = IntegerParser.parse(self, arg)
     TurtleDrawer.draw_circle(self, command)
Example #22
0
 def do_P(self, arg):
     """Select Pen:  P 10"""
     self.results.writeToFile("Selected pen", arg)
     data = IntegerParser.parse(self, arg)
     TurtleDrawer.select_pen(self, data)
Example #23
0
 def drawTurtle(self):
     self._clearCanvas()
     self.draw(TurtleDrawer(self.canvas))
Example #24
0
 def do_U(self, arg):
     """Pen Up : U"""
     self.results.writeToFile("Pen is up", arg)
     command = StringParser.parse(self, arg)
     TurtleDrawer.pen_up(command)
Example #25
0
 def setUp(self):
     self.source_reader = TigrReader(TigrParser(TurtleDrawer()), None,
                                     "N30")
     self.no_source_reader = TigrReader(TigrParser(TurtleDrawer()), None,
                                        None)
Example #26
0
 def do_D(self, arg):
     """Pen Down : D"""
     self.results.writeToFile("Pen is down", arg)
     command = StringParser.parse(self, arg)
     TurtleDrawer.pen_down(command)
Example #27
0
 def setUp(self):
     self.drawer = TurtleDrawer()
Example #28
0
 def do_X(self, arg):
     """Go Along : X 100"""
     self.results.writeToFile("Go Along : X ", arg)
     command = IntegerParser.parse(self, arg)
     TurtleDrawer.go_along(self, command)
 def set_data_form_file_parser(self):
     self.the_reader.reader.set_data_form_file_parser(
         TigrParser(TurtleDrawer(), self.exception))
Example #30
0
 def do_S(self, arg):
     """Draw line 120 degrees : S 100"""
     command = IntegerParser.parse(self, arg)
     TurtleDrawer.draw_line(self, 180, command)