Ejemplo n.º 1
0
 def testName03(self):
     """ Testing invalid commands """
     mock = Mock(spec=ToyRobotInterpreter, **toy_robot_interpreter_attrs)
     ip = InputParser(mock)
     ip.process_line('PLACE 5,6,NORTH SPAM REPORT EGG')
     expected = [
         call.cmd_PLACE_handler('5,6,NORTH'),
         call.unhandled_keyword('SPAM'),
         call.cmd_REPORT_handler(None),
         call.unhandled_keyword('EGG')
     ]
     self.assertEqual(mock.method_calls, expected,
                      "method_calls not initialised correctly")
Ejemplo n.º 2
0
 def testName02(self):
     """ Testing PLACE called multiple times """
     mock = Mock(spec=ToyRobotInterpreter, **toy_robot_interpreter_attrs)
     ip = InputParser(mock)
     ip.process_line('PLACE 1,2,EAST MOVE PLACE 11,12,WEST REPORT')
     expected = [
         call.cmd_PLACE_handler('1,2,EAST'),
         call.cmd_MOVE_handler(None),
         call.cmd_PLACE_handler('11,12,WEST'),
         call.cmd_REPORT_handler(None)
     ]
     self.assertEqual(mock.method_calls, expected,
                      "method_calls not initialised correctly")
Ejemplo n.º 3
0
 def testName01(self):
     """ Testing all commands """
     mock = Mock(spec=ToyRobotInterpreter, **toy_robot_interpreter_attrs)
     ip = InputParser(mock)
     ip.process_line('PLACE 1,2,NORTH MOVE LEFT RIGHT REPORT')
     expected = [
         call.cmd_PLACE_handler('1,2,NORTH'),
         call.cmd_MOVE_handler(None),
         call.cmd_LEFT_handler(None),
         call.cmd_RIGHT_handler(None),
         call.cmd_REPORT_handler(None)
     ]
     self.assertEqual(mock.method_calls, expected,
                      "method_calls not initialised correctly")
	def test_parse(self) :
		print 'function test_parse'
		# create test data
		filenames = ['file1.txt', 'file2.txt', 'file3.txt']
		#filenames = ['oppskrifter kjøtt.txt', 'oppskrifter fisk.txt', 'oppskrifter kylling.txt']

		# write all files to disk
		for i, filename in enumerate(filenames) :
			file = open(filename, 'w')
			for line in self.files[i] :
				# write all lines to file
				# print 'writing to file ' + filenames[i] + ' line : ' + line
				file.write(line + '\n')
			file.close()

		# write the exclude file
		exclfilename = 'testexclude.txt'
		file = open(exclfilename, 'w')
		for line in self.excl :
			file.write(','.join(map(str, line)) + '\n')
		file.close()

		# normal input
		# filenames = ['oppskrifter kjøtt.txt', 'oppskrifter fisk.txt', 'oppskrifter kylling.txt']

		fileliststr = ','.join(filenames)
		print 'fileliststr :' + fileliststr
		numliststr = ','.join(map(str, self.nums))

		parser = InputParser()
		retval = parser.parse(fileliststr, numliststr, exclfilename)
		self.assertEqual(retval, 0)
		files = parser.files
		numlines = parser.numlines
		excllines = parser.excludelines

		print 'files {0}'.format(files)
		print 'numlines {0}'.format(numlines)
		print 'excllines {0}'.format(excllines)

		self.assertEqual(files, self.files)
		self.assertEqual(numlines, self.nums)
		self.assertEqual(excllines, self.excl)
Ejemplo n.º 5
0
 def __init__(self, data_dir):
     input_parser = InputParser(data_dir)
     self.data_dir = data_dir
     self.students = input_parser.parse_students()
     self.courses = input_parser.parse_courses()
     self.tests = input_parser.parse_tests()
     self.marks = input_parser.parse_marks(self.tests, self.courses)
    def testName03(self):
        """ Testing correct ToyRobot calls """
        robot_attrs = {
            'TRANSITIONS': ToyRobot.TRANSITIONS,
            'FACINGS': ToyRobot.FACINGS
        }
        toy = Mock(**robot_attrs)
        ip = InputParser(ToyRobotInterpreter(toy))
        ip.process_line(
            'PLACE 1,2,NORTH MOVE LEFT PLACE 3,4,EAST RIGHT REPORT')

        expected = [
            call.place(1, 2, 'NORTH'),
            call.move(),
            call.rotate_left(),
            call.place(3, 4, 'EAST'),
            call.rotate_right(),
            call.report()
        ]

        self.assertEqual(toy.method_calls, expected,
                         "methods not invoked correctly")
#

import math
import sys
from linerandomizer import LineRandomizer
from inputparser import InputParser
from argchecker import ArgChecker
from outputformatter import RecipeFormatter
from textoutput import TextOutput

# check arguments
argcheck = ArgChecker()
ok = argcheck.check(sys.argv)
# parse input
if ok != -1 : 
	parser = InputParser()
	# print argcheck.fileliststr
	ok = parser.parse (argcheck.fileliststr, argcheck.linenumberstr, argcheck.excludestr, argcheck.catstr)
	
	if ok != -1 :
		# process input
		processor = LineRandomizer()
		# print parser.files
		ok = processor.process(	parser.files, parser.numlines, parser.excludelines)
		if ok != -1 :
			# format output
			formatter = RecipeFormatter()
			formatter.headers = ['Oppskrifter', 'Ingredienser']
			# print processor.headers
			ok = formatter.format(processor.headers, processor.components, parser.categories)
			if ok != -1 :
Ejemplo n.º 8
0
#!/usr/bin/env python3

from sys import stdin

from toyrobot import ToyRobot
from toyrobotinterpreter import ToyRobotInterpreter
from inputparser import InputParser

if __name__ == '__main__':
    toy_robot = ToyRobot()
    inputparser = InputParser(ToyRobotInterpreter(toy_robot))

    for line in stdin:
        line = line.rstrip()
        if line == ':q':
            print('exiting..')
            break
        inputparser.process_line(line)
Ejemplo n.º 9
0
 def testName04(self):
     """ Testing invalid arguments in PLACE command """
     mock = Mock(spec=ToyRobotInterpreter, **toy_robot_interpreter_attrs)
     ip = InputParser(mock)
     ip.process_line('PLACE x,y,NORTH REPORT')
     mock.cmd_PLACE_handler.assert_called_once_with(None)