How to use create_function method in localstack

Best Python code snippet using localstack_python

query_db.py

Source:query_db.py Github

copy

Full Screen

...202def get_connection(sqlitedb_path, addfunctions=True):203 sqlite.enable_callback_tracebacks(addfunctions)204 conn = sqlite.connect(sqlitedb_path)205 if addfunctions:206 conn.create_function("re_match", 2, regex_match)207 conn.create_function("re_search", 2, regex_search)208 conn.create_function("re_sub", 3, regex_sub)209 conn.create_function("acos", 1, math_acos)210 conn.create_function("acosh", 1, math_acosh)211 conn.create_function("asin", 1, math_asin)212 conn.create_function("asinh", 1, math_asinh)213 conn.create_function("atan", 1, math_atan)214 conn.create_function("atanh", 1, math_atanh)215 conn.create_function("atan2", 2, math_atan2)216 conn.create_function("ceil", 1, math_ceil)217 conn.create_function("cos", 1, math_cos)218 conn.create_function("cosh", 1, math_cosh)219 conn.create_function("degrees", 1, math_degrees)220 conn.create_function("exp", 1, math_exp)221 conn.create_function("expm1", 1, math_expm1)222 conn.create_function("fabs", 1, math_fabs)223 conn.create_function("floor", 1, math_floor)224 conn.create_function("fmod", 2, math_fmod)225 conn.create_function("log", 1, math_log)226 conn.create_function("log", 2, math_blog)227 conn.create_function("log10", 1, math_log10)228 conn.create_function("log2", 1, math_log2)229 conn.create_function("log1p", 1, math_log1p)230 conn.create_function("mod", 2, math_mod)231 conn.create_function("pow", 2, math_pow)232 conn.create_function("radians", 1, math_radians)233 conn.create_function("sin", 1, math_sin)234 conn.create_function("sinh", 1, math_sinh)235 conn.create_function("sqrt", 1, math_sqrt)236 conn.create_function("tan", 1, math_tan)237 conn.create_function("tanh", 1, math_tanh)238 conn.create_function("trunc", 1, math_trunc)239 return conn240def describe_tables(conn, outputFile):241 try:242 c = conn.cursor()243 tables_query = TABLE_QUERY244 rslt = c.execute(tables_query).fetchall()245 for table, sql in rslt:246 print("Table %s:" % table, file=outputFile)247 try:248 col_query = 'SELECT * FROM %s LIMIT 0' % table249 cur = conn.cursor().execute(col_query)250 cols = [col[0] for col in cur.description]251 print(" Columns: %s" % cols, file=outputFile)252 except Exception as exc:...

Full Screen

Full Screen

Functions.py

Source:Functions.py Github

copy

Full Screen

...36 self.arity = arity37 # No. of inputs of the function38 self.ret_type = ret_type39# This function is called when a new function is to be made.40def create_function(function, name, arity):41 if not isinstance(arity, int):42 raise ValueError('arity of the function %s should be int, got %s' % (name, type(arity)))43 return _Function(function, name, arity);44def _protectedDiv(left, right):45 try:46 # Converting the np primitives to ordinary primitives so as to avoid any numpy related error.47 left = np.float64(left).item()48 right = np.float64(right).item()49 return left / right50 except ZeroDivisionError:51 return 152def _protectedSqrt(arg):53 return np.sqrt(np.abs(arg))54def get_arity(func):55 return _common_functions[func].arity56def get_function(func):57 return _common_functions[func].function58# Making some common function to be used in the tree. More functions can be created here.59add1 = create_function(np.add, "add", 2)60sub1 = create_function(np.subtract, "sub", 2)61mul1 = create_function(np.multiply, "mul", 2)62div1 = create_function(_protectedDiv, "div", 2)63less1 = create_function(np.less, "lt", 2)64great1 = create_function(np.greater, "gt", 2)65max1 = create_function(np.maximum, "max", 2)66min1 = create_function(np.minimum, "min", 2)67sin1 = create_function(np.sin, "sin", 1)68cos1 = create_function(np.cos, "cos", 1)69tan1 = create_function(np.tan, "tan", 1)70neg1 = create_function(np.negative, "neg", 1)71abs1 = create_function(np.abs, "abs", 1)72sqrt1 = create_function(_protectedSqrt, "sqrt", 1)73_common_functions = {'add': add1,74 'sub': sub1,75 'mul': mul1,76 'div': div1,77 'lt': less1,78 'gt': great1,79 'sqrt': sqrt1,80 'max': max1,81 'min': min1,82 'sin': sin1,83 'cos': cos1,84 'tan': tan1,85 'neg': neg1,86 'abs': abs1}

Full Screen

Full Screen

mock.py

Source:mock.py Github

copy

Full Screen

...47 _tan,48 _to_base6449 )50 mock_db = sqlite3.connect(":memory:")51 mock_db.create_function("carve", 1, _carve)52 mock_db.create_function("SPLIT", 3, _split)53 mock_db.create_function("concat", -1, _concat)54 mock_db.create_function("concat_ws", -1, _concat_ws)55 mock_db.create_function("regex_split", 3, _regex_split)56 mock_db.create_function("regex_match", 3, _regex_match)57 mock_db.create_function("inet_aton", 1, _inet_aton)58 mock_db.create_function("community_id_v1", -1, _community_id_v1)59 mock_db.create_function("to_base64", 1, _to_base64)60 mock_db.create_function("from_base64", 1, _from_base64)61 mock_db.create_function("conditional_to_base64", 1, _conditional_to_base64)62 mock_db.create_function("sqrt", 1, _sqrt)63 mock_db.create_function("log", 1, _log)64 mock_db.create_function("log10", 1, _log10)65 mock_db.create_function("ceil", 1, _ceil)66 mock_db.create_function("floor", 1, _floor)67 mock_db.create_function("power", 1, _power)68 mock_db.create_function("sin", 1, _sin)69 mock_db.create_function("cos", 1, _cos)70 mock_db.create_function("tan", 1, _tan)71 mock_db.create_function("asin", 1, _asin)72 mock_db.create_function("acos", 1, _acos)73 mock_db.create_function("atan", 1, _atan)74 mock_db.create_function("cot", 1, _cot)75 mock_db.create_function("degrees", 1, _degrees)76 mock_db.create_function("radians", 1, _radians)77 for ddl in schema:78 mock_db.execute(ddl)79 for ddl in extension_schema:80 mock_db.execute(ddl)81 cursor = mock_db.cursor()82 cursor.execute("SELECT name,sql FROM sqlite_master WHERE type='table';")83 for osquery_table in cursor.fetchall():84 PolyLogyxServerDefaults.POLYLOGYX_OSQUERY_SCHEMA_JSON[osquery_table[0]] = osquery_table[1]85 return mock_db86def validate_osquery_query(query):87 # Check if this thread has an instance of the SQLite database88 db = getattr(osquery_mock_db, "db", None)89 if db is None:90 db = create_mock_db()...

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