Best Python code snippet using autotest_python
test.py
Source:test.py
...43 # print("EXPLODERS", [e.toList() for e in exploders])44 # print(snum.toJSON())45 # snum = snail.process("[[[[[4, 3], 4], 4], [7, [[8, 4], 9]]], [1, 1]]")46 # assert snum.toList() == [[[[0, 7], 4], [[7, 8], [6, 0]]], [8, 1]]47 snum = snail.process_lines(48 "[[[[4, 3], 4], 4], [7, [[8, 4], 9]]]\n[1, 1]".split("\n")49 )50 assert snum.toList() == [[[[0, 7], 4], [[7, 8], [6, 0]]], [8, 1]]51 processed = snail.process_lines(ex.ex_02[0].split("\n"))52 assert processed.toList() == [[[[1, 1], [2, 2]], [3, 3]], [4, 4]]53 processed = snail.process_lines(ex.ex_03[0].split("\n"))54 assert processed.toList() == json.loads(ex.ex_03[1])55 processed = snail.process_lines(ex.ex_04[0].split("\n"))56 assert processed.toList() == json.loads(ex.ex_04[1])57 processed = snail.process_lines(ex.ex_05[0].strip().split("\n"))58 assert processed.toList() == json.loads(ex.ex_05[1])59 processed = snail.process_lines(ex.ex_homework.strip().split("\n"))60 assert processed.toList() == json.loads(ex.ex_homework_final)61 assert processed.calculate_magnitude() == ex.ex_homework_mag62 processed = snail.process_lines(input.parse_snail_nums())63 assert processed.calculate_magnitude() == 434764test_part_1()65def test_part_2():66 largest_mag = snail.find_largest_pair(ex.ex_homework.strip().split("\n"))67 print("LARGEST MAG", largest_mag)68 largest_mag = snail.find_largest_pair(input.parse_snail_nums())69 print("LARGEST MAG", largest_mag)...
parse_file_list.py
Source:parse_file_list.py
...6list_file_path = r'./list'7encoding = 'utf-8'8def print_help():9 print('Usage: -c <count>')10def process_lines(handler):11 with codecs.open(list_file_path, 'r', encoding=encoding) as file:12 for line in file.readlines():13 if line.startswith('Strength'):14 line = line[:-2]15 handler(line)16def count_lines():17 with codecs.open(list_file_path, 'r', encoding=encoding) as file:18 count = 019 for line in file.readlines():20 line = line[:-1]21 if line.startswith('Strength'):22 count += 123 print('%d lines in total' % count)24def show_lines(line: str):25 matched = re.search(r'(>+)', line, re.M | re.I)26 if len(matched.group()) == 1:27 print('\n', '-'*10)28 print(line)29def show_desc(line: str):30 left_quota, right_quota = line.find('`'), line.rfind('`')31 ext = line[left_quota + 1:right_quota]32 if ext:33 print('%-50s\t%s' % (ext, line))34def show_ext(line: str):35 left_quota, right_quota = line.rfind('['), line.rfind(']')36 ext = line[left_quota + 1:right_quota]37 if ext:38 print('%s\t%s' % (ext, line))39def show_apple(line: str):40 matched = re.search(r'\[(.*)\], \[(.*)\], \[(.*)\]', line, re.M | re.I)41 apple = matched.group(2)42 if apple:43 print('%s\t%s' % (apple, line))44def show_lineno_desc(line: str):45 matched = re.search(r'@([\d]*): `(.*)`', line, re.M | re.I)46 print('%-10s%s' % (matched.group(1), matched.group(2)))47def main(argv):48 try:49 opts, args = getopt.getopt(argv, 'hfcsedal',50 ['file', 'count', 'show', 'ext', 'desc', 'apple', 'linedesc'])51 except getopt.GetoptError:52 print_help()53 sys.exit(-1)54 for opt, arg in opts:55 if opt == '-h':56 print_help()57 sys.exit(0)58 elif opt in ('-f', '--file'):59 global list_file_path60 list_file_path = opt61 elif opt in ('-c', '--count'):62 count_lines()63 elif opt in ('-s', '--show'):64 process_lines(show_lines)65 elif opt in ('-e', '--ext'):66 process_lines(show_ext)67 elif opt in ('-d', '--desc'):68 process_lines(show_desc)69 elif opt in ('-a', '--apple'):70 process_lines(show_apple)71 elif opt in ('-l', '--linedesc'):72 process_lines(show_lineno_desc)73if __name__ == '__main__':...
sorted.py
Source:sorted.py
1from re import split as resplit2from typing import Any, List3from dmoj.error import InternalError4from dmoj.utils.unicode import utf8bytes5def check(process_output: bytes, judge_output: bytes, split_on: str = 'lines', **kwargs) -> bool:6 split_pattern = {'lines': b'[\r\n]', 'whitespace': br'[\s]'}.get(split_on)7 if not split_pattern:8 raise InternalError('invalid `split_on` mode')9 process_lines: List[Any]10 judge_lines: List[Any]11 process_lines = list(filter(None, resplit(split_pattern, utf8bytes(process_output))))12 judge_lines = list(filter(None, resplit(split_pattern, utf8bytes(judge_output))))13 if len(process_lines) != len(judge_lines):14 return False15 if split_on == 'lines':16 process_lines = list(map(bytes.split, process_lines))17 judge_lines = list(map(bytes.split, judge_lines))18 process_lines.sort()19 judge_lines.sort()20 for process_line, judge_line in zip(process_lines, judge_lines):21 if process_line != judge_line:22 return False...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!