MCPcopy Create free account
hub / github.com/PyTables/PyTables / create_test_method

Function create_test_method

tables/tests/test_queries.py:362–508  ·  view source on GitHub ↗
(type_, op, extracond, func=None)

Source from the content-addressed store, hash-verified

360
361
362def create_test_method(type_, op, extracond, func=None):
363 sctype = sctype_from_type[type_]
364
365 # Compute the value of bounds.
366 condvars = {
367 "bound": right_bound,
368 "lbound": left_bound,
369 "rbound": right_bound,
370 "func_bound": func_bound,
371 }
372 for bname, bvalue in condvars.items():
373 if type_ == "string":
374 bvalue = str_format % bvalue
375 bvalue = nxtype_from_type[type_](bvalue)
376 condvars[bname] = bvalue
377
378 # Compute the name of columns.
379 colname = "c_%s" % type_
380 ncolname = "c_nested/%s" % colname
381
382 # Compute the query condition.
383 if not op: # as is
384 cond = colname
385 elif op == "~": # unary
386 cond = "~(%s)" % colname
387 elif op == "<" and func is None: # binary variable-constant
388 cond = f'{colname} {op} {_old_repr(condvars["bound"])}'
389 elif isinstance(op, tuple): # double binary variable-constant
390 cond = f"(lbound {op[0]} {colname}) & ({colname} {op[1]} rbound)"
391 elif func is not None:
392 cond = f"{func}({colname}) {op} func_bound"
393 else: # function or binary variable-variable
394 cond = f"{colname} {op} bound"
395 if extracond:
396 cond = f"({cond}) {extracond}"
397
398 def ignore_skipped(oldmethod):
399 @functools.wraps(oldmethod)
400 def newmethod(self, *args, **kwargs):
401 self._verboseHeader()
402 try:
403 return oldmethod(self, *args, **kwargs)
404 except SilentlySkipTest as se:
405 if se.args:
406 msg = se.args[0]
407 else:
408 msg = "<skipped>"
409 common.verbosePrint("\nSkipped test: %s" % msg)
410 finally:
411 common.verbosePrint("") # separator line between tests
412
413 return newmethod
414
415 @ignore_skipped
416 def test_method(self):
417 common.verbosePrint("* Condition is ``%s``." % cond)
418 # Replace bitwise operators with their logical counterparts.
419 pycond = cond

Callers 1

add_test_methodFunction · 0.85

Calls 2

_old_reprFunction · 0.85
itemsMethod · 0.45

Tested by

no test coverage detected