def start(): global _state if _state <= STOPPED: try: uos.stat("/code.py") except Exception: _state = CODE_MISSING return try: import code _state = CODE_IMPORTED if hasattr(code, "main"): if callable(code.main): code.main() _state = CODE_MAIN except ImportError as exc: _handle_error(exc, cleanup=False) except Exception as exc: _handle_error(exc, cleanup=True)
def test_answer_yes(self, mocked_input): mocked_input.side_effect = ['2', 'kiarash 20', 'bita 20'] self.assertEqual(code.main(), {'kiarash': 20, 'bita': 20}) # @patch('code.input', return_value='no') # def test_answer_no(self, input): # self.assertEqual(code.main("test input?"), 'no')
def test_random(self): user_input = [ '2', 'spanish', 'english', '3', 'Dhyey', 'y', '145', 'spanish', 'Navin', 'y', '100', 'spanish speaker', 'Varun', 'y', '200', 'english', 'Random', 'Random' ] user_function_input = [ '3', 'Dhyey', 'y', '145', 'spanish', 'Navin', 'y', '100', 'spanish speaker', 'Varun', 'y', '200', 'english', 'Random', 'Random' ] issue_lst = ['spanish', 'english'] with patch('builtins.input', side_effect=user_function_input): output0 = code.agent_selector_main(issue_lst) try: self.assertEqual(output0, [['Dhyey'], ['Varun']]) except: self.assertEqual(output0, [['Navin'], ['Varun']]) with patch('builtins.input', side_effect=user_input): output = code.main() self.assertEqual(output, "All Agent Selections for given Issues done.")
def test_mass_agents_mass_issue(self): user_input = [ '6', 'spanish', 'english', 'english', 'english', 'Hindi', 'Gujarati', '6', 'Dhyey', 'y', '145', 'spanish', 'Navin', 'y', '100', 'spanish speaker', 'Varun', 'y', '200', 'english', 'Dev', 'n', 'Gujarati', 'Ukshit', 'y', '55', 'Hindi', 'Stanley', 'n', 'english', 'All Available', 'Least Busy', 'Random', 'All Available', 'Least Busy', 'All Available' ] user_function_input = [ '6', 'Dhyey', 'y', '145', 'spanish', 'Navin', 'y', '100', 'spanish speaker', 'Varun', 'y', '200', 'english', 'Dev', 'n', 'Gujarati', 'Ukshit', 'y', '55', 'Hindi', 'Stanley', 'n', 'english', 'All Available', 'Least Busy', 'Random', 'All Available', 'Least Busy', 'All Available' ] issue_lst = [ 'spanish', 'english', 'english', 'english', 'Hindi', 'Gujarati' ] with patch('builtins.input', side_effect=user_function_input): output0 = code.agent_selector_main(issue_lst) self.assertEqual(output0, [['Dhyey', 'Navin'], ['Varun'], ['Varun'], ['Varun'], ['Ukshit'], "No agents available."]) with patch('builtins.input', side_effect=user_input): output = code.main() self.assertEqual(output, "All Agent Selections for given Issues done.")
def test_all_availaibe(self): user_input = [ '2', 'spanish', 'english', '6', 'Dhyey', 'y', '145', 'spanish', 'Navin', 'y', '100', 'spanish speaker', 'Varun', 'y', '200', 'english', 'Dev', 'n', 'english', 'Ukshit', 'y', '55', 'spanish', 'Stanley', 'n', 'english' 'All Available', 'All Available' ] user_function_input = [ '6', 'Dhyey', 'y', '145', 'spanish', 'Navin', 'y', '100', 'spanish speaker', 'Varun', 'y', '200', 'english', 'Dev', 'n', 'english', 'Ukshit', 'y', '55', 'spanish', 'Stanley', 'n', 'english' 'All Available', 'All Available' ] issue_lst = ['spanish', 'english'] with patch('builtins.input', side_effect=user_function_input): output0 = code.agent_selector_main(issue_lst) self.assertEqual(output0, [['Dhyey', 'Navin', 'Ukshit'], ['Varun']]) with patch('builtins.input', side_effect=user_input): output = code.main() self.assertEqual(output, "All Agent Selections for given Issues done.")
def parenthesis_post(): parenthesis = Parenthesis() if request.method == 'POST': int_array = [ int(i) for i in parenthesis.arr.raw_data[0].strip().split(',') ] output = main(int_array) parenthesis.output = output return render_template('parenthesis_python.html', form=parenthesis)
def test_n_insteadof_y(self): user_input = [ '2', 'spanish', 'english', '3', 'Dhyey', 'n', 'spanish', 'Navin', 'y', '100', 'spanish speaker', 'Varun', 'n', 'english', 'Random', 'Random' ] user_function_input = [ '3', 'Dhyey', 'n', 'spanish', 'Navin', 'y', '100', 'spanish speaker', 'Varun', 'n', 'english', 'Random', 'Random' ] issue_lst = ['spanish', 'english'] with patch('builtins.input', side_effect=user_function_input): output0 = code.agent_selector_main(issue_lst) self.assertEqual(output0, [['Navin'], "No agents available."]) with patch('builtins.input', side_effect=user_input): output = code.main() self.assertEqual(output, "All Agent Selections for given Issues done.")
def test_int_errors(self): user_input = [ '2ww', 'ww', '2', 'spanish', 'english', 'wee3', 'dsd', '3', 'Dhyey', 'y', '145', 'spanish', 'Navin', 'y', 'wer', '100', 'spanish speaker', 'Varun', 'y', '200', 'english', 'All Available', 'All Available' ] user_function_input = [ 'wee3', 'dsd', '3', 'Dhyey', 'y', '145', 'spanish', 'Navin', 'y', 'wer', '100', 'spanish speaker', 'Varun', 'y', '200', 'english', 'All Available', 'All Available' ] issue_lst = ['spanish', 'english'] with patch('builtins.input', side_effect=user_function_input): output0 = code.agent_selector_main(issue_lst) self.assertEqual(output0, [['Dhyey', 'Navin'], ['Varun']]) with patch('builtins.input', side_effect=user_input): output = code.main() self.assertEqual(output, "All Agent Selections for given Issues done.")
def run(self): code.main() self.exit()
def test_answer_yes(self, mocked_input): mocked_input.side_effect = ['4 4', '1 2 1', '2 3 0', '3 4 0', '2 4 0'] result = code.main() print(result) self.assertEqual(result, '2 3 2 1')
def test_answer_no(self, mocked_input): mocked_input.side_effect = ['4 3', '2 2 0', '2 3 1', '1 4 0'] result = code.main() print(result) self.assertEqual(code.main(), '-1')
import os os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (x, y) #imports import settings as s # (perso) contient les variables blobales from pygame import * # (system) pour la fenetre et ses interactions (evenements, etc...) import loop # (perso) verification pour la boucle principale import time # (system) permet de faire des pauses dans le code (lors de l'execution notament) from function import * # (perso) pour toutes les fonctions lourdes try: # on test si il y a quelque chose dans le main() de code.py import code # (perso) le code de l'utilisateur except IndentationError as ex: # gestion de l'erreur du main() vide print "nothing to do" s.init() # initialisation de toutes les variables globales print "looping..." print "ratio : ", sizes( )[2], "px" # le ratio est la taille des sprites utilises (ici 30x30 px) loop.loopCheck() # verifie si des conditions de sortie sont reunies dispMaze() # affiche le labyrinthe try: # si code est vide il y aura une erreur de nom code.main( ) # execute le contenu de la fonction 'main' dans le fichier 'code.py' except NameError: # gestion de l'erreur du non import de code.py pass # on continue comme si de rien n'etait print "execution over" # quand tout est termine print "end\npress enter key to quit" # on demande a l'utilisateur d'appuyer sur entrer while 1: # tant qu'il ne l'a pas fait loop.loopCheck(1) # verifie si il a appuyer sur une touche de sortie
def index(): return main()
def test_main(self): for sample in self.samples: self.assertEqual(main(sample[0], sample[1]), sample[2])
# s += "\n" # with open("input.txt", "w") as f: # f.write(str(N) + "\n") # f.write(str(MAX_FRUIT_TYPE) + "\n") # f.write("300.0\n") # f.write(s) PLAYER_1_TIME = TIME PLAYER_2_TIME = TIME while True: print "Calling Player2 code......" start = time.time() x, y = code.main() time_taken = time.time() - start print x, y score, matrix = runDfs(matrix, x, y, "PLAYER2") PLAYER_2_TIME -= time_taken if PLAYER_1_TIME < 0: print "Player 1 loses!! Time exceeded!" print "player1 total score: " + str(player1_score) print "player2's total score: " + str(player2_score) print "Player 1 time remaining: " + str(PLAYER_1_TIME) print "Player 2 time remaining: " + str(PLAYER_2_TIME) exit() writeToFile(2) player2_score += score