How to use closer method in pytest-asyncio

Best Python code snippet using pytest-asyncio_python

boolean.py

Source:boolean.py Github

copy

Full Screen

1#!/usr/bin/env python2#3# Copyright (c) 2019 Opticks Team. All Rights Reserved.4#5# This file is part of Opticks6# (see https://bitbucket.org/simoncblyth/opticks).7#8# Licensed under the Apache License, Version 2.0 (the "License"); 9# you may not use this file except in compliance with the License. 10# You may obtain a copy of the License at11#12# http://www.apache.org/licenses/LICENSE-2.013#14# Unless required by applicable law or agreed to in writing, software 15# distributed under the License is distributed on an "AS IS" BASIS, 16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17# See the License for the specific language governing permissions and 18# limitations under the License.19#20"""21This is going the way of the dodo... due to state table bugs,22moving to the XRT language generated from the C enums23"""24from intersect import DIFFERENCE, UNION, INTERSECTION, desc25# intersect status26Enter = 127Exit = 228Miss = 329desc_state = { Enter : "Enter", Exit : "Exit", Miss : "Miss" }30# acts31NONE = 032RetMiss = 0x1 << 0 33RetL = 0x1 << 1 34RetR = 0x1 << 2 35RetLIfCloser = 0x1 << 3 36RetRIfCloser = 0x1 << 437LoopL = 0x1 << 5 38LoopLIfCloser = 0x1 << 639LoopR = 0x1 << 7 40LoopRIfCloser = 0x1 << 841FlipR = 0x1 << 942RetFlippedRIfCloser = 0x1 << 1043BooleanStart = 0x1 << 1144BooleanError = 0x1 << 1245IterativeError = 0x1 << 1346_act_index = {47 RetMiss:0,48 RetL:1,49 RetR:2,50 RetLIfCloser:3,51 RetRIfCloser:4,52 LoopL:5,53 LoopLIfCloser:6,54 LoopR:7,55 LoopRIfCloser:8,56 FlipR:9,57 RetFlippedRIfCloser:10,58 BooleanStart:11,59 BooleanError:12,60 IterativeError:13,61}62def act_index(act):63 return _act_index[act]64 65def desc_acts(acts):66 s = ""67 if acts & RetMiss: s+= "RetMiss "68 if acts & RetL: s+= "RetL "69 if acts & RetR: s+= "RetR "70 if acts & RetLIfCloser: s+= "RetLIfCloser "71 if acts & RetRIfCloser: s+= "RetRIfCloser "72 if acts & RetFlippedRIfCloser: s+= "RetFlippedRIfCloser "73 if acts & LoopL: s+= "LoopL "74 if acts & LoopLIfCloser:s+= "LoopLIfCloser "75 if acts & LoopR: s+= "LoopR "76 if acts & LoopRIfCloser:s+= "LoopRIfCloser "77 if acts & FlipR: s+= "FlipR "78 if acts & BooleanStart: s+= "BooleanStart"79 if acts & BooleanError: s+= "BooleanError"80 if acts & IterativeError: s+= "IterativeError"81 #if acts & ResumeFromLoopL: s+= "ResumeFromLoopL "82 #if acts & ResumeFromLoopR: s+= "ResumeFromLoopR "83 #if acts & NewTranche: s+= "NewTranche "84 return s 85#86# note that although two loopers do appear together "LoopLIfCloser | LoopRIfCloser" 87# they are always conditionals on which is closer so only one of them will be enacted 88#89# note that FlipR only occurs for DIFFERENCE90#91# 92#93table_ = {94 DIFFERENCE : { 95 Enter : {96 Enter : RetLIfCloser | LoopR,97 Exit : LoopLIfCloser | LoopRIfCloser,98 Miss : RetL99 },100 Exit: {101 Enter : RetLIfCloser | RetFlippedRIfCloser,102 Exit : RetFlippedRIfCloser | LoopL,103 Miss : RetL104 },105 Miss: {106 Enter : RetMiss,107 Exit : RetMiss,108 Miss : RetMiss109 }110 }, 111 UNION : {112 Enter : {113 Enter : RetLIfCloser | RetRIfCloser, 114 Exit : RetRIfCloser | LoopL,115 Miss : RetL116 },117 Exit : {118 Enter : RetLIfCloser | LoopR, 119 Exit : LoopLIfCloser | LoopRIfCloser,120 Miss : RetL121 },122 Miss: {123 Enter : RetR,124 Exit : RetR,125 Miss : RetMiss126 }127 },128 129 INTERSECTION : {130 Enter : {131 Enter : LoopLIfCloser | LoopRIfCloser,132 Exit : RetLIfCloser | LoopR ,133 Miss : RetMiss134 },135 Exit : {136 Enter : RetRIfCloser | LoopL,137 Exit : RetLIfCloser | RetRIfCloser,138 Miss : RetMiss 139 },140 Miss : {141 Enter : RetMiss, 142 Exit : RetMiss, 143 Miss : RetMiss144 }145 }146}147def boolean_table(operation, l, r):148 assert operation in [UNION, INTERSECTION, DIFFERENCE], operation149 assert l in [Enter,Exit,Miss], l150 assert r in [Enter,Exit,Miss], r151 return table_[operation][l][r]152if __name__ == '__main__':153 for op in [UNION,INTERSECTION,DIFFERENCE]:154 print desc[op]155 for l in [Enter, Exit, Miss]:156 for r in [Enter, Exit, Miss]:157 acts = boolean_table(op, l, r )158 print " %7s %7s -> %35s " % ( desc_state[l], desc_state[r], desc_acts(acts) )...

Full Screen

Full Screen

test_CloserVariablesFinder.py

Source:test_CloserVariablesFinder.py Github

copy

Full Screen

1import unittest2from Generator import CloserVariablesFinder3class TestCloserVariablesFinder(unittest.TestCase):4 """5 Tests the CloserVariablesFinder.py script in the Generator.CloserVariablesFinder6 """7 def test_01(self):8 """9 Test the closer lines. Therefore check line 1 and add 1 as area.10 """11 print("+++ Test 1 +++")12 code_lines_without_annotations = ['mid(x, y, z)', 'm = z', 'y < z', 'x < y', 'm = y', 'x < z', 'm = y # m = x',13 'else', 'x > y', 'm = y', 'x > z', 'm = x', 'return m']14 closer_variables = CloserVariablesFinder.get_closer_variables(1, code_lines_without_annotations, 1)15 closer_variables_str = str(closer_variables)16 print(closer_variables_str)17 closer_variables_str_solution = "['m', 'x', 'y', 'z']"18 self.assertEqual(closer_variables_str_solution, closer_variables_str)19 def test_02(self):20 """21 Test the closer lines. Therefore check line 1 and add 2 as area (def).22 """23 print("+++ Test 2 +++")24 code_lines_without_annotations = ['mid(x, y, z)', 'm = z', 'y < z', 'x < y', 'm = y', 'x < z', 'm = y # m = x',25 'else', 'x > y', 'm = y', 'x > z', 'm = x', 'return m']26 closer_variables = CloserVariablesFinder.get_closer_variables(1, code_lines_without_annotations, 2)27 closer_variables_str = str(closer_variables)28 print(closer_variables_str)29 closer_variables_str_solution = "['m', 'x', 'y', 'z']"30 self.assertEqual(closer_variables_str_solution, closer_variables_str)31 def test_03(self):32 """33 Test the closer lines. Therefore check a line where an expression transformation is located.34 """35 print("+++ Test 3 +++")36 code_lines_without_annotations = ['mid(x, y, z)',37 "m = EXPTransformation.call(2, 7, False, [['m', m], ['z', z])",38 'y < z', 'x < y', 'm = y', 'x < z', 'm = y # m = x',39 'else', 'x > y', 'm = y', 'x > z', 'm = x', 'return m']40 closer_variables = CloserVariablesFinder.get_closer_variables(2, code_lines_without_annotations, 0)41 closer_variables_str = str(closer_variables)42 print(closer_variables_str)43 closer_variables_str_solution = "[]"44 self.assertEqual(closer_variables_str_solution, closer_variables_str)45 def test_04(self):46 """47 Test the closer lines. Therefore check line 5 and add 0 as area.48 """49 print("+++ Test 4 +++")50 code_lines_without_annotations = ['mid(x, y, z)', 'm = z', 'y < z', 'x < y', 'm = y', 'x < z', 'm = y # m = x',51 'else', 'x > y', 'm = y', 'x > z', 'm = x', 'return m']52 closer_variables = CloserVariablesFinder.get_closer_variables(5, code_lines_without_annotations, 0)53 closer_variables_str = str(closer_variables)54 print(closer_variables_str)55 closer_variables_str_solution = "['m', 'y']"56 self.assertEqual(closer_variables_str_solution, closer_variables_str)57 def test_05(self):58 """59 Test the closer lines. Therefore check line 13 and add 0 as area (return).60 """61 print("+++ Test 5 +++")62 code_lines_without_annotations = ['mid(x, y, z)', 'm = z', 'y < z', 'x < y', 'm = y', 'x < z', 'm = y # m = x',63 'else', 'x > y', 'm = y', 'x > z', 'm = x', 'return m']64 closer_variables = CloserVariablesFinder.get_closer_variables(13, code_lines_without_annotations, 0)65 closer_variables_str = str(closer_variables)66 print(closer_variables_str)67 closer_variables_str_solution = "['m']"68 self.assertEqual(closer_variables_str_solution, closer_variables_str)69if __name__ == '__main__':...

Full Screen

Full Screen

balance_pairs.py

Source:balance_pairs.py Github

copy

Full Screen

1# For each opening emphasis-like marker find a matching closing one2#3from .state_inline import StateInline4def processDelimiters(state: StateInline, delimiters, *args):5 openersBottom = {}6 maximum = len(delimiters)7 closerIdx = 08 while closerIdx < maximum:9 closer = delimiters[closerIdx]10 # Length is only used for emphasis-specific "rule of 3",11 # if it's not defined (in strikethrough or 3rd party plugins),12 # we can default it to 0 to disable those checks.13 #14 closer.length = closer.length or 015 if not closer.close:16 closerIdx += 117 continue18 # Previously calculated lower bounds (previous fails)19 # for each marker and each delimiter length modulo 3.20 if closer.marker not in openersBottom:21 openersBottom[closer.marker] = [-1, -1, -1]22 minOpenerIdx = openersBottom[closer.marker][closer.length % 3]23 openerIdx = closerIdx - closer.jump - 124 # avoid crash if `closer.jump` is pointing outside of the array,25 # e.g. for strikethrough26 if openerIdx < -1:27 openerIdx = -128 newMinOpenerIdx = openerIdx29 while openerIdx > minOpenerIdx:30 opener = delimiters[openerIdx]31 if opener.marker != closer.marker:32 openerIdx -= opener.jump + 133 continue34 if opener.open and opener.end < 0:35 isOddMatch = False36 # from spec:37 #38 # If one of the delimiters can both open and close emphasis, then the39 # sum of the lengths of the delimiter runs containing the opening and40 # closing delimiters must not be a multiple of 3 unless both lengths41 # are multiples of 3.42 #43 if opener.close or closer.open:44 if (opener.length + closer.length) % 3 == 0:45 if opener.length % 3 != 0 or closer.length % 3 != 0:46 isOddMatch = True47 if not isOddMatch:48 # If previous delimiter cannot be an opener, we can safely skip49 # the entire sequence in future checks. This is required to make50 # sure algorithm has linear complexity (see *_*_*_*_*_... case).51 #52 if openerIdx > 0 and not delimiters[openerIdx - 1].open:53 lastJump = delimiters[openerIdx - 1].jump + 154 else:55 lastJump = 056 closer.jump = closerIdx - openerIdx + lastJump57 closer.open = False58 opener.end = closerIdx59 opener.jump = lastJump60 opener.close = False61 newMinOpenerIdx = -162 break63 openerIdx -= opener.jump + 164 if newMinOpenerIdx != -1:65 # If match for this delimiter run failed, we want to set lower bound for66 # future lookups. This is required to make sure algorithm has linear67 # complexity.68 #69 # See details here:70 # https:#github.com/commonmark/cmark/issues/178#issuecomment-27041744271 #72 openersBottom[closer.marker][(closer.length or 0) % 3] = newMinOpenerIdx73 closerIdx += 174def link_pairs(state: StateInline) -> None:75 tokens_meta = state.tokens_meta76 maximum = len(state.tokens_meta)77 processDelimiters(state, state.delimiters)78 curr = 079 while curr < maximum:80 curr_meta = tokens_meta[curr]81 if curr_meta and "delimiters" in curr_meta:82 processDelimiters(state, curr_meta["delimiters"])...

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 pytest-asyncio 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