Best Python code snippet using gabbi_python
setup.py
Source:setup.py
...20 pass21 def finalize_options(self):22 pass23 def run(self):24 set_test_environ()25 # Wipe existing modules, to make sure coverage data is properly26 # generated for them.27 for key in list(sys.modules.keys()):28 if key.startswith('pgi'):29 del(sys.modules[key])30 try:31 from coverage import coverage32 except ImportError:33 print("Missing 'coverage' module. See "34 "https://pypi.python.org/pypi/coverage or try "35 "`apt-get install python-coverage`")36 return37 cov = coverage()38 cov.start()39 import tests40 tests.test(False, "cffi")41 dest = os.path.join(os.getcwd(), "coverage")42 cov.stop()43 cov.html_report(44 directory=dest,45 ignore_errors=True,46 include=["pgi/*"])47 print("Coverage summary: file://%s/index.html" % dest)48def set_test_environ():49 """Sets LD_LIBRARY_PATH for dlopen and GI_TYPELIB_PATH for gi"""50 ld_path = os.path.join(os.path.dirname(__file__), "tests", "libs")51 paths = os.environ.get("LD_LIBRARY_PATH", "")52 if ld_path not in paths.split(os.pathsep):53 print("Testlibs not in LD_LIBRARY_PATH: exec self with new environ")54 paths = ld_path + os.pathsep + paths55 os.environ["LD_LIBRARY_PATH"] = paths56 # restart the interpreter so dlopen gets te right environ57 exit(subprocess.call([sys.executable] + sys.argv))58 typelib_paths = os.environ.get("GI_TYPELIB_PATH", "")59 if ld_path not in typelib_paths.split(os.pathsep):60 print("Adding %r to GI_TYPELIB_PATH" % ld_path)61 typelib_paths = ld_path + os.pathsep + typelib_paths62 os.environ["GI_TYPELIB_PATH"] = typelib_paths63class TestCommand(Command):64 description = "run unit tests"65 user_options = [66 ("pgi-only", None, "only run pgi"),67 ("gi-only", None, "only run gi"),68 ("backend=", None, "backend"),69 ("strict", None, "make glib warnings/errors fatal"),70 ("filter=", None, "regexp for filter classes"),71 ("exitfirst", "x", "exit instantly on first error or failed test"),72 ]73 def initialize_options(self):74 self.pgi_only = False75 self.gi_only = False76 self.backend = ""77 self.filter = ""78 self.strict = False79 self.exitfirst = False80 def finalize_options(self):81 self.pgi_only = bool(self.pgi_only)82 self.gi_only = bool(self.gi_only)83 self.backend = str(self.backend)84 self.strict = bool(self.strict)85 self.filter = str(self.filter)86 self.exitfirst = bool(self.exitfirst)87 def run(self):88 import tests89 import os90 import platform91 set_test_environ()92 if os.name == "nt":93 self.pgi_only = True94 self.backend = "ctypes"95 self.gi_only = False96 if platform.python_implementation() != "CPython":97 self.pgi_only = True98 self.gi_only = False99 if self.pgi_only and self.gi_only:100 raise ValueError("You can't set both pgi-only and gi-only")101 if self.backend and self.gi_only :102 raise ValueError("Backend selection only works with pgi")103 filtered_runs = []104 runs = [(False, "ctypes"), (False, "cffi"), (True, None)]105 for (run_gi, backend) in runs:106 if run_gi and self.pgi_only:107 continue108 if not run_gi and self.gi_only:109 continue110 if self.backend and self.backend != backend:111 continue112 filtered_runs.append((run_gi, backend))113 # create a filter function for selecting tests by regexp114 if self.filter:115 def filter_tests(name):116 return re.search(self.filter, name) is not None117 else:118 filter_tests = None119 # don't fork with one run120 if len(filtered_runs) == 1:121 run_gi, backend = filtered_runs[0]122 exit(tests.test(123 run_gi, backend, self.strict, filter_tests, self.exitfirst))124 for is_gi, backend in filtered_runs:125 pid = os.fork()126 if pid != 0:127 pid, status = os.waitpid(pid, 0)128 kill_signal = (status & 0xff)129 returncode = (status >> 8) & 0xff130 if not kill_signal:131 if returncode:132 exit(returncode)133 else:134 exit(1)135 else:136 exit(tests.test(137 is_gi, backend, self.strict, filter_tests, self.exitfirst))138class QualityCommand(Command):139 description = "run pep8 pyflakes"140 user_options = []141 def initialize_options(self):142 pass143 def finalize_options(self):144 pass145 def run(self):146 import tests147 exit(tests.test_pep8() != 0)148class BenchmarkCommand(Command):149 description = "run benchmarks"150 user_options = [151 ("pgi-only", None, "only run pgi"),152 ]153 def initialize_options(self):154 self.pgi_only = False155 def finalize_options(self):156 self.pgi_only = bool(self.pgi_only)157 def run(self):158 import benchmarks159 import os160 import platform161 if os.name == "nt":162 exit(benchmarks.run(False, "ctypes"))163 set_test_environ()164 is_cpython = platform.python_implementation() == "CPython"165 runs = [(False, "ctypes"), (False, "cffi"), (True, None)]166 for is_gi, backend in runs:167 if is_gi and (self.pgi_only or not is_cpython):168 continue169 pid = os.fork()170 if pid != 0:171 pid, status = os.waitpid(pid, 0)172 if status:173 exit(status)174 else:175 exit(benchmarks.run(is_gi, backend))176setup(name='pgi',177 version=pgi.__version__,...
test_mongo_minfinparse.py
Source:test_mongo_minfinparse.py
...12# logging.basicConfig(level=logging.DEBUG)13DB_NAME = 'TEST'14client = MongoClient()15DATABASE = client[DB_NAME]16# def set_test_environ(fn):17# # decorate fun. Set fixet test_filemap_dict argument in fn18# def wraper(*args, **kwargs):19# return fn(*args, test_filemap_dict=files)20# return wraper21def set_test_environ(fn=get_triple_data, dic=files):22 # decorate fun. Set fixet test_filemap_dict argument in fn23 def wraper(*args, files=dic):24 return fn(*args, test_data=files)25 return wraper26class MongoTests(unittest.TestCase):27 def setUp(self):28 self.get_triple_data_test = set_test_environ(get_triple_data)29 self.get_triple_data_test_del = set_test_environ(get_triple_data, gen_files_del())30 #31 def tearDown(self):32 MongoClient().drop_database(DB_NAME)33 def test_insert(self):34 result = parent([(data_api_minfin, self.get_triple_data_test),], 'records')35 print(result)36 first_insert_time = datetime.now(tz=local_tz)37 assert result == (308, 0), 'wrong parent return, etalon is 308 records'38 assert result[0] == records.find({}).count(), 'function insert report wrong'39 assert records.find({}).count() == 308, 'should be 308 in "records"'40 assert data_active.find({}).count() == 308, 'should be 308 in "data_active"'41 assert data_active.find({}).count() == records.find({}).count(), 'after first insert "records" and "data_active"' \42 'should be equal'43 assert records.find({'session': True}).count() == 6, 'should be 6 cookies in "records"'...
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!!