How to use is_int method in pandera

Best Python code snippet using pandera_python

two_arguments.py

Source:two_arguments.py Github

copy

Full Screen

1from check_type import *2import math3import itertools4def get_list_or_string_item_or_concatenate_yield(a, b, arg):5 if is_int(a) and is_int(b):6 yield int(str(a)+str(b))7 elif is_int(a) and is_list(b):8 yield b[a % len(b)]9 elif is_list(a) and is_int(b):10 yield a[b % len(a)]11 elif is_int(a) and is_str(b):12 yield b[a % len(b)]13 elif is_str(a) and is_int(b):14 yield a[b % len(a)]15 elif is_list(a) and is_list(b):16 yield [a[n % len(a)] for n in b]17 else:18 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))19def is_equal(a, b, arg):20 if is_num(a) and is_num(b):21 yield int(a == b)22 elif type(a) == type(b) and type(a) != str:23 yield int(a == b)24 elif is_list(a):25 yield a.index(b) if b in a else -126 elif is_list(b):27 yield b.index(a) if a in b else -128 elif is_str(a) and is_str(b):29 if (len(a) == 1 or len(b) == 1) and len(a) != len(b):30 if len(a) < len(b):31 yield b.find(a)32 else:33 yield a.find(b)34 else:35 yield int(a == b)36 else:37 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))38def is_less(a, b, arg):39 if is_num(a) and is_num(b):40 yield int(a < b)41 elif is_int(a) and is_list(b):42 yield [b[i%len(b)] for i in range(a)]43 elif is_list(a) and is_int(b):44 yield [a[i%len(a)] for i in range(b)]45 elif is_int(a) and is_str(b):46 yield ''.join([b[i%len(b)] for i in range(a)])47 elif is_str(a) and is_int(b):48 yield ''.join([a[i%len(a)] for i in range(b)])49 else:50 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))51def is_greater(a, b, arg):52 if is_num(a) and is_num(b):53 yield int(a > b)54 elif is_int(a) and is_list(b):55 yield [b[i] for i in range((a+1)%len(b), len(b))]56 elif is_list(a) and is_int(b):57 yield [a[i] for i in range((b+1)%len(a), len(a))]58 elif is_int(a) and is_str(b):59 yield ''.join([b[i] for i in range((a+1)%len(b), len(b))])60 elif is_str(a) and is_int(b):61 yield ''.join([a[i] for i in range((b+1)%len(a), len(a))])62 else:63 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))64def is_leq(a, b, arg):65 if is_num(a) and is_num(b):66 yield int(a <= b)67 elif is_int(a) and is_list(b):68 yield [b[i%len(b)] for i in range(a+1)]69 elif is_list(a) and is_int(b):70 yield [a[i%len(a)] for i in range(b+1)]71 elif is_int(a) and is_str(b):72 yield ''.join([b[i%len(b)] for i in range(a+1)])73 elif is_str(a) and is_int(b):74 yield ''.join([a[i%len(a)] for i in range(b+1)])75 else:76 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))77def is_geq(a, b, arg):78 if is_num(a) and is_num(b):79 yield int(a >= b)80 elif is_int(a) and is_list(b):81 yield [b[i] for i in range(a%len(b), len(b))]82 elif is_list(a) and is_int(b):83 yield [a[i] for i in range(b%len(a), len(a))]84 elif is_int(a) and is_str(b):85 yield ''.join([b[i] for i in range(a%len(b), len(b))])86 elif is_str(a) and is_int(b):87 yield ''.join([a[i] for i in range(b%len(a), len(a))])88 else:89 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))90def is_not(a, b, arg):91 if type(a) == type(b):92 yield int(a != b)93 else:94 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))95def zip_yield(a, b, arg):96 if is_list(a) and is_list(b):97 max_len = max(len(a), len(b))98 yield [([a[i]] if i<len(a) else []) + ([b[i]] if i<len(b) else []) \99 for i in range(max_len)]100 elif is_str(a) and is_str(b):101 max_len = max(len(a), len(b))102 yield "".join([(a[i] if i<len(a) else "") + (b[i] if i<len(b) else "") \103 for i in range(max_len)])104 else:105 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))106def add_yield(a, b, arg):107 if is_num(a) and is_num(b):108 yield a+b109 elif is_num(a) and is_list(b):110 yield [n+a for n in b]111 elif is_list(a) and is_num(b):112 yield [n+b for n in a]113 elif is_list(a) and is_list(b):114 yield a+b115 elif is_str(a) and is_num(b):116 yield a+str(b)117 elif is_num(a) and is_str(b):118 yield str(a)+b119 elif is_list(a):120 yield [c for n in a for c in add_yield(n, b, arg)]121 elif is_list(b):122 yield [c for n in b for c in add_yield(a, n, arg)]123 elif is_str(a) and is_str(b):124 yield a+b125 else:126 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))127def subtract_yield(a, b, arg):128 if is_num(a) and is_num(b):129 yield a-b130 elif is_num(a) and is_list(b):131 yield [a-n for n in b]132 elif is_list(a) and is_num(b):133 yield [n-b for n in a]134 elif is_list(a) and is_list(b):135 yield [n for n in a if n not in set(b)]136 elif is_list(a) and is_str(b):137 yield [n for n in a if n not in set(b)]138 elif is_str(a) and is_list(b):139 yield ''.join([n for n in a if n not in set(b)])140 elif is_str(a) and is_str(b):141 yield ''.join([n for n in a if n not in set(b)])142 else:143 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))144def reverse_subtract_yield(a, b, arg):145 for res in subtract_yield(b, a, arg):146 yield res147def mult_yield(a, b, arg):148 if is_num(a) and is_num(b):149 yield a*b150 elif is_str(a) and is_num(b):151 yield a*int(b)152 elif is_num(a) and is_str(b):153 yield int(a)*b154 elif is_num(a) and is_list(b):155 yield a*b156 elif is_list(a) and is_num(b):157 yield [n2 for n in a for n2 in mult_yield(n, b, arg)]158 elif is_list(a) and is_str(b):159 yield [n2 for n in a for n2 in mult_yield(n, b, arg)]160 elif is_list(a) and is_list(b):161 yield [list(n) for n in itertools.product(a, b)]162 elif is_str(a) and is_list(b):163 if all(isinstance(item, str) for item in b):164 yield ''.join([''.join(n) for n in itertools.product(a, b)])165 else:166 yield [list(n) for n in itertools.product(a, b)]167 elif is_str(a) and is_str(b):168 yield ''.join([''.join(n) for n in itertools.product(a, b)])169 else:170 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))171def reverse_multiply_yield(a, b, arg):172 for res in mult_yield(b, a, arg):173 yield res174def divide_yield(a, b, arg):175 if is_int(a) and is_int(b):176 yield a//b177 elif is_num(a) and is_num(b):178 yield a/b179 elif is_num(a) and is_list(b):180 yield [a//n if is_int(a) and is_int(n) else a/n for n in b]181 elif is_list(a) and is_num(b):182 yield [n//b if is_int(b) and is_int(n) else n/b for n in a]183 elif is_list(a) and is_list(b):184 yield [n for n in a if n in set(b)]185 elif is_str(a) and is_int(b):186 yield [a[i*b:(i+1)*b] for i in range(math.ceil(len(a)/b))]187 elif is_str(a) and is_str(b):188 yield a.split(b)189 elif is_list(a) and is_str(b):190 yield [n for n in a if n != b]191 elif is_str(a) and is_list(b):192 if all(isinstance(item, str) for item in b):193 for n in b:194 a = a.replace(n, "")195 yield a196 elif all(isinstance(item, int) for item in b):197 yield [a[b[i]:b[i+1]] for i in range(len(b)-1)]198 else:199 raise ValueError("[%s][%s]%s is only supported for single type string or int arrays" % (type(a), type(b), arg.char))200 else:201 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))202def reverse_divide_yield(a, b, arg):203 for res in divide_yield(b, a, arg):204 yield res205def power_yield(a, b, arg):206 if is_num(a) and is_num(b):207 yield a**b208 elif is_num(a) and is_list(b):209 yield [a**n for n in b]210 elif is_list(a) and is_num(b):211 yield [n**b for n in a]212 else:213 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))214def reverse_power_yield(a, b, arg):215 for res in power_yield(b, a, arg):216 yield res217def modulo_yield(a, b, arg):218 if is_num(a) and is_num(b):219 yield a%b220 elif is_int(a) and is_list(b):221 yield [n for n in b[::a]]222 elif is_list(a) and is_num(b):223 yield [n%b for n in a]224 elif is_num(a) and is_str(b):225 yield ''.join([n for n in b[::n]])226 else:227 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))228def join_yield(a, b, arg):229 if is_list(a) and is_str(b):230 yield b.join([str(n) for n in a])231 elif is_str(a) and is_list(b):232 yield a.join([str(n) for n in b])233 elif(is_str(a) and is_str(b)):234 yield b.join(list(a))235 elif is_list(a) and is_list(b):236 yield [n.join(a) for n in b]237 else:238 raise ValueError("[%s]%s is not supported" % (type(a),arg.char))239def prepend_list_or_string_yield(a, b, arg):240 if is_num(a) and is_list(b):241 yield [a] + b242 elif is_list(a) and is_num(b):243 yield [b] + a244 elif is_str(a) and is_list(b):245 yield [a] + b246 elif is_list(a) and is_str(b):247 yield [b] + a248 elif is_str(a) and is_num(b):249 yield str(b) + a250 elif is_num(a) and is_str(b):251 yield str(a) + b252 elif is_str(a) and is_str(b):253 yield b + a254 elif is_int(a) and is_int(b):255 yield int(str(b)+str(a))256 elif is_list(a) and is_list(b):257 yield b + a258 else:259 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))260def append_list_or_string_yield(a, b, arg):261 if is_num(a) and is_list(b):262 yield b + [a]263 elif is_list(a) and is_num(b):264 yield a + [b]265 elif is_str(a) and is_list(b):266 yield b + [a]267 elif is_list(a) and is_str(b):268 yield a + [b]269 elif is_str(a) and is_num(b):270 yield a + str(b)271 elif is_num(a) and is_str(b):272 yield b + str(a)273 elif is_str(a) and is_str(b):274 yield a + b275 elif is_int(a) and is_int(b):276 yield int(str(a)+str(b))277 elif is_list(a) and is_list(b):278 yield a + b279 else:280 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))281def increase_array_element_yield(a, b, arg):282 if is_int(a) and is_list(b):283 b[a % len(b)] += 1284 yield b285 elif is_list(a) and is_int(b):286 a[b % len(a)] += 1287 yield a288 else:289 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))290def decrease_array_element_yield(a, b, arg):291 if is_int(a) and is_list(b):292 b[a % len(b)] -= 1293 yield b294 elif is_list(a) and is_int(b):295 a[b % len(a)] -= 1296 yield a297 else:298 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))299def is_divisible_yield(a, b, arg):300 if is_int(a) and is_int(b):301 yield int(a%b == 0)302 elif is_int(a) and is_list(b):303 yield [int(a%n == 0) for n in b]304 elif is_list(a) and is_int(b):305 yield [int(n%b == 0) for n in a]306 else:307 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))308def add(a, b):309 return a+b310def mult(a, b, arg):311 return a*b312def center_string_or_int_yield(a, b, arg):313 if is_int(a) and is_int(b):314 yield str(a).center(b)315 elif is_int(a) and is_str(b):316 yield b.center(a)317 elif is_str(a) and is_int(b):318 yield a.center(b)319 elif is_int(a) and is_list(b):320 yield [str(n).center(a) for n in b]321 elif is_list(a) and is_int(b):322 yield [str(n).center(b) for n in a]323 else:324 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))325def pad_to_equal_length(a, b, arg):326 if is_list(a) and (is_int(b) or is_str(b)):327 max_len = 0328 for n in a:329 max_len = max(max_len, len(str(n)))330 res = []331 for n in a:332 pad = max_len - len(str(n))333 res.append(pad*str(b)+str(n))334 yield res335 elif is_list(b) and (is_int(a) or is_str(a)):336 max_len = 0337 for n in b:338 max_len = max(max_len, len(str(n)))339 res = []340 for n in b:341 pad = max_len - len(str(n))342 res.append(pad*str(a)+str(n))343 yield res344 else:345 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))346def contains_yield(a, b, arg):347 if is_list(a):348 yield 1 if b in a else 0349 elif is_list(b):350 yield 1 if a in b else 0351 elif is_str(a) and is_str(b):352 if len(a) < len(b):353 yield 1 if a in b else 0354 else:355 yield 1 if b in a else 0356 elif is_str(a):357 yield 1 if str(b) in a else 0358 elif is_str(b):359 yield 1 if str(a) in b else 0360 elif is_int(a) and is_int(b):361 yield 1 if str(b) in str(a) else 0362 else:363 raise ValueError("[%s][%s]%s is not supported" % (type(a), type(b), arg.char))364def inclusive_range_yield(a, b, arg):365 if is_int(a) and is_int(b):366 if b < a:367 yield list(range(b, a+1))368 else:369 yield list(range(b, a-1, -1))370 else:...

Full Screen

Full Screen

expr.py

Source:expr.py Github

copy

Full Screen

...41class Expression(object):42 """43 Base class for all expressions.44 """45 def is_int(self, val = None):46 return False47class Terminal(Expression):48 """49 A terminal object.50 """51 def __init__(self, val, pretty = None):52 """53 Construct a Terminal.54 The val variable is usually a string or an integer. Integers may also55 be passed as strings. The pretty-printer will use the string when56 formatting the expression.57 """58 self.val = val59 self.pretty = pretty60 def __str__(self):61 """62 Return the string expression of this object.63 """64 if self.pretty is None:65 return str(self.val)66 return self.pretty67 def simplify(self):68 """69 Return a simplified version of this sub-expression.70 """71 return self72 def is_int(self, val = None):73 """74 Return True if the value of this Terminal is an integer.75 """76 if type(self.val) is int:77 return val is None or self.val == val78 return False79class FunctionCall(Expression):80 """81 Represent a function call82 """83 def __init__(self, name, args):84 """85 Construct a function call object.86 """87 self.name = _classify(name)88 self.args = [_classify(arg) for arg in args]89 def __str__(self):90 """91 Return the string expression of this object.92 """93 return str(self.name) + '(' + ', '.join([str(arg) for arg in self.args]) + ')'94 def simplify(self):95 """96 Return a simplified version of this sub-expression.97 """98 args = [arg.simplify() for arg in self.args]99 return FunctionCall(self.name, args)100class Parenthesis(Expression):101 """102 Represent a pair of round brackets.103 """104 def __init__(self, val):105 """106 Construct a parenthesis object.107 """108 self.val = _classify(val)109 def simplify(self):110 """111 Return a simplified version of this sub-expression.112 """113 val = self.val.simplify()114 if type(val) is Terminal:115 return val116 return Parenthesis(val)117 def __str__(self):118 """119 Return the string expression of this object.120 """121 return '(' + str(self.val) + ')'122class Add(Expression):123 """124 Represent an addition of operands.125 """126 def __init__(self, lhs, rhs):127 """128 Construct an addition object.129 """130 self.lhs = _classify(lhs)131 self.rhs = _classify(rhs)132 def simplify(self):133 """134 Return a simplified version of this sub-expression.135 """136 lhs = self.lhs.simplify()137 rhs = self.rhs.simplify()138 if lhs.is_int() and rhs.is_int():139 return Terminal(lhs.val + rhs.val)140 if lhs.is_int(0):141 return rhs142 if rhs.is_int(0):143 return lhs144 return Add(lhs, rhs)145 def __str__(self):146 """147 Return the string expression of this object.148 """149 return str(self.lhs) + ' + ' + str(self.rhs)150class Sub(Expression):151 """152 Represent a subtraction of operands.153 """154 def __init__(self, lhs, rhs):155 """156 Construct subtraction object.157 """158 self.lhs = _classify(lhs)159 self.rhs = _classify(rhs)160 def simplify(self):161 """162 Return a simplified version of this sub-expression.163 """164 lhs = self.lhs.simplify()165 rhs = self.rhs.simplify()166 if lhs.is_int() and rhs.is_int():167 return Terminal(lhs.val - rhs.val)168 if lhs.is_int(0):169 return rhs170 if rhs.is_int(0):171 return lhs172 return Sub(lhs, rhs)173 def __str__(self):174 """175 Return the string expression of this object.176 """177 return str(self.lhs) + ' - ' + str(self.rhs)178class Mul(Expression):179 """180 Represent the multiplication of operands.181 """182 def __init__(self, lhs, rhs):183 """184 Construct a multiplication object.185 """186 self.lhs = _classify(lhs)187 self.rhs = _classify(rhs)188 def simplify(self):189 """190 Return a simplified version of this sub-expression.191 """192 lhs = self.lhs.simplify()193 rhs = self.rhs.simplify()194 if lhs.is_int() and rhs.is_int():195 return Terminal(lhs.val * rhs.val)196 if lhs.is_int(0) or rhs.is_int(0):197 return Terminal(0)198 if lhs.is_int(1):199 return rhs200 if rhs.is_int(1):201 return lhs202 return Mul(lhs, rhs)203 def __str__(self):204 """205 Return the string expression of this object.206 """207 return str(self.lhs) + ' * ' + str(self.rhs)208class Shl(Expression):209 """210 Shift left operation.211 """212 def __init__(self, lhs, rhs):213 """214 Construct a shift left object.215 """216 self.lhs = _classify(lhs)217 self.rhs = _classify(rhs)218 def simplify(self):219 """220 Return a simplified version of this sub-expression.221 """222 lhs = self.lhs.simplify()223 rhs = self.rhs.simplify()224 if lhs.is_int() and rhs.is_int():225 return Terminal(lhs.val << rhs.val)226 if lhs.is_int(0):227 return Terminal(0)228 if rhs.is_int(0):229 return lhs230 return Shl(lhs, rhs)231 def __str__(self):232 """233 Return the string expression of this object.234 """235 return str(self.lhs) + ' << ' + str(self.rhs)236class Shr(Expression):237 """238 Shift right operation.239 """240 def __init__(self, lhs, rhs):241 """242 Construct a shift right object.243 """244 self.lhs = _classify(lhs)245 self.rhs = _classify(rhs)246 def simplify(self):247 """248 Return a simplified version of this sub-expression.249 """250 lhs = self.lhs.simplify()251 rhs = self.rhs.simplify()252 if lhs.is_int() and rhs.is_int():253 return Terminal(lhs.val >> rhs.val)254 if lhs.is_int(0):255 return Terminal(0)256 if rhs.is_int(0):257 return lhs258 return Shr(lhs, rhs)259 def __str__(self):260 """261 Return the string expression of this object.262 """263 return str(self.lhs) + ' >> ' + str(self.rhs)264class Or(Expression):265 """266 Logical or operation.267 """268 def __init__(self, lhs, rhs):269 """270 Construct a logical and object.271 """272 self.lhs = _classify(lhs)273 self.rhs = _classify(rhs)274 def simplify(self):275 """276 Return a simplified version of this sub-expression.277 """278 lhs = self.lhs.simplify()279 rhs = self.rhs.simplify()280 if lhs.is_int() and rhs.is_int():281 return Terminal(lhs.val | rhs.val)282 if lhs.is_int(0):283 return rhs284 if rhs.is_int(0):285 return lhs286 return Or(lhs, rhs)287 def __str__(self):288 """289 Return the string expression of this object.290 """291 return str(self.lhs) + ' | ' + str(self.rhs)292class And(Expression):293 """294 Logical and operation.295 """296 def __init__(self, lhs, rhs):297 """298 Construct a logical and object.299 """300 self.lhs = _classify(lhs)301 self.rhs = _classify(rhs)302 def simplify(self):303 """304 Return a simplified version of this sub-expression.305 """306 lhs = self.lhs.simplify()307 rhs = self.rhs.simplify()308 if lhs.is_int() and rhs.is_int():309 return Terminal(lhs.val & rhs.val)310 if lhs.is_int(0) or rhs.is_int(0):311 return Terminal(0)312 return And(lhs, rhs)313 def __str__(self):314 """315 Return the string expression of this object.316 """317 return str(self.lhs) + ' & ' + str(self.rhs)318class Xor(Expression):319 """320 Logical xor operation.321 """322 def __init__(self, lhs, rhs):323 """324 Construct a logical xor object.325 """326 self.lhs = _classify(lhs)327 self.rhs = _classify(rhs)328 def simplify(self):329 """330 Return a simplified version of this sub-expression.331 """332 lhs = self.lhs.simplify()333 rhs = self.rhs.simplify()334 if lhs.is_int() and rhs.is_int():335 return Terminal(lhs.val ^ rhs.val)336 if lhs.is_int(0):337 return rhs338 if rhs.is_int(0):339 return lhs340 return Xor(lhs, rhs)341 def __str__(self):342 """343 Return the string expression of this object.344 """...

Full Screen

Full Screen

test_variable.py

Source:test_variable.py Github

copy

Full Screen

...15 """16 def get_variable(self,cls):17 v = cls(host=mysql_host,port=mysql_port,user=mysql_user,password=mysql_password)18 return v.value19 def is_int(self,cls,msg=''):20 v = self.get_variable(cls)21 print("{cls.variable_name:32} = {v}".format(cls=cls,v=v))22 self.assertEqual(type(v),int,msg)23 def is_str(self,cls,msg=''):24 v = self.get_variable(cls)25 print("{cls.variable_name:<32} = {v}".format(cls=cls,v=v))26 self.assertEqual(type(v),str,msg)27 def test_ServerID(self):28 self.is_int(variable.ServerID)29 def test_BaseDir(self):30 self.is_str(variable.BaseDir)31 def test_DataDir(self):32 self.is_str(variable.DataDir)33 def test_Port(self):34 self.is_int(variable.Port)35 def test_CharacterSetServer(self):36 self.is_str(variable.CharacterSetServer)37 def test_Socket(self):38 self.is_str(variable.Socket)39 def test_ReadOnly(self):40 self.is_int(variable.ReadOnly)41 def test_SkipNameResolve(self):42 self.is_int(variable.SkipNameResolve)43 def test_LowerCaseTableNames(self):44 self.is_int(variable.LowerCaseTableNames)45 def test_ThreadCacheSize(self):46 self.is_int(variable.ThreadCacheSize)47 def test_TableOpenCache(self):48 self.is_int(variable.TableOpenCache)49 def test_TableDefinitionCache(self):50 self.is_int(variable.TableDefinitionCache)51 def test_TableOpenCacheInstances(self):52 self.is_int(variable.TableOpenCacheInstances)53 def test_MaxConnections(self):54 self.is_int(variable.MaxConnections)55 def test_BinlogFormat(self):56 self.is_str(variable.BinlogFormat)57 def test_LogBin(self):58 self.is_int(variable.LogBin)59 def test_BinlogRowsQueryLogEvents(self):60 self.is_int(variable.BinlogRowsQueryLogEvents)61 def test_LogSlaveUpdates(self):62 self.is_int(variable.LogSlaveUpdates)63 def test_ExpireLogsDays(self):64 self.is_int(variable.ExpireLogsDays)65 def test_BinlogCacheSize(self):66 self.is_int(variable.BinlogCacheSize)67 def test_SyncBinlog(self):68 self.is_int(variable.SyncBinlog)69 def test_ErrorLog(self):70 self.is_str(variable.ErrorLog)71 def test_GtidMode(self):72 self.is_str(variable.GtidMode)73 def test_EnforceGtidConsistency(self):74 self.is_str(variable.EnforceGtidConsistency)75 def test_MasterInfoRepository(self):76 self.is_str(variable.MasterInfoRepository)77 def test_RelayLogInfoRepository(self):78 self.is_str(variable.RelayLogInfoRepository)79 def test_SlaveParallelType(self):80 self.is_str(variable.SlaveParallelType)81 def test_SlaveParallelWorkers(self):82 self.is_int(variable.SlaveParallelWorkers)83 def test_InnodbDataFilePath(self):84 self.is_str(variable.InnodbDataFilePath)85 def test_InnodbTempDataFilePath(self):86 self.is_str(variable.InnodbTempDataFilePath)87 def test_InnodbBufferPoolFilename(self):88 self.is_str(variable.InnodbBufferPoolFilename)89 def test_InnodbLogGroupHomeDir(self):90 self.is_str(variable.InnodbLogGroupHomeDir)91 def test_InnodbLogFilesInGroup(self):92 self.is_int(variable.InnodbLogFilesInGroup)93 def test_InnodbLogFileSize(self):94 self.is_int(variable.InnodbLogFileSize)95 def test_InnodbFileformat(self):96 v = self.get_variable(variable.Version)97 if v.startswith('8'):98 #8.0.x 以上版本已经不再有innodb_file_format参数99 pass100 else:101 self.is_str(variable.InnodbFileformat)102 def test_InnodbFilePerTable(self):103 self.is_int(variable.InnodbFilePerTable)104 def test_InnodbOnlineAlterLogMaxSize(self):105 self.is_int(variable.InnodbOnlineAlterLogMaxSize)106 def test_InnodbOpenFiles(self):107 self.is_int(variable.InnodbOpenFiles)108 def test_InnodbPageSize(self):109 self.is_int(variable.InnodbPageSize)110 def test_InnodbThreadConcurrency(self):111 self.is_int(variable.InnodbThreadConcurrency)112 def test_InnodbReadIoThreads(self):113 self.is_int(variable.InnodbReadIoThreads)114 def test_InnodbWriteIoThreads(self):115 self.is_int(variable.InnodbWriteIoThreads)116 def test_InnodbPurgeThreads(self):117 self.is_int(variable.InnodbPurgeThreads)118 def test_InnodbLockWaitTimeout(self):119 self.is_int(variable.InnodbLockWaitTimeout)120 def test_InnodbSpinWaitDelay(self):121 self.is_int(variable.InnodbSpinWaitDelay)122 def test_InnodbAutoincLockMode(self):123 self.is_int(variable.InnodbAutoincLockMode)124 def test_InnodbStatsAutoRecalc(self):125 self.is_int(variable.InnodbStatsAutoRecalc)126 def test_InnodbStatsPersistent(self):127 self.is_int(variable.InnodbStatsPersistent)128 def test_InnodbStatsPersistentSamplePages(self):129 self.is_int(variable.InnodbStatsPersistentSamplePages)130 def test_InnodbBufferPoolInstances(self):131 self.is_int(variable.InnodbBufferPoolInstances)132 def test_InnodbAdaptiveHashIndex(self):133 self.is_int(variable.InnodbAdaptiveHashIndex)134 def test_InnodbChangeBuffering(self):135 self.is_str(variable.InnodbChangeBuffering)136 def test_InnodbChangeBufferMaxSize(self):137 self.is_int(variable.InnodbChangeBufferMaxSize)138 def test_InnodbFlushNeighbors(self):139 self.is_int(variable.InnodbFlushNeighbors)140 def test_InnodbFlushMethod(self):141 self.is_str(variable.InnodbFlushMethod)142 def test_InnodbDoublewrite(self):143 self.is_int(variable.InnodbDoublewrite)144 def test_InnodbLogBufferSize(self):145 self.is_int(variable.InnodbLogBufferSize)146 def test_InnodbFlushLogAtTimeout(self):147 self.is_int(variable.InnodbFlushLogAtTimeout)148 def test_InnodbFlushLogAtTrxCommit(self):149 self.is_int(variable.InnodbFlushLogAtTrxCommit)150 def test_InnodbBufferPoolSize(self):151 self.is_int(variable.InnodbBufferPoolSize)152 def test_Autocommit(self):153 self.is_str(variable.Autocommit)154 def test_InnodbOldBlocksPct(self):155 self.is_int(variable.InnodbOldBlocksPct)156 def test_InnodbOldBlocksTime(self):157 self.is_int(variable.InnodbOldBlocksTime)158 def test_InnodbReadAheadThreshold(self):159 self.is_int(variable.InnodbReadAheadThreshold)160 def test_InnodbRandomReadAhead(self):161 self.is_int(variable.InnodbRandomReadAhead)162 def test_InnodbBufferPoolDumpPct(self):163 self.is_int(variable.InnodbBufferPoolDumpPct)164 def test_InnodbBufferPoolDumpAtShutdown(self):165 self.is_int(variable.InnodbBufferPoolDumpAtShutdown)166 def test_InnodbBufferPoolLoadAtStartup(self):167 self.is_int(variable.InnodbBufferPoolLoadAtStartup)168 def test_QueryCacheLimit(self):169 if not self.get_variable(variable.Version).startswith('8'):170 self.is_int(variable.QueryCacheLimit)171 def test_QueryCacheMinResUnit(self):172 if not self.get_variable(variable.Version).startswith('8'):173 self.is_int(variable.QueryCacheMinResUnit)174 def test_QueryCacheSize(self):175 if not self.get_variable(variable.Version).startswith('8'):176 self.is_int(variable.QueryCacheSize)177 def test_QueryCacheType(self):178 if not self.get_variable(variable.Version).startswith('8'):179 self.is_int(variable.QueryCacheType)180 def test_Version(self):181 self.is_str(variable.Version)182if __name__=="__main__":...

Full Screen

Full Screen

day18.py

Source:day18.py Github

copy

Full Screen

...6 self.left = ch17 self.right = ch28 self.parent = None9 def is_simple_node(self):10 return is_int(self.left) and is_int(self.right)11 def __repr__(self):12 return f'[{self.left},{self.right}]'13 def magnitude(self):14 mag = 015 if is_int(self.left):16 mag += 3 * self.left17 else:18 mag += 3 * self.left.magnitude()19 if is_int(self.right):20 mag += 2 * self.right21 else:22 mag += 2 * self.right.magnitude()23 return mag24def is_node(v): return isinstance(v, Node)25def is_int(v): return isinstance(v, int)26def parse_snail(d):27 stack = []28 current_level = 029 for c in filter(lambda s: s not in list(', '), d):30 if c == '[':31 current_level += 132 elif c == ']':33 v1 = stack.pop()34 v2 = stack.pop()35 n = Node(current_level, v2, v1)36 if is_node(v1): v1.parent = n37 if is_node(v2): v2.parent = n38 stack.append(n)39 current_level -= 140 else:41 stack.append(int(c))42 return stack[0]43def inc_level(p):44 if not is_node(p): return45 p.level += 146 inc_level(p.left)47 inc_level(p.right)48def add_snails(s1, s2):49 s = Node(0, s1, s2)50 s1.parent = s51 s2.parent = s52 inc_level(s)53 return s54def explode_left(p, v):55 t = p.parent56 if is_int(t.left):57 t.left += v58 return59 prev = p60 while t and prev == t.left:61 prev = t62 t = t.parent63 if t is None: return64 if is_int(t.left):65 t.left += v66 return67 t = t.left68 while is_node(t.right):69 t = t.right70 t.right += v71def explode_right(p, v):72 t = p.parent73 if is_int(t.right):74 t.right += v75 return76 prev = p77 while t and prev == t.right:78 prev = t79 t = t.parent80 if t is None: return81 if is_int(t.right):82 t.right += v83 return84 t = t.right85 while is_node(t.left):86 t = t.left87 t.left += v88def explode_node(n: Node):89 if n is None: return90 p = n.parent91 explode_right(n, n.right)92 explode_left(n, n.left)93 if p.left == n:94 p.left = 095 else:96 p.right = 097def split_node(n: Node):98 if n is None: return99 if is_int(n.left) and n.left > 9:100 v = n.left101 n.left = Node(n.level + 1, floor(v / 2), ceil(v / 2))102 n.left.parent = n103 return104 if is_int(n.right) and n.right > 9:105 v = n.right106 n.right = Node(n.level + 1, floor(v / 2), ceil(v / 2))107 n.right.parent = n108 return109def check_for_explode(p):110 if is_int(p): return None111 if is_node(p) and p.level == 5: return p112 for_explode = check_for_explode(p.left)113 if for_explode: return for_explode114 return check_for_explode(p.right)115def check_for_split(p):116 if is_int(p.left) and is_int(p.right):117 if p.left > 9 or p.right > 9: return p118 return None119 elif is_int(p.left):120 if p.left > 9: return p121 return check_for_split(p.right)122 elif is_int(p.right):123 found = check_for_split(p.left)124 if found: return found125 if p.right > 9: return p126 return None127 else:128 found = check_for_split(p.left)129 if found: return found130 found = check_for_split(p.right)131 if found: return found132 return None133def reduce_snail(snail):134 while True:135 found = check_for_explode(snail)136 if found:...

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