Best Python code snippet using autotest_python
Build Order.py
Source:Build Order.py
1'''2use edges to draw graphs and check if it's fully connected3'''4'''5def build_order(projects: list, dependencies: list(tuple())):6 dependency_tree = {p: set() for p in projects}7 build_order_list = []8 unbuilt_projects = set(projects)9 for dependency, project in dependencies:10 dependency_tree[project].add(dependency)11 while unbuilt_projects:12 something_built = False13 for project in unbuilt_projects:14 dependencies = dependency_tree[project]15 16 # if the project has no dependencies i.e. 'e' and 'f'17 if not unbuilt_projects.intersection(dependencies):18 build_order_list.append(project)19 unbuilt_projects.remove(project)20 something_built = True21 22 if not something_built:23 pass24'''25def DFS(nodes, edges):26 adjList = dict()27 for node in nodes:28 if node not in adjList:29 adjList[node] = []30 for n1, n2 in edges:31 if node == n1:32 adjList[node].append(n2)33 print(adjList)34from collections import deque35def build_order_wrong(projects, dependencies):36 '''37 projects: list of nodes38 dependencies: list of edges39 1. append node with no n1 (not in n2) or not in dependencies40 remove them from n1 if in41 (check if n2 in build list, raise error) means there is a loop # A simple graph contains no loops. (Loop (graph theory) - Wikipedia)42 2. set(dependencies) # some n1s have same n243 3. back to 1.44 4. break when there are no dependencies45 '''46 build_list = []47 for node in projects:48 # 1. append node with no n1 (not in n2) or not in dependencies49 if all(node != n2 for _, n2 in dependencies):50 build_list.append(node)51 to_build_queue = deque(build_list)52 while to_build_queue:53 node = to_build_queue.popleft()54 to_build_dependencies = []55 for n1, n2 in dependencies:56 to_build_dependencies.append((n1, n2))57 # add n2 to to_build_queue58 if n1 == node: # and:59 to_build_queue.append(n2)60 build_list.append(n2)61 to_build_dependencies.pop()62 63 dependencies = to_build_dependencies64 return build_list65def build_order(projects, dependencies):66 '''67 while dependencise:68 1. find root: not in n2s69 2. add to build and delete the edges70 '''71 build = []72 dependencies_temp = dependencies.copy()73 projects_temp = projects.copy()74 while dependencies:75 # find the root 76 for node in projects:77 78 root = True79 for n1, n2 in dependencies:80 if n2 == node:81 root = False82 break83 84 if root:85 build.append(node)86 projects_temp.pop(projects_temp.index(node))87 88 # delete the edge if it's dependent on root89 for n1, n2 in dependencies:90 if n1 == node:91 dependencies_temp.pop(dependencies_temp.index((n1, n2)))92 dependencies = dependencies_temp.copy()93 94 # no root found at the first round of attempt, return None95 if not build:96 return None97 projects = projects_temp.copy()98 99 return build + projects100 101 102 103 104 105class NoValidBuildOrderError(Exception):106 pass107def build_order_brute_force(projects, dependencies):108 '''109 find the start node, if no, return None (means no root, it's a loop)110 do DFS111 '''112if __name__ == '__main__':113 test_projects = ['a', 'b', 'c', 'd', 'e', 'f']114 test_dependencies = [('a', 'd'), ('f', 'b'), ('b', 'd'), ('f', 'a'), ('d', 'c')]115 # example answer:116 # ['f', 'e', 'a', 'b', 'd', 'c']117 118 DFS(test_projects, test_dependencies)119 print({1,2,3}.intersection({1,2}))120 a = [1,2,3, 4, 5, 6]121 for i in a:122 if i==2:123 a.pop(1)124 continue125 print(i)126 a = {'a': 1}127 # a['b']128 b = {1,2,3}129 for i in b:130 print(i)131 132 DFS(test_projects, test_dependencies)133 print(build_order(test_projects, test_dependencies))134 135 test_projects = ['a', 'b', 'c', 'd', 'e', 'f', 'g']136 test_dependencies = [137 ('a', 'e'), ('b', 'a'), ('b', 'e'), ('c', 'a'),138 ('d', 'g'), ('f', 'b'), ('f', 'a'), ('f', 'c')139 ]140 print(build_order(test_projects, test_dependencies))141 test_projects = ['a', 'b', 'c', 'd', 'e', 'f', 'g']142 test_dependencies = [143 ('a', 'e'), ('b', 'a'), ('b', 'e'), ('c', 'a'),144 ('d', 'g'), ('f', 'b'), ('f', 'a'), ('f', 'c'),145 ('e', 'f'), ('e', 'd'),146 ]...
test_pdfobjects_script.py
Source:test_pdfobjects_script.py
1#Pdf Object Script Test File2import pytest3import sys4import os5from Model.PdfObject import *6from Scripts import PdfObjectsScript as pos7def test_get_DC_settings_txt():8 path = '/home/kali/Raspberry-Pi4-Forensics/ForinApp/Tests/test_dependencies/'9 filename = 'test.pdf'10 obj_list, paths = pos.get_pdf_objects_list(path, filename, 'False')11 assert len(obj_list) == 012 assert paths[0].endswith('Tests/test_dependencies/test_parser_md5.txt') == True13 assert paths[1].endswith('Tests/test_dependencies/test_parser_locs.txt') == True14 assert paths[2].endswith('Tests/test_dependencies/test_parser_objs.txt') == True15 assert paths[3].endswith('Tests/test_dependencies/test_parser_objs/') == True16 assert paths[4].endswith('Tests/test_dependencies/test_pdfid.txt') == True17 assert os.path.isfile('Tests/test_dependencies/test_parser_md5.txt') == True18 assert os.path.isfile('Tests/test_dependencies/test_parser_locs.txt') == True19 assert os.path.isfile('Tests/test_dependencies/test_parser_objs.txt') == True20 assert os.path.isdir('Tests/test_dependencies/test_parser_objs/') == True21 assert os.path.isfile('Tests/test_dependencies/test_pdfid.txt') == True22 os.system('sudo rm -r Tests/test_dependencies/test_parser*')23 os.system('sudo rm -r Tests/test_dependencies/test_pdfid.txt')24 assert os.path.isfile('Tests/test_dependencies/test_parser_md5.txt') == False25 assert os.path.isfile('Tests/test_dependencies/test_parser_locs.txt') == False26 assert os.path.isfile('Tests/test_dependencies/test_parser_objs.txt') == False27 assert os.path.isdir('Tests/test_dependencies/test_parser_objs/') == False...
script.py
Source:script.py
1import json2import setuptools3import glob4def parse_setup_py(fn) -> object:5 # replace this with imp.from_source or similar instead of compile6 with open(fn) as fh:7 code = compile(fh.read(), 'foo', 'exec')8 l = {}9 g = {}10 exec(code, g, l)11 return l.get('INSTALL_REQUIRES', []), l.get('TESTS_REQUIRE', [])12def main():13 install_dependencies = []14 test_dependencies = []15 for fn in glob.glob('**/setup.py'):16 install, tests = parse_setup_py(fn)17 install_dependencies += install18 test_dependencies += tests19 manifest = [20 open(fn).read().strip() for fn in glob.glob('**/MANIFEST.in')21 ]22 install_dependencies = list((d for d in set(install_dependencies) if not d.startswith('stcg-')))23 test_dependencies = list((d for d in set(test_dependencies) if not d.startswith('stcg-')))24 print(json.dumps(dict(install_requires=install_dependencies, test_dependencies=test_dependencies, manifest=manifest)))25if __name__ == "__main__":...
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!!