Best Python code snippet using tempest_python
test_utils.py
Source:test_utils.py
...17 list_set,18 remove_largest_whitespace_prefix,19 takeafter,20)21def test_is_std_lib() -> None:22 assert not is_std_lib("")23 assert not is_std_lib("foo")24 assert not is_std_lib("pytest")25 stdlib_modules = (26 "argparse",27 "codecs",28 "collections",29 "copy",30 "csv",31 "datetime",32 "decimal",33 "fileinput",34 "fnmatch",35 "functools",36 "glob",37 "gzip",38 "hashlib",39 "hmac",40 "importlib",41 "io",42 "itertools",43 "json",44 "logging",45 "math",46 "numbers",47 "operator",48 "optparse",49 "os",50 "pickle",51 "pprint",52 "random",53 "re",54 "shelve",55 "shutil",56 "socket",57 "sqlite3",58 "ssl",59 "stat",60 "string",61 "struct",62 "subprocess",63 "sys",64 "typing",65 "sysconfig",66 "tempfile",67 "time",68 "timeit",69 "trace",70 "traceback",71 "unittest",72 "uuid",73 "xml",74 "zlib",75 )76 for module in stdlib_modules:77 assert is_std_lib(module)78def test_is_site_package() -> None:79 assert not is_site_package("")80 assert not is_site_package("foo")81 stdlib_modules = ("argparse", "codecs")82 for module in stdlib_modules:83 assert not is_site_package(module)84 # these packages come from requirements-dev.txt85 site_packages_modules = ("pytest", "tox")86 for module in site_packages_modules:87 assert is_site_package(module)88def test_force_text() -> None:89 assert force_text(b"foo") == "foo"90 assert force_text("foo") == "foo"91def test_force_bytes() -> None:...
Dependencies.py
Source:Dependencies.py
...7import re8import subprocess9from stdlib_list import stdlib_list10stdlibs = stdlib_list()11def is_std_lib(module_name):12 return module_name in stdlibs13def is_module(name):14 status, _ = subprocess.getstatusoutput("pip3 show " + name)15 return status == 016if __name__ == "__main__":17 current_path = os.path.split(__file__)[0]18 project_path = os.path.abspath(current_path + "/../")19 print(project_path)20 all_imports = set()21 for filename in glob.iglob(project_path + "/**/*.py", recursive=True):22 # module finder couldn't parse our files :(23 with open(filename) as f:24 imports = filter(lambda s: "import" in s, f.read().splitlines()) # get imports25 imports = map(lambda s: s.strip(), imports) # strip26 imports = filter(lambda s: re.match(r"^(import|from)\s+[A-Za-z\\.]+($|\s+[A-Za-z]+)", s), imports)27 imports = map(lambda s: re.search("^((import|from)\s+[A-Za-z]+)($|\\.|\s+)", s).group(1), imports)28 imports = map(lambda s: s.split()[1], imports) # get just the names29 imports = filter(lambda s: not is_std_lib(s), imports)30 all_imports |= set(imports)31 print("source code checked")32 all_imports = sorted(all_imports, key=lambda s: s.lower())33 module_names = []34 other_names = []35 for import_name in all_imports:36 if is_module(import_name):37 module_names.append(import_name)38 else:39 other_names.append(import_name)40 print("----------------------modules----------------------")41 print("\n".join(module_names))42 print("----------------------other----------------------")43 print("\n".join(other_names))
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!!