How to use pull_node method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

testtree.py

Source:testtree.py Github

copy

Full Screen

...66 links = OrderedSet()67 for node in self.hierarchy:68 links.update(node.links)69 return links70 def pull_node(self):71 # type: () -> "_N"72 node = copy.copy(self)73 node.parent_suite = None74 return node75 def __str__(self):76 return "<%s %s>" % (self.__class__.__name__, self.path)77_N = TypeVar("_N", bound=BaseTreeNode)78TreeNodeHierarchy = Union[Tuple[str, ...], List, BaseTreeNode, str]79def normalize_node_hierarchy(hierarchy):80 # type: (TreeNodeHierarchy) -> Tuple[str, ...]81 if type(hierarchy) is tuple:82 return hierarchy83 elif type(hierarchy) is list:84 return tuple(hierarchy)85 elif isinstance(hierarchy, BaseTreeNode):86 return tuple(p.name for p in hierarchy.hierarchy)87 else: # assume str88 return tuple(hierarchy.split("."))89class BaseTest(BaseTreeNode):90 pass91T = TypeVar("T", bound=BaseTest)92class BaseSuite(BaseTreeNode):93 def __init__(self, name, description):94 BaseTreeNode.__init__(self, name, description)95 # NB: use OrderedDict instead of list to enable fast test lookup in suites96 # containing a large number of tests97 self._tests = OrderedDict()98 self._suites = []99 def add_test(self, test):100 """101 Add test to the suite.102 """103 test.parent_suite = self104 self._tests[test.name] = test105 def get_tests(self):106 """107 Get suite's tests.108 """109 return list(self._tests.values())110 def get_test_by_name(self, name):111 return self._tests[name]112 def add_suite(self, suite):113 """114 Add a sub-suite to the suite.115 """116 suite.parent_suite = self117 self._suites.append(suite)118 def get_suites(self):119 return self._suites120 def is_empty(self):121 if len(self.get_tests()) != 0:122 return False123 for sub_suite in self.get_suites():124 if not sub_suite.is_empty():125 return False126 return True127 def pull_node(self):128 # type: () -> "BaseSuite"129 node = BaseTreeNode.pull_node(self)130 node._tests = OrderedDict()131 node._suites = []132 return node133 def filter(self, test_filter):134 suite = self.pull_node()135 for test in self.get_tests():136 if test_filter(test):137 suite.add_test(test.pull_node())138 for sub_suite in filter_suites(self.get_suites(), test_filter):139 suite.add_suite(sub_suite)140 return suite141def filter_suites(suites, test_filter):142 return list(143 filter(144 lambda s: not s.is_empty(), (s.filter(test_filter) for s in suites)145 )146 )147S = TypeVar("S", bound=BaseSuite)148def flatten_suites(suites):149 # type: (Sequence[S]) -> Generator[S]150 for suite in suites:151 yield suite...

Full Screen

Full Screen

q3_tools.py

Source:q3_tools.py Github

copy

Full Screen

1import numpy as np2import os, sys3# to import social_network4path2add = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, 'social_network')))5sys.path.append(path2add)6import sn_tools7def get_edges_cascade(pull_node, list_edges_activated):8 list_new_nodes = [pull_node]9 list_cascade_edges = []10 while(len(list_new_nodes) != 0):11 tamp = []12 for node_head in list_new_nodes:13 for edge in list_edges_activated:14 if node_head == edge[0]:15 list_cascade_edges.append(edge)16 tamp.append(edge[1])17 list_new_nodes = tamp18 return list_cascade_edges19 # Find nodes who activate an A node.20def credit_nodes(list_A_node_activated, list_edges_activated, pulled_super_arm):21 list_credit = [0]*len(pulled_super_arm)22 for i in range(len(pulled_super_arm)):23 pull_node = pulled_super_arm[i]24 if pull_node in list_A_node_activated:25# If it is an initial node, we add 1 to his credit because it is possible that it has no edges.26 list_credit[i] += 127 tamp = get_edges_cascade(pull_node, list_edges_activated)28 if len(tamp) != 0:29 list_cascade_node = [num[1] for num in tamp] # get the inherited nodes from the cascade30 for node in list_cascade_node:31 if node in list_A_node_activated: # add a credit if it activates an A node.32 list_credit[i] +=133 return list_credit34def calculate_reward(pulled_super_arm, env, list_nodes_info, budget):35 list_rewards_super_arm = [0] * len(pulled_super_arm)36 # Simulate an episode.37 [episode , list_edges_activated]= sn_tools.simulate_episode(init_prob_matrix = env.p, n_steps_max = 100, budget = env.budget, perfect_nodes = pulled_super_arm)38 # We count only nodes activated regardless of their message. If track = True then we assign rewards at a specific node by tracing the root. If track = False we give the same rewards to all the nodes.39 credits_of_each_node, score_by_seeds_history, nbr_activates = sn_tools.credits_assignment(dataset = [episode], dataset_edges = [list_edges_activated], list_nodes = list_nodes_info, track = env.bool_track, budget = budget)40 # print(credits_of_each_node, '\n')41 if env.bool_track == False:42 i = 043 for node in pulled_super_arm:44 list_rewards_super_arm[i] = (credits_of_each_node[node])/(len(list_nodes_info)) #practilly is the % of nodes activated in the network45 i +=146 else:47 i = 048 for node in pulled_super_arm:49 list_rewards_super_arm[i] = (credits_of_each_node[node]/len(list_nodes_info))50 i +=151 return list_rewards_super_arm52def get_list_features(list_of_nodes, dim):53 list_features = [[0]*dim]*len(list_of_nodes)54 i = 055 for nodes in list_of_nodes:56 list_gender = (nodes.features['gender'])57 list_age = (nodes.features['age'])58 list_interests = (nodes.features['interests'])59 list_location = (nodes.features['location'])60 list_features[i]= list_gender+list_age + list_interests + list_location61 i +=1...

Full Screen

Full Screen

code_traverser.py

Source:code_traverser.py Github

copy

Full Screen

1import astroid2from .classifier import Classifier3from .classifier import Classification4def lazify(ast: astroid.Module) -> set:5 """6 Read the input program and prepare VIEWs, but no PULLs.7 Modifies the input variable in-place and returns a list of names that can be PULLed.8 """9 classifier = Classifier()10 state = {}11 lineno = 012 while lineno < len(ast.body):13 line = ast.body[lineno]14 classification: Classification = classifier.classify(line, state)15 if classification:16 del ast.body[lineno]17 state[classification.name] = classification18 lazy_node = gen_lazy_node(classification.backend)19 ast.last_p2d2_node += 120 ast.body.insert(ast.last_p2d2_node, lazy_node)21 lineno += 122 return set(state) # only the keys23def eagerfy(ast: astroid.Module, eagerfiable: set) -> None:24 """25 inserts PULL nodes in ast26 """27 names_gen = ast.nodes_of_class(astroid.Name)28 names_in_ast = {name.name for name in names_gen}29 to_eagerfy = names_in_ast & eagerfiable30 for view in to_eagerfy:31 pull_node = gen_eager_node(view)32 ast.last_p2d2_node += 133 ast.body.insert(ast.last_p2d2_node, pull_node)34def get_line_name(line: astroid.Expr) -> str:35 """36 Handles 2 cases:37 1. Expr is an Assignment -> return target38 2. Expr is not an Assignment -> return39 """40 return str41def gen_lazy_node(backend_code: str) -> astroid.Expr:42 """43 returns a Call node (wrapped in an Expr) corresponding to this line of code:44 cur.execute("SQL..")45 """46 return astroid.parse(f"cur.execute({backend_code})").body[0]47def gen_eager_node(table_name: str) -> astroid.Expr:48 """49 returns a Call node (wrapped in an Expr) corresponding to this line of code:50 pandas.read_sql_table(table_name= table_name, con=conn)51 """52 return astroid.parse(53 f"pandas.read_sql_table(table_name= {table_name}, con=conn)"...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful