Best Python code snippet using tempest_python
testcase.py
Source:testcase.py
1from __future__ import print_function2import sys3import traceback4import StringIO5import torch6from torch.autograd import Variable7class testcase(object):8 """""9 Decorator marking a function as a test case.10 Usage:11 @testcase(structs.Stack)12 def test_push(...):13 ...14 assert CONDITION15 More example test cases in structs.tests.16 """17 def __init__(self, struct_type, arg_lists=None):18 self._struct_type = struct_type19 self._arg_lists = arg_lists20 @property21 def struct_type(self):22 return self._struct_type23 def __call__(self, test):24 name = self._rename(test, self.struct_type)25 def wrap_test(i, args):26 try:27 print("-" * 80)28 test_msg = "Running {}".format(name)29 if i > -1: test_msg += "#{}".format(i)30 test_msg += ".."31 print(test_msg)32 stdout = StringIO.StringIO()33 old_stdout = sys.stdout34 sys.stdout = stdout35 test(*args)36 except Exception:37 sys.stdout = old_stdout38 print(" FAILED!")39 if test.__doc__ is not None:40 print("Documentation:")41 print(test.__doc__)42 output = stdout.getvalue()43 if output:44 print("Stdout:")45 print(stdout.getvalue().strip())46 traceback.print_exc()47 else:48 sys.stdout = old_stdout49 print(" PASSED!")50 finally:51 stdout.close()52 test.__name__ = name53 def run_wrapped_tests():54 if self._arg_lists:55 # Multiple argument configs for the same test.56 for i, args in enumerate(self._arg_lists):57 wrap_test(i, args)58 else:59 # No argument configs specified.60 wrap_test(-1, [])61 run_wrapped_tests._is_test_case = True62 return run_wrapped_tests63 @staticmethod64 def _rename(f, struct_type):65 return "{}::{}".format(struct_type.__name__, f.__name__)66def type_has_tests(struct_type):67 return hasattr(struct_type, "__tests__")68def test_module(module):69 """ Run all the tests defined within a class, module, or dictionary. """70 if isinstance(module, dict):71 d = module72 elif hasattr(module, "__dict__"):73 d = module.__dict__74 else:75 raise ValueError("{} is not a class, module, or dictionary".format(module))76 for obj in d.values():77 if getattr(obj, "_is_test_case", False):78 obj()79def is_close(a, b):80 diff = a - b81 if isinstance(diff, Variable) or isinstance(diff, torch.Tensor):82 abs_fn = torch.abs83 else:84 abs_fn = abs...
test_suite_manager.py
Source:test_suite_manager.py
...32 """33 :type test_suite_path: str34 :return:35 """36 def _is_test_case(list_of_tests):37 non_test_files_to_skip = ["__init__.py", ]38 non_test_extensions_to_skip = ["action", "json"]39 verified_object = list_of_tests.split("/")[-1]40 if verified_object in non_test_files_to_skip:41 return False42 elif verified_object.split(".")[-1] in non_test_extensions_to_skip:43 return False44 elif path.isdir(list_of_tests):45 return False46 return True47 test_suite = TestSuite()48 test_suite.name = test_suite_path.split(path.sep)[-1]49 test_suite.path = test_suite_path50 test_scripts_paths_list = [test_script for test_script in glob.glob("%s%s*" % (test_suite_path, path.sep)) if51 access(test_script, X_OK) and _is_test_case(test_script)]52 test_suite.scripts = []53 for test_script_path in test_scripts_paths_list:54 try:55 test_suite.scripts.append(self.test_script_manager.analyze_test_script(test_script_path))56 except OSError as err:57 if err.errno in [errno.ENOEXEC, errno.EACCES]:58 # script was not executable59 print "Unable to parse %s" % test_script_path60 continue61 else:62 raise...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!