How to use normalize_node_hierarchy method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

report.py

Source:report.py Github

copy

Full Screen

...329 return cls(cls._TEST_SESSION_TEARDOWN)330 @classmethod331 def in_suite_setup(cls, suite):332 # type: (TreeNodeHierarchy) -> ReportLocation333 return cls(cls._SUITE_SETUP, normalize_node_hierarchy(suite))334 @classmethod335 def in_suite_teardown(cls, suite):336 # type: (TreeNodeHierarchy) -> ReportLocation337 return cls(cls._SUITE_TEARDOWN, normalize_node_hierarchy(suite))338 @classmethod339 def in_test(cls, test):340 # type: (TreeNodeHierarchy) -> ReportLocation341 return cls(cls._TEST, normalize_node_hierarchy(test))342 def get(self, report):343 # type: (Report) -> Union[Result, SuiteResult, TestResult, None]344 if self.node_type == self._TEST_SESSION_SETUP:345 return report.test_session_setup346 elif self.node_type == self._TEST_SESSION_TEARDOWN:347 return report.test_session_teardown348 elif self.node_type == self._SUITE_SETUP:349 suite = report.get_suite(self.node_hierarchy)350 return suite.suite_setup351 elif self.node_type == self._SUITE_TEARDOWN:352 suite = report.get_suite(self.node_hierarchy)353 return suite.suite_teardown354 elif self.node_type == self._TEST:355 return report.get_test(self.node_hierarchy)...

Full Screen

Full Screen

testtree.py

Source:testtree.py Github

copy

Full Screen

...75 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 suite152 for sub_suite in flatten_suites(suite.get_suites()):153 yield sub_suite154def flatten_tests(suites):155 # type: (Sequence[S]) -> Generator[T]156 for suite in flatten_suites(suites):157 for test in suite.get_tests():158 yield test159def find_suite(suites, hierarchy):160 # type: (Sequence[S], TreeNodeHierarchy) -> S161 hierarchy = normalize_node_hierarchy(hierarchy)162 lookup_suites = suites163 lookup_suite = None164 for lookup_suite_name in hierarchy:165 try:166 lookup_suite = next(s for s in lookup_suites if s.name == lookup_suite_name)167 except StopIteration:168 raise LookupError("Cannot find suite named '%s' within %s" % (169 lookup_suite_name, [s.name for s in lookup_suites]170 ))171 lookup_suites = lookup_suite.get_suites()172 return lookup_suite173def find_test(suites, hierarchy):174 # type: (Sequence[BaseSuite], TreeNodeHierarchy) -> T175 hierarchy = normalize_node_hierarchy(hierarchy)176 suite = find_suite(suites, hierarchy[:-1])177 try:178 return suite.get_test_by_name(hierarchy[-1])179 except KeyError:...

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