Best Python code snippet using Testify_python
05-monitor_patch.py
Source:05-monitor_patch.py
...142 unmonitor_msgs = [Msg("unmonitor", sig) for sig in signals]143 def insert_after_open(msg):144 if msg.command == "open_run":145 def new_gen():146 yield from ensure_generator(monitor_msgs)147 return single_gen(msg), new_gen()148 else:149 return None, None150 def insert_before_close(msg):151 if msg.command == "close_run":152 def new_gen():153 yield from ensure_generator(unmonitor_msgs)154 yield msg155 return new_gen(), None156 else:157 return None, None158 # Apply nested mutations.159 plan1 = plan_mutator(plan, insert_after_open)160 plan2 = plan_mutator(plan1, insert_before_close)161 return (yield from plan2)162ts_monitor_during_decorator = make_decorator(ts_monitor_during_wrapper)163async def _ts_monitor(msg):164 # rely on closing over RE in the name space, this is dirty, but165 self = RE166 run_key = msg.run167 try:...
10-monitor_patch.py
Source:10-monitor_patch.py
...142 unmonitor_msgs = [Msg("unmonitor", sig) for sig in signals]143 def insert_after_open(msg):144 if msg.command == "open_run":145 def new_gen():146 yield from ensure_generator(monitor_msgs)147 return single_gen(msg), new_gen()148 else:149 return None, None150 def insert_before_close(msg):151 if msg.command == "close_run":152 def new_gen():153 yield from ensure_generator(unmonitor_msgs)154 yield msg155 return new_gen(), None156 else:157 return None, None158 # Apply nested mutations.159 plan1 = plan_mutator(plan, insert_after_open)160 plan2 = plan_mutator(plan1, insert_before_close)161 return (yield from plan2)162ts_monitor_during_decorator = make_decorator(ts_monitor_during_wrapper)163async def _ts_monitor(msg):164 # rely on closing over RE in the name space, this is dirty, but165 self = RE166 run_key = msg.run167 try:...
main.py
Source:main.py
1from __future__ import print_function2from itertools import imap, chain, ifilter3from functools import partial4from operator import methodcaller5import string6from collections import Counter7from pyparsing import (8 Literal,9 ZeroOrMore,10 OneOrMore,11 Forward,12 Group,13 Empty14)15class Operation(object):16 pass17class MemoryOperation(Operation):18 def __init__(self, operations):19 count = Counter(operations)20 self.diff = count['+'] - count['-']21class PointerOperation(Operation):22 def __init__(self, operations):23 pass24class IOOperation(Operation):25 pass26def memory_operation_compile(memory_operations):27 count = Counter(list(memory_operations))28 return "m[p]=(m[p]+({}))%256\n".format(count['+']-count['-'])29def pointer_operation_compile(M):30 def _pointer_operation_compile(pointer_operations):31 count = Counter(list(pointer_operations))32 return "p=(p+({}))%{}\n".format(count['>']-count['<'], M)33 return _pointer_operation_compile34def io_operation_compile(io_operations):35 def translate(token):36 if token == '.':37 return "yield m[p]\n"38 else:39 return "m[p]=i.next()%256\n"40 return "".join(41 map(42 translate,43 io_operations44 )45 )46ifilter_nonblanks = partial(ifilter, None)47def loop_compile(expressions):48 nonempty_rows = ifilter_nonblanks(49 chain.from_iterable(50 imap(51 methodcaller('split', '\n'),52 expressions53 )54 )55 )56 tab = partial(imap, " {}\n".format)57 pass_if_empty = lambda s: s if s else ' pass\n'58 return "while m[p]:\n{}".format(59 pass_if_empty(60 "".join(61 tab(62 nonempty_rows63 )64 )65 )66 )67def start_compile(M):68 def _start_compile(_):69 return "p=0\nm=bytearray({})\n".format(M)70 return _start_compile71def parser(M):72 """Brainfuck->Python73 """74 plus, minus = Literal('+'), Literal('-')75 right, left = Literal('>'), Literal('<')76 write, read = Literal('.'), Literal(',')77 memory_operation = OneOrMore(plus | minus).setParseAction(78 memory_operation_compile79 )80 pointer_operation = OneOrMore(right | left).setParseAction(81 pointer_operation_compile(M=M)82 )83 io_operation = OneOrMore(write | read).setParseAction(84 io_operation_compile85 )86 start_bracket = Literal('[').suppress()87 end_bracket = Literal(']').suppress()88 expression = Forward()89 loop = (start_bracket + expression + end_bracket).setParseAction(90 loop_compile91 )92 start = Empty().setParseAction(start_compile(M=M))93 expression << ZeroOrMore(94 memory_operation | pointer_operation | io_operation | loop95 )96 program = (start + expression).setParseAction(''.join)97 return program98def bf(program, M=1024):99 alphabet = '+-><[].,'100 all_characters = string.maketrans('', '')101 cleaned_program = string.translate(102 program,103 None,104 string.translate(105 all_characters,106 None,107 alphabet108 )109 )110 header_template = "def _f(i):\n{code}"111 compiled_program = parser(M=M).parseString(cleaned_program)[0]112 ensure_generator = [113 "if False:",114 " yield 0"115 ] # HACK the yield will never be reached, this is so that the degenerate program without output still gets interpreted as a generator by the python compiled and by this is always return a generator116 compiled_program_with_header = header_template.format(117 code="".join(118 imap(119 " {}\n".format,120 chain(121 ifilter_nonblanks(122 compiled_program.split('\n')123 ),124 ensure_generator125 )126 )127 )128 )129 print(compiled_program_with_header)130 def _bf(input_stream=[]):131 input_stream = iter(input_stream)132 code = compile(compiled_program_with_header, '<compiled>', 'exec')133 exec code in {}, locals() # MAGIC: _f gets loaded into scope134 # TODO this could be done via types.LambdaType(...,135 # code=types.CodeType(codestring='jsjfjdksf', nlocals=4, ...))136 return _f(input_stream)137 return _bf138brainfuck = bf139def test(program):140 print(program)141 print(parser(1024).parseString(program)[0])142 print('-----------------------------------------')143#map(144# test,145# [146# '[]'147# '++++----',148# '><<>><<>',149# '>>[++---]',150# '[-[++]+]',151# '++[>>[-]..,]',152# '++[-->>+++][+[+]+][+>-]',153# ]154#)155add_text = ',>,[<+>-]<.'156sum_to_first_zero_text = ',[[->+<],]>.' # FIXME (fix the compiler not the code) result is empty if trailing 0 is missing157fibonacci_text = '.>+.[[->+>+<<]<[->>+<<]>>>[-<<+>>]<.]'158mul_text = ',>,[-<[->>+>+<<<]>>[-<<+>>]<]>>.'159hello_text = '++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.'160sort_text = '>>,[>>,]<<[[-<+<]>[>[>>]<[.[-]<[[>>+<<-]<]>>]>]<<]' # NOTE zero terminated sort, example input [3,1,3,2,0]161copy_text = ',[.[-],]'162reverse_text = '>,[>,]<[.<]'163render_brainfuck_text = '+++++[>+++++++++<-],[[>--.++>+<<-]>+.->[<.>-]<<,]' # NOTE outputs brainfuck that prints the input164brainfuck_interpreter_text = '>>>+[[-]>>[-]++>+>+++++++[<++++>>++<-]++>>+>+>+++++[>++>++++++<<-]+>>>,<++[[>[->>]<[>>]<<-]<[<]<+>>[>]>[<+>-[[<+>-]>]<[[[-]<]++<-[<+++++++++>[<->-]>>]>>]]<<]<]<[[<]>[[>]>>[>>]+[<<]<[<]<+>>-]>[>]+[->>]<<<<[[<<]<[<]+<<[+>+<<-[>-->+<<-[>+<[>>+<<-]]]>[<+>-]<]++>>-->[>]>>[>>]]<<[>>+<[[<]<]>[[<<]<[<]+[-<+>>-[<<+>++>-[<->[<<+>>-]]]<[>+<-]>]>[>]>]>[>>]>>]<<[>>+>>+>>]<<[->>>>>>>>]<<[>>>>>>>>]<<[>->>>>>]<<[>,>>>]<<[>+>]<<[+<<]<]' # NOTE [input a brainfuck program and its input, separated by an exclamation point.. http://www.hevanet.com/cristofd/brainfuck/dbfi.b165def main():166 pass167if __name__ == '__main__':...
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!!