How to use ensure_generator method in Testify

Best Python code snippet using Testify_python

05-monitor_patch.py

Source: 05-monitor_patch.py Github

copy

Full Screen

...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:...

Full Screen

Full Screen

10-monitor_patch.py

Source: 10-monitor_patch.py Github

copy

Full Screen

...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:...

Full Screen

Full Screen

main.py

Source: main.py Github

copy

Full Screen

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__':...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Assessing Risks in the Scrum Framework

Software Risk Management (SRM) combines a set of tools, processes, and methods for managing risks in the software development lifecycle. In SRM, we want to make informed decisions about what can go wrong at various levels within a company (e.g., business, project, and software related).

How To Use Playwright For Web Scraping with Python

In today’s data-driven world, the ability to access and analyze large amounts of data can give researchers, businesses & organizations a competitive edge. One of the most important & free sources of this data is the Internet, which can be accessed and mined through web scraping.

Agile in Distributed Development &#8211; A Formula for Success

Agile has unquestionable benefits. The mainstream method has assisted numerous businesses in increasing organizational flexibility as a result, developing better, more intuitive software. Distributed development is also an important strategy for software companies. It gives access to global talent, the use of offshore outsourcing to reduce operating costs, and round-the-clock development.

How To Handle Multiple Windows In Selenium Python

Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.

Joomla Testing Guide: How To Test Joomla Websites

Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.

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 Testify 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