How to use print_failure method in Radish

Best Python code snippet using radish

m1t_test_CircleChanger.py

Source:m1t_test_CircleChanger.py Github

copy

Full Screen

...57 print('Expected:', expected)58 print('Actual: ', actual, flush=True)59 time.sleep(flush_time)60 if not passes_test:61 print_failure(flush_time=flush_time)62def is_a_number(x):63 """ Returns True if x is an int or a float. """64 return (type(x) is int) or (type(x) is float)65def print_failure(message=' *** FAILED the above test. ***',66 flush_time=0.05):67 """ Prints a message onto stderr, hence in RED. """68 print(message,69 file=sys.stderr, flush=True)70 time.sleep(flush_time)71def is_implemented(circle_changer_method, expected_lines=2):72 """ True if the given CircleChanger method is not yet implemenented. """73 # There is probably a better way to do this...74 method = getattr(m1.CircleChanger, circle_changer_method)75 source = inspect.getsource(method)76 doc_string = method.__doc__77 expected = source.replace(doc_string, '')78 lines_left = expected.splitlines()79 return len(lines_left) > expected_lines80# # [OLDER APPROACH} There is probably a better way to do this...81# method = getattr(m1.CircleChanger, circle_changer_method)82# source = inspect.getsource(method)83#84# docstring = re.search(r'""".*"""', source, re.DOTALL)85# code_wo_docstring = source.replace(docstring.group(0), '')86# code_wo_def = re.sub(r'def[^:]*:', '', code_wo_docstring)87# code_wo_comments = re.sub(r'#.*$', '', code_wo_def, re.MULTILINE)88# lines_of_code = code_wo_comments.splitlines()89# count = 090# for line in lines_of_code:91# if line.strip() == '':92# count = count + 193# # print(circle_changer_method, len(lines_of_code), count)94# return len(lines_of_code) - count > expected_lines95def start_drawing(title=None):96 global WINDOW97 if WINDOW:98 WINDOW.close()99 WINDOW = rg.RoseWindow(WIDTH, HEIGHT, title)100def draw(circle_changer, message=None):101 """102 Type hints:103 :type circle_changer: CircleChanger104 :type message: str105 """106 global WINDOW107 if not WINDOW:108 WINDOW = rg.RoseWindow(WIDTH, HEIGHT)109 circle_changer.circle.attach_to(WINDOW)110 WINDOW.render()111 if message is None:112 WINDOW.render(circle_changer.seconds_to_sleep *113 circle_changer.animation_factor)114 elif type(message) is float or type(message) is int:115 if message > 0:116 WINDOW.render(message * circle_changer.animation_factor)117 elif message:118 if WINDOW.title:119 prefix = WINDOW.title + '. You should see:\n'120 else:121 prefix = 'You should see:\n'122 suffix = '\nTo continue, click anywhere in this window.'123 screen_message = prefix + message.strip() + suffix124 from_bottom = HEIGHT - (12 * (screen_message.count('\n') + 1))125 WINDOW.continue_on_mouse_click(screen_message,126 y_position=from_bottom)127def evaluate_circle_changer(circle_changer,128 x, y, radius, color, thickness, colors):129 expected_circle = rg.Circle(rg.Point(x, y), radius)130 expected_circle.fill_color = color131 expected_circle.outline_thickness = thickness132 instance_variables = ('center', 'radius', 'fill_color',133 'outline_thickness')134 for instance_variable in instance_variables:135 expected = getattr(expected_circle, instance_variable)136 actual = getattr(circle_changer.circle, instance_variable)137 if isinstance(expected, rg.Point):138 expected = rg.Point(round(expected.x, 5),139 round(expected.y, 5))140 if isinstance(actual, rg.Point):141 actual = rg.Point(round(actual.x, 5),142 round(actual.y, 5))143 if isinstance(expected, float):144 expected = round(expected, 5)145 if isinstance(actual, float):146 actual = round(actual, 5)147 title = 'Testing the ' + instance_variable + ' attribute:'148 evaluate_test(expected, actual, title)149 evaluate_test(colors, circle_changer.colors,150 'Testing the colors attribute:')151########################################################################152# The TEST functions for the CircleChanger class begin here.153########################################################################154def run_test_init():155 """ Tests the __init__ method of the CircleChanger class. """156 print()157 print('-----------------------------------------------------------')158 print('Testing the __init__ method:')159 print('-----------------------------------------------------------')160 if not is_implemented('__init__', 20):161 return162 print('The following are OUR tests (from m1_tests):')163 colors = ('red', 'green', 'blue')164 circle_changers = []165 try:166 for k in range(1, 3):167 ac = m1.CircleChanger(100 * k,168 20 * k,169 50 + k,170 colors[k % len(colors)],171 k * colors)172 circle_changers.append(ac)173 except:174 print_failure()175 print_failure('Something broke in your __init__ function.')176 print_failure('The following error messages may be helpful.')177 raise178 for k in range(1, 3):179 for attribute in ('circle', 'colors'):180 try:181 getattr(circle_changers[k - 1], attribute)182 except AttributeError:183 print_failure()184 print_failure('Your Animate_Circle class does not seem')185 print_failure('to have a ' + attribute +186 ' instance variable.')187 print_failure('Stopping our tests of __init__ here.\n')188 return189 for attribute in ('fill_color', 'x', 'y'):190 if hasattr(circle_changers[k - 1], attribute):191 print_failure()192 print_failure(193 'Your Animate_Circle class seems to have\n'194 'instance variables that DUPLICATE information.\n\n'195 ' *** TALK TO YOUR INSTRUCTOR ABOUT THIS. ***\n\n'196 'Stopping our tests of __init__ here.\n')197 return198 if type(circle_changers[k - 1].circle) is not rg.Circle:199 print_failure()200 print_failure('Your circle instance variable')201 print_failure('does not seem to be an rg.Circle.')202 print_failure('Stopping tests of __init__ here.')203 if type(circle_changers[k - 1].colors) is not tuple:204 print_failure()205 print_failure('Your colors instance variable')206 print_failure('does not seem to be a tuple.')207 print_failure('Tuples are like lists, but with parentheses')208 print_failure("like this: ('red', 'blue', 'pink')")209 print_failure('Stopping tests of __init__ here.')210 evaluate_test(100 * k,211 circle_changers[k - 1].circle.center.x,212 'Testing x-coordinate of the circle attribute')213 evaluate_test(20 * k,214 circle_changers[k - 1].circle.center.y,215 'Testing y-coordinate of the circle attribute')216 evaluate_test(50 + k,217 circle_changers[k - 1].circle.radius,218 'Testing radius of the circle attribute')219 evaluate_test(colors[k % len(colors)],220 circle_changers[k - 1].circle.fill_color,221 'Testing fill_color of the circle attribute')222 evaluate_test(k * colors,223 circle_changers[k - 1].colors,...

Full Screen

Full Screen

board.py

Source:board.py Github

copy

Full Screen

1import heapq2from copy import deepcopy, copy3from math import inf4class Board:5 def __init__(self, rows, columns, player_1_pawns, player_2_pawns):6 self.rows = rows7 self.columns = columns8 self.num_placed_walls = 09 self.player_1_pawns = deepcopy(player_1_pawns)10 self.player_2_pawns = deepcopy(player_2_pawns)11 self.player_1_start = (copy(player_1_pawns[0]), copy(player_1_pawns[1]))12 self.player_2_start = (copy(player_2_pawns[0]), copy(player_2_pawns[1]))13 self.board = [[BoardSquare() for _ in range(columns)] for _ in range(rows)]14 self.board[player_1_pawns[0][0]][player_1_pawns[0][1]].set_start('X')15 self.board[player_1_pawns[1][0]][player_1_pawns[1][1]].set_start('X')16 self.board[player_2_pawns[0][0]][player_2_pawns[0][1]].set_start('O')17 self.board[player_2_pawns[1][0]][player_2_pawns[1][1]].set_start('O')18 def print_board(self):19 for i in range(2 * self.rows + 3):20 # When i and j are divisible by 2 index_i and index_j are board coordinates21 index_i = i // 2 - 122 for j in range(2 * self.columns + 3):23 index_j = j // 2 - 124 # Top-bottom border25 if i == 0 or i == 2 * self.rows + 2:26 if j == 0 or j == 2 * self.columns + 2 or j % 2 == 1:27 print(" ", end="")28 else:29 print(self.matrix_index_to_board_index(index_j), end="")30 elif i == 1 or i == 2 * self.rows + 1:31 if j == 0 or j == 2 * self.columns + 2 or j % 2 == 1:32 print(" ", end="")33 else:34 print("=", end="")35 # Square rows36 elif i % 2 == 0:37 # Left-right border38 if j == 0 or j == 2 * self.columns + 2:39 print(self.matrix_index_to_board_index(index_i), end="")40 elif j == 1 or j == 2 * self.columns + 1:41 print("‖", end="")42 # Squares43 elif j % 2 == 0:44 print(self.board[index_i][index_j].center, end="")45 # Left-right walls46 else:47 print("‖" if self.board[index_i][index_j].right else "|", end="")48 # Top-bottom wall rows49 # Top-bottom walls50 elif j != 0 and j != 2 * self.columns + 2 and j % 2 == 0:51 print("=" if self.board[index_i][index_j].bottom else "—", end="")52 else:53 print(" ", end="")54 print()55 def game_end(self):56 return self.player_1_pawns[0] in self.player_2_start or self.player_1_pawns[1] in self.player_2_start or \57 self.player_2_pawns[0] in self.player_1_start or self.player_2_pawns[1] in self.player_1_start58 def valid_pawn_move(self, player, pawn_index, row, column, print_failure=True):59 # Check if pawn indices are in range60 if row >= self.rows or column >= self.columns:61 self.conditional_print("Pawn indices are out of bounds!", print_failure)62 return False63 prev_pos = self.player_1_pawns[pawn_index] if player == 'X' else self.player_2_pawns[pawn_index]64 old_square = self.board[prev_pos[0]][prev_pos[1]]65 new_square = self.board[row][column]66 if abs(prev_pos[0] - row) + abs(prev_pos[1] - column) == 0 or \67 abs(prev_pos[0] - row) + abs(prev_pos[1] - column) > 2:68 self.conditional_print("You cannot stay in place or move more than two squares from you current position!",69 print_failure)70 return False71 if (new_square.center == 'X' or new_square.center == 'O') and \72 (new_square.starting is None or new_square.starting == player):73 self.conditional_print("You cannot jump to a square with a pawn!", print_failure)74 return False75 # Top76 if row < prev_pos[0]:77 # Top-Left78 if column < prev_pos[1]:79 if old_square.top_left() or new_square.bottom_right() or \80 (old_square.left and new_square.right) or (old_square.top and new_square.bottom):81 self.conditional_print("You cannot jump over a wall!", print_failure)82 return False83 # Top-Right84 elif column > prev_pos[1]:85 if old_square.top_right() or new_square.bottom_left() or \86 (old_square.right and new_square.left) or (old_square.top and new_square.bottom):87 self.conditional_print("You cannot jump over a wall!", print_failure)88 return False89 else:90 # Top-Middle91 if prev_pos[0] - row == 1:92 if new_square.bottom:93 self.conditional_print("You cannot jump over a wall!", print_failure)94 return False95 elif new_square.starting is not None and new_square.starting != player:96 pass97 elif new_square.top:98 self.conditional_print("You cannot jump just one space forward!", print_failure)99 return False100 elif row == 0 or (self.board[row - 1][column].center != 'X' and101 self.board[row - 1][column].center != 'O'):102 self.conditional_print("You cannot jump just one space forward!", print_failure)103 return False104 # Top-Middle-Long105 else:106 if new_square.bottom or old_square.top:107 self.conditional_print("You cannot jump over a wall!", print_failure)108 return False109 # Bottom110 elif row > prev_pos[0]:111 # Bottom-Left112 if column < prev_pos[1]:113 if old_square.bottom_left() or new_square.top_right() or \114 (old_square.bottom and new_square.top) or (old_square.left and new_square.right):115 self.conditional_print("You cannot jump over a wall!", print_failure)116 return False117 # Bottom-Right118 elif column > prev_pos[1]:119 if old_square.bottom_right() or new_square.top_left() or \120 (old_square.bottom and new_square.top) or (old_square.right and new_square.left):121 self.conditional_print("You cannot jump over a wall!", print_failure)122 return False123 else:124 # Bottom-Middle125 if row - prev_pos[0] == 1:126 if new_square.top:127 self.conditional_print("You cannot jump over a wall!", print_failure)128 return False129 elif new_square.starting is not None and new_square.starting != player:130 pass131 elif new_square.bottom:132 self.conditional_print("You cannot jump just one space forward!", print_failure)133 return False134 elif row == self.rows - 1 or (self.board[row + 1][column].center != 'X' and135 self.board[row + 1][column].center != 'O'):136 self.conditional_print("You cannot jump just one space forward!", print_failure)137 return False138 # Bottom-Middle-Long139 else:140 if new_square.top or old_square.bottom:141 self.conditional_print("You cannot jump over a wall!", print_failure)142 return False143 elif column > prev_pos[1]:144 # Middle-Right145 if column - prev_pos[1] == 1:146 if new_square.left:147 self.conditional_print("You cannot jump over a wall!", print_failure)148 return False149 elif new_square.starting is not None and new_square.starting != player:150 pass151 elif new_square.right:152 self.conditional_print("You cannot jump just one space forward!", print_failure)153 return False154 elif column == self.columns - 1 or (self.board[row][column + 1].center != 'X' and155 self.board[row][column + 1].center != 'O'):156 self.conditional_print("You cannot jump just one space forward!", print_failure)157 return False158 # Middle-Right-Long159 else:160 if new_square.left or old_square.right:161 self.conditional_print("You cannot jump over a wall!", print_failure)162 return False163 else:164 # Middle-Left165 if prev_pos[1] - column == 1:166 if new_square.right:167 self.conditional_print("You cannot jump over a wall!", print_failure)168 return False169 elif new_square.starting is not None and new_square.starting != player:170 pass171 elif new_square.left:172 self.conditional_print("You cannot jump just one space forward!", print_failure)173 return False174 elif column == 0 or (self.board[row][column - 1].center != 'X' and175 self.board[row][column - 1].center != 'O'):176 self.conditional_print("You cannot jump just one space forward!", print_failure)177 return False178 # Middle-Left-Long179 else:180 if new_square.right or old_square.left:181 self.conditional_print("You cannot jump over a wall!", print_failure)182 return False183 return True184 def move_pawn(self, player, pawn_index, row, column):185 player_pawns = self.player_1_pawns if player == 'X' else self.player_2_pawns186 old_row, old_column = player_pawns[pawn_index][0], player_pawns[pawn_index][1]187 # Update pawn position188 player_pawns[pawn_index][0], player_pawns[pawn_index][1] = row, column189 # Update board190 self.board[old_row][old_column].center = \191 ' ' if self.board[old_row][old_column].starting is None else '·'192 self.board[row][column].center = player193 # Return the undoing move194 return player, pawn_index, old_row, old_column195 def valid_wall_placement(self, wall_type, row, column, print_failure=True):196 # Check if wall indices are in range197 if row >= self.rows - 1 or column >= self.columns - 1:198 self.conditional_print("Wall indices out of bound!", print_failure)199 return False200 if (wall_type == 'Z' and (self.board[row][column].right or self.board[row + 1][column].right)) or \201 (wall_type == 'P' and (self.board[row][column].bottom or self.board[row][column + 1].bottom)):202 self.conditional_print("A wall already exists on those coordinates!", print_failure)203 return False204 return True205 def place_wall(self, wall_type, row, column, lift=False):206 if wall_type == 'Z':207 self.board[row][column].right = not lift208 self.board[row][column + 1].left = not lift209 self.board[row + 1][column].right = not lift210 self.board[row + 1][column + 1].left = not lift211 else:212 self.board[row][column].bottom = not lift213 self.board[row][column + 1].bottom = not lift214 self.board[row + 1][column].top = not lift215 self.board[row + 1][column + 1].top = not lift216 self.num_placed_walls += not lift217 def check_paths_after_move(self, move, print_failure=True):218 # Make the move219 undo_move = self.move_pawn(*(move[0]))220 self.place_wall(*(move[1]))221 if not self.check_path(self.player_1_pawns[0], self.player_2_start[0]) or \222 not self.check_path(self.player_1_pawns[0], self.player_2_start[1]) or \223 not self.check_path(self.player_1_pawns[1], self.player_2_start[0]) or \224 not self.check_path(self.player_1_pawns[1], self.player_2_start[1]) or \225 not self.check_path(self.player_2_pawns[0], self.player_1_start[0]) or \226 not self.check_path(self.player_2_pawns[0], self.player_1_start[1]) or \227 not self.check_path(self.player_2_pawns[1], self.player_1_start[0]) or \228 not self.check_path(self.player_2_pawns[1], self.player_1_start[1]):229 # Undo the move230 self.place_wall(*(move[1]), lift=True)231 self.move_pawn(*undo_move)232 self.conditional_print("You cannot block one of the pawns' path to the goal!", print_failure)233 return False234 # Undo the move235 self.place_wall(*(move[1]), lift=True)236 self.move_pawn(*undo_move)237 return True238 # A* algorithm to check if there is a pawn path from the source to the destination239 def check_path(self, source, destination):240 # Dictionary for keeping track of visited nodes241 seen_set = {(source[0], source[1])}242 prio_queue = [(self.non_diagonal_distance(source, destination), *source)]243 while len(prio_queue):244 # noinspection PyTupleAssignmentBalance245 _, row, column = heapq.heappop(prio_queue)246 if row == destination[0] and column == destination[1]:247 return True248 for new_pos in filter(lambda jump: jump not in seen_set, self.iter_non_blocking_jumps(row, column)):249 seen_set.add(new_pos)250 heapq.heappush(prio_queue, (self.non_diagonal_distance(new_pos, destination), *new_pos))251 return False252 # Returns all one square jumps from the square with the row and column taking into account only the walls.253 # It's similar to all legal jumps except it's jumps one square away and doesn't account for player position on254 # the squares. Used for path-checking255 def iter_non_blocking_jumps(self, row, column):256 # Top side257 if row > 0:258 # Top259 if not self.board[row][column].top:260 yield row - 1, column261 # Top-Left262 if column > 0 and not (263 self.board[row][column].top_left() or264 self.board[row - 1][column - 1].bottom_right() or265 (self.board[row][column].top and self.board[row][column - 1].top) or266 (self.board[row][column].left and self.board[row - 1][column].left)267 ):268 yield row - 1, column - 1269 # Top-Right270 if column < self.columns - 1 and not (271 self.board[row][column].top_right() or272 self.board[row - 1][column + 1].bottom_left() or273 (self.board[row][column].top and self.board[row][column + 1].top) or274 (self.board[row][column].right and self.board[row - 1][column].right)275 ):276 yield row - 1, column + 1277 # Bottom side278 if row < self.rows - 1:279 # Bottom280 if not self.board[row][column].bottom:281 yield row + 1, column282 # Bottom-Left283 if column > 0 and not (284 self.board[row][column].bottom_left() or285 self.board[row + 1][column - 1].top_right() or286 (self.board[row][column].bottom and self.board[row][column - 1].bottom) or287 (self.board[row][column].left and self.board[row + 1][column].left)288 ):289 yield row + 1, column - 1290 # Bottom-Right291 if column < self.columns - 1 and not (292 self.board[row][column].bottom_right() or293 self.board[row + 1][column + 1].top_left() or294 (self.board[row][column].bottom and self.board[row][column + 1].bottom) or295 (self.board[row][column].right and self.board[row + 1][column].right)296 ):297 yield row + 1, column + 1298 # Left299 if column > 0 and not self.board[row][column].left:300 yield row, column - 1301 # Right302 if column < self.columns - 1 and not self.board[row][column].right:303 yield row, column + 1304 @staticmethod305 def non_diagonal_distance(source, destination):306 return abs(source[0] - destination[0]) + abs(source[1] - destination[1])307 def static_evaluation(self):308 evaluation = 0309 for pawn in self.player_1_pawns:310 pawn_distance_1 = self.non_diagonal_distance(pawn, self.player_2_start[0])311 pawn_distance_2 = self.non_diagonal_distance(pawn, self.player_2_start[1])312 if pawn_distance_1 == 0 or pawn_distance_2 == 0:313 return inf314 evaluation += 1 / pawn_distance_1 + 1 / pawn_distance_2315 for pawn in self.player_2_pawns:316 pawn_distance_1 = self.non_diagonal_distance(pawn, self.player_1_start[0])317 pawn_distance_2 = self.non_diagonal_distance(pawn, self.player_1_start[1])318 if pawn_distance_1 == 0 or pawn_distance_2 == 0:319 return -inf320 evaluation -= 1 / pawn_distance_1 + 1 / pawn_distance_2321 return evaluation322 @staticmethod323 def matrix_index_to_board_index(index):324 return chr(ord('0') + index + 1) if index < 9 else chr(ord('A') - 9 + index)325 @staticmethod326 def board_index_to_matrix_index(char):327 return ord(char) - ord('0') - 1 if ord('0') <= ord(char) <= ord('9') else ord(char) - ord('A') + 9328 # Helper method for printing a message if a condition is true329 @staticmethod330 def conditional_print(message, condition):331 if condition:332 print(message)333class BoardSquare:334 def __init__(self, center=" ", top=False, left=False, right=False, bottom=False):335 self.center = center336 self.top = top337 self.left = left338 self.right = right339 self.bottom = bottom340 # Variable for remembering the starting position of the first or second player341 self.starting = None342 def set_start(self, player):343 self.center = player344 self.starting = player345 def top_left(self):346 return self.top and self.left347 def top_right(self):348 return self.top and self.right349 def bottom_left(self):350 return self.bottom and self.left351 def bottom_right(self):...

Full Screen

Full Screen

zflock.py

Source:zflock.py Github

copy

Full Screen

...31 comment = "%s%s" % (prefix, f.read().rstrip("\n"))32 except IOError:33 comment = ""34 return comment35def print_failure(message):36 stderr("zflock: %s on %s" % (message, platform.node()))37def print_verbose(message):38 verbose_stderr("zflock: %s on %s" % (message, platform.node()))39def lock_and_run(filesystem, command, options):40 """Attempt to lock filesystem and run command, return whether we did."""41 ok = True42 locked = False43 lockpath = lockpath_for(filesystem)44 try:45 os.makedirs(lockpath, 0o0755)46 except os.error:47 pass48 readme = readme_for(lockpath)49 x = os.open(lockpath, os.O_RDONLY)50 if x != -1:51 try:52 fcntl.flock(x, fcntl.LOCK_EX | fcntl.LOCK_NB)53 except IOError:54 print_failure("failed to lock %s%s" % (filesystem, readme_comment(readme, " # ")))55 ok = False56 if ok:57 locked = True58 if options.comment:59 # write a comment if we can60 try:61 with open(readme, "w") as f:62 f.write("%s\n" % options.comment)63 except:64 print_failure("failed to write README for %s" % filesystem)65 ok = False66 if ok:67 print_verbose("locked %s" % filesystem)68 ok = subprocess.call(command) == 069 if not ok:70 print_failure("non-zero exit status from %s" % ' '.join(command))71 os.close(x)72 if locked:73 print_verbose("unlocked %s" % filesystem)74 else:75 print_failure("failed to open %s" % lockpath)76 ok = False77 return ok78def list_locks(options):79 for (dirpath, dirnames, filenames) in os.walk(LOCKDIR):80 for d in dirnames:81 lockpath = os.path.join(dirpath, d)82 filesystem = os.path.relpath(lockpath, LOCKDIR)83 try:84 x = os.open(lockpath, os.O_RDONLY)85 if x != -1:86 fcntl.flock(x, fcntl.LOCK_EX | fcntl.LOCK_NB)87 # successfully locked, so wasn't locked88 fcntl.flock(x, fcntl.LOCK_UN)89 except IOError:90 # failed to acquire lock, so must have been locked91 print("%s%s" % (filesystem, readme_comment(readme_for(lockpath), " # ")))92 return True93def gc_locks(options):94 for (dirpath, dirnames, filenames) in os.walk(LOCKDIR, topdown=False):95 for d in dirnames:96 lockpath = os.path.join(dirpath, d)97 filesystem = os.path.relpath(lockpath, LOCKDIR)98 try:99 x = os.open(lockpath, os.O_RDONLY)100 if x != -1:101 fcntl.flock(x, fcntl.LOCK_EX | fcntl.LOCK_NB)102 # successfully locked, so wasn't locked103 try:104 os.remove(readme_for(lockpath))105 except OSError:106 pass107 try:108 os.rmdir(lockpath)109 print_verbose("removed %s" % lockpath)110 except:111 pass112 fcntl.flock(x, fcntl.LOCK_UN)113 except IOError:114 # failed to acquire lock, so must have been locked115 print_verbose("not removing %s%s" % (filesystem, readme_comment(readme_for(lockpath), " # ")))116 return True117def main():118 usage = "usage: %prog [options] [<filesystem> <command>]"119 parser = optparse.OptionParser(usage)120 parser.add_option("-l", "--list", action="store_true", dest="list", default=False, help="list locks, do nothing else (default: %default)")121 parser.add_option("-g", "--gc", action="store_true", dest="gc", default=False, help="garbage collect, do nothing else (default: %default)")122 parser.add_option("-c", "--comment", action="store", dest="comment", default=None, help="comment explaining reason for lock (default: %default)")123 parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="be verbose (default: %default)")124 (options, args) = parser.parse_args(sys.argv)125 set_verbose(options.verbose)126 ok = False127 try:128 if options.list:129 if len(args) == 1:130 ok = list_locks(options)131 elif options.gc:132 if len(args) == 1:133 ok = gc_locks(options)134 elif len(args) >= 3:135 ok = lock_and_run(args[1], args[2:], options)136 else:137 parser.print_usage()138 ok = True139 except Exception as e:140 # report exception and exit141 print_failure("failed with exception %s" % e)142 exctype, value, tb = sys.exc_info()143 traceback.print_tb(tb)144 sys.exit(1)145 if not ok:...

Full Screen

Full Screen

subprocess_manager.py

Source:subprocess_manager.py Github

copy

Full Screen

...47 if self.is_correct_err_output() and self.file_created() == False:48 d.print_success("OK")49 return 050 else:51 d.print_failure("KO")52 if self.is_correct_err_output() == False:53 print("-> Should return an error")54 print(" your output: ", self.err_output_printed())55 print(" expected output:", self.err_output_expected())56 if self.file_created() == True:57 print("-> Should not create a file", self.file_basename + ".cor")58 return 159 # == TEST WITH FILE ========================================================60 def get_file_test_rslt(self):61 # if no error returned + file created + file ok : OK62 if self.err_output_printed() == None and self.file_created() and self.is_correct_file_output():63 d.print_success("OK")64 return 065 else:66 d.print_failure("KO")67 if self.err_output_printed() != None:68 print("-> Should not return an error")69 if self.file_created() == False:70 print("-> Should create a file", self.file_basename + ".cor")71 elif self.is_correct_file_output() == False:72 print("-> Your output file (input/" + self.file_basename + ".cor) is different from the expected output (output/" + self.file_basename + ".cor)")73 return 174 # == PROCESS A TEST ========================================================75 def get_result(self):76 # If this test should return an error = it's a parsing test77 if self.is_parsing_test():78 return self.get_parsing_test_rslt()79 # If this test should created a .cor file80 else:81 # Check if there is an expected output in 'output/' folder82 if self.output_file_exists():83 return self.get_file_test_rslt()84 else:85 d.print_warning("File " + self.file_basename + ".cor not found in output folder")86 return 187 # == IF EXCEPTION RAISED ===================================================88 # If code < 0 -> signal (python convention)89 # If code = 1 or 255, it means the program returned 1 or -1 (typically when there is an error)90 def get_rslt_when_exception(self):91 if self.code == -signal.SIGSEGV:92 d.print_failure('SEGFAULT')93 return 194 elif self.code == -signal.SIGABRT:95 d.print_failure('SIGABORT')96 return 197 elif self.code < 0 :98 d.print_failure('Signal caught (' + str(self.code) + ')')99 return 1100 elif self.code == 1 or self.code == 255:101 return self.get_result()102 else:103 d.print_failure('Returned a wrong exit code (' + str(self.code) + ')')...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Radish automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful