def processSnippets(self, evaluationResult): result = Result() for i, snippet in enumerate(self.snippets, start=1): t = TestRig() t.stub_result(evaluationResult) has_failed = t.process_fragment(snippet).has_failed() if has_failed: result._failures.append("({})".format(i)) else: result._successes.append("({})".format(i)) return result
def process(self, fragment): r = TestRig(fixture=self).process_fragment(fragment) result = Result() result.successCount = r.num_success result.failureCount = r.num_failure result.exceptionCount = r.num_exception lastEvent = r.last_failed_event() if lastEvent is not None: result.lastActualValue = lastEvent.actual result.lastExpectedValue = lastEvent.expected return result
class StylesheetTest(ConcordionTestCase): def processDocument(self, html): self.rig = TestRig() result = self.rig.process_html(html) self.root_element = result.root_element def getRelativePosition(self, outer, target, sibling): outer_tag = self.root_element.xpath("//{}".format(outer))[0] target_index = 0 sibling_index = 0 for i, children in enumerate(outer_tag.getchildren()): if children.tag == target: target_index = i elif children.tag == sibling: sibling_index = i return "after" if target_index > sibling_index else "before" def elementTextContains(self, elementName, s1, s2): element_tag = self.root_element.xpath("//{}".format(elementName))[0] element_text = etree.tostring(element_tag) result = s1 in element_text and s2 in element_text return "should" if result else "should not"
def countsFromExecutingSnippetWithSimulatedEvaluationResult( self, snippet, outcome): t = TestRig() if outcome == "(An exception)": t.stub_result(RuntimeError()) else: t.stub_result(outcome) return t.process_fragment(snippet)
def countsFromExecutingSnippetWithSimulatedEvaluationResult(self, snippet, outcome): t = TestRig() if outcome == "(An exception)": t.stub_result(RuntimeError()) else: t.stub_result(outcome) return t.process_fragment(snippet)
def outcomeOfPerformingAssertEquals(self, fragment, expectedString, result): if result == "None": result = None fragment = fragment.replace("(some expectation)", expectedString) t = TestRig() t.stub_result(result) t.process_fragment(fragment) return t.success_or_failure()
def outcomeOfPerformingAssertEquals(self, fragment, expectedString, result, resultType): if resultType == "String": simulatedResult = result elif resultType == "Integer": simulatedResult = int(result) elif resultType == "Double": simulatedResult = float(result) else: raise RuntimeError( "Unsupported result-type '{}'".format(resultType)) fragment = fragment.replace("(some expectation)", expectedString) t = TestRig() t.stub_result(simulatedResult) t.process_fragment(fragment) return t.success_or_failure()
def outcomeOfPerformingAssertEquals(self, fragment, expectedString, result, resultType): if resultType == "String": simulatedResult = result elif resultType == "Integer": simulatedResult = int(result) elif resultType == "Double": simulatedResult = float(result) else: raise RuntimeError("Unsupported result-type '{}'".format(resultType )) fragment = fragment.replace("(some expectation)", expectedString) t = TestRig() t.stub_result(simulatedResult) t.process_fragment(fragment) return t.success_or_failure()
def process(self, snippet): t = TestRig(self) return t.process_fragment(snippet)
def process(self, fragment): t = TestRig(fixture=self) t.stub_result(None) t.process_fragment(fragment) return t.success_or_failure()
def processDocument(self, html): self.rig = TestRig() result = self.rig.process_html(html) self.root_element = result.root_element
def renderAsFailure(self, fragment, acronym): self.acronym = acronym test_rig = TestRig(fixture=self) test_rig.process_fragment(fragment) return test_rig.get_output_fragment_xml()
def succeeds(self, snippet, evaluationResult): t = TestRig() t.stub_result(evaluationResult) return t.process_fragment(snippet).has_succeeded()
def render(self, fragment): rig = TestRig(fixture=self) rig.process_fragment(fragment) return rig.get_output_fragment_xml()
def myMethodWasCalledProcessing(self, fragment): t = TestRig(fixture=self) t.process_fragment(fragment) return "Will" if self.method_called else "Will Not"
def matchOrNotMatch(self, snippet, outcome): t = TestRig() t.stub_result(outcome) result = t.process_fragment(snippet) return "match" if not result.has_failed() else "not match"
def process(self, snippet): t = TestRig() t.stub_result("Fred") result = t.process_fragment(snippet) return snippet if not result.has_failed() else "Did not work"
def process(self, html): result = TestRig().process_html(html) self.remove_irrelevant_elements(result.root_element) return etree.tostring(result.root_element)
def process(self, html): result = TestRig(fixture=self).process_html(html) return "success" if result.has_succeeded() else "failure"
def render(self, fragment): rig = TestRig() rig.stub_result(self.nextResult) rig.process_fragment(fragment) return rig.get_output_fragment_xml()
def processFragment(self, fragment, csv): self._usernames = [username.strip() for username in csv.split(",")] result = TestRig(fixture=self).process_fragment(fragment) return self.categorize(result)
def successOrFailure(self, snippet, outcome): t = TestRig() t.stub_result(text_to_bool(outcome)) t.process_fragment(snippet) return t.success_or_failure()
def getOutputFragment(self, inputFragment): test_rig = TestRig(fixture=self) test_rig.process_fragment(inputFragment) return test_rig.get_output_fragment_xml()
def render(self, fragment, evalResult): rig = TestRig() rig.stub_result(evalResult) rig.process_fragment(fragment) result = rig.get_output_fragment_xml() return result.replace(" concordion:echo=\"username\">", ">")
def renderAsSuccess(self, fragment): test_rig = TestRig(fixture=self) test_rig.process_fragment(fragment) return test_rig.get_output_fragment_xml()