Exemplo n.º 1
0
    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
Exemplo n.º 3
0
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"
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
    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()
Exemplo n.º 7
0
    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()
Exemplo n.º 8
0
    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()
Exemplo n.º 9
0
    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()
Exemplo n.º 10
0
 def process(self, snippet):
     t = TestRig(self)
     return t.process_fragment(snippet)
Exemplo n.º 11
0
 def process(self, fragment):
     t = TestRig(fixture=self)
     t.stub_result(None)
     t.process_fragment(fragment)
     return t.success_or_failure()
Exemplo n.º 12
0
 def processDocument(self, html):
     self.rig = TestRig()
     result = self.rig.process_html(html)
     self.root_element = result.root_element
Exemplo n.º 13
0
 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()
Exemplo n.º 14
0
 def succeeds(self, snippet, evaluationResult):
     t = TestRig()
     t.stub_result(evaluationResult)
     return t.process_fragment(snippet).has_succeeded()
Exemplo n.º 15
0
 def render(self, fragment):
     rig = TestRig(fixture=self)
     rig.process_fragment(fragment)
     return rig.get_output_fragment_xml()
Exemplo n.º 16
0
 def myMethodWasCalledProcessing(self, fragment):
     t = TestRig(fixture=self)
     t.process_fragment(fragment)
     return "Will" if self.method_called else "Will Not"
Exemplo n.º 17
0
 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)
Exemplo n.º 20
0
 def process(self, html):
     result = TestRig(fixture=self).process_html(html)
     return "success" if result.has_succeeded() else "failure"
Exemplo n.º 21
0
 def render(self, fragment):
     rig = TestRig()
     rig.stub_result(self.nextResult)
     rig.process_fragment(fragment)
     return rig.get_output_fragment_xml()
Exemplo n.º 22
0
 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)
Exemplo n.º 23
0
 def successOrFailure(self, snippet, outcome):
     t = TestRig()
     t.stub_result(text_to_bool(outcome))
     t.process_fragment(snippet)
     return t.success_or_failure()
Exemplo n.º 24
0
 def getOutputFragment(self, inputFragment):
     test_rig = TestRig(fixture=self)
     test_rig.process_fragment(inputFragment)
     return test_rig.get_output_fragment_xml()
Exemplo n.º 25
0
 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\">", ">")
Exemplo n.º 26
0
 def renderAsSuccess(self, fragment):
     test_rig = TestRig(fixture=self)
     test_rig.process_fragment(fragment)
     return test_rig.get_output_fragment_xml()