Esempio n. 1
0
File: test.py Progetto: COS-Temp/art
 def createFile(self, caseList):
   testFile = CheckerFile("<test_file>")
   for caseEntry in caseList:
     caseName = caseEntry[0]
     testCase = TestCase(testFile, caseName, 0)
     assertionList = caseEntry[1]
     for assertionEntry in assertionList:
       content = assertionEntry[0]
       variant = assertionEntry[1]
       assertion = TestAssertion(testCase, variant, content, 0)
       assertion.addExpression(TestExpression.createPatternFromPlainText(content))
   return testFile
Esempio n. 2
0
 def createFile(self, caseList):
   testFile = CheckerFile("<test_file>")
   for caseEntry in caseList:
     caseName = caseEntry[0]
     testCase = TestCase(testFile, caseName, 0)
     statementList = caseEntry[1]
     for statementEntry in statementList:
       content = statementEntry[0]
       variant = statementEntry[1]
       statement = TestStatement(testCase, variant, content, 0)
       statement.addExpression(TestExpression.createPatternFromPlainText(content))
   return testFile
Esempio n. 3
0
def ParseCheckerAssertion(parent, line, variant, lineNo):
  """ This method parses the content of a check line stripped of the initial
      comment symbol and the CHECK-* keyword.
  """
  assertion = TestAssertion(parent, variant, line, lineNo)
  isEvalLine = (variant == TestAssertion.Variant.Eval)

  # Loop as long as there is something to parse.
  while line:
    # Search for the nearest occurrence of the special markers.
    if isEvalLine:
      # The following constructs are not supported in CHECK-EVAL lines
      matchWhitespace = None
      matchPattern = None
      matchVariableDefinition = None
    else:
      matchWhitespace = re.search(r"\s+", line)
      matchPattern = re.search(TestExpression.Regex.regexPattern, line)
      matchVariableDefinition = re.search(TestExpression.Regex.regexVariableDefinition, line)
    matchVariableReference = re.search(TestExpression.Regex.regexVariableReference, line)

    # If one of the above was identified at the current position, extract them
    # from the line, parse them and add to the list of line parts.
    if __isMatchAtStart(matchWhitespace):
      # A whitespace in the check line creates a new separator of line parts.
      # This allows for ignored output between the previous and next parts.
      line = line[matchWhitespace.end():]
      assertion.addExpression(TestExpression.createSeparator())
    elif __isMatchAtStart(matchPattern):
      pattern = line[0:matchPattern.end()]
      pattern = pattern[2:-2]
      line = line[matchPattern.end():]
      assertion.addExpression(TestExpression.createPattern(pattern))
    elif __isMatchAtStart(matchVariableReference):
      var = line[0:matchVariableReference.end()]
      line = line[matchVariableReference.end():]
      name = var[2:-2]
      assertion.addExpression(TestExpression.createVariableReference(name))
    elif __isMatchAtStart(matchVariableDefinition):
      var = line[0:matchVariableDefinition.end()]
      line = line[matchVariableDefinition.end():]
      colonPos = var.find(":")
      name = var[2:colonPos]
      body = var[colonPos+1:-2]
      assertion.addExpression(TestExpression.createVariableDefinition(name, body))
    else:
      # If we're not currently looking at a special marker, this is a plain
      # text match all the way until the first special marker (or the end
      # of the line).
      firstMatch = __firstMatch([ matchWhitespace,
                                  matchPattern,
                                  matchVariableReference,
                                  matchVariableDefinition ],
                                line)
      text = line[0:firstMatch]
      line = line[firstMatch:]
      if isEvalLine:
        assertion.addExpression(TestExpression.createPlainText(text))
      else:
        assertion.addExpression(TestExpression.createPatternFromPlainText(text))
  return assertion
Esempio n. 4
0
File: test.py Progetto: COS-Temp/art
 def assertEqualsText(self, string, text):
     self.assertEqual(self.parseExpression(string),
                      TestExpression.createPatternFromPlainText(text))
Esempio n. 5
0
def ParseCheckerAssertion(parent, line, variant, lineNo):
    """ This method parses the content of a check line stripped of the initial
      comment symbol and the CHECK-* keyword.
  """
    assertion = TestAssertion(parent, variant, line, lineNo)
    isEvalLine = (variant == TestAssertion.Variant.Eval)

    # Loop as long as there is something to parse.
    while line:
        # Search for the nearest occurrence of the special markers.
        if isEvalLine:
            # The following constructs are not supported in CHECK-EVAL lines
            matchWhitespace = None
            matchPattern = None
            matchVariableDefinition = None
        else:
            matchWhitespace = re.search(r"\s+", line)
            matchPattern = re.search(TestExpression.Regex.regexPattern, line)
            matchVariableDefinition = re.search(
                TestExpression.Regex.regexVariableDefinition, line)
        matchVariableReference = re.search(
            TestExpression.Regex.regexVariableReference, line)

        # If one of the above was identified at the current position, extract them
        # from the line, parse them and add to the list of line parts.
        if __isMatchAtStart(matchWhitespace):
            # A whitespace in the check line creates a new separator of line parts.
            # This allows for ignored output between the previous and next parts.
            line = line[matchWhitespace.end():]
            assertion.addExpression(TestExpression.createSeparator())
        elif __isMatchAtStart(matchPattern):
            pattern = line[0:matchPattern.end()]
            pattern = pattern[2:-2]
            line = line[matchPattern.end():]
            assertion.addExpression(TestExpression.createPattern(pattern))
        elif __isMatchAtStart(matchVariableReference):
            var = line[0:matchVariableReference.end()]
            line = line[matchVariableReference.end():]
            name = var[2:-2]
            assertion.addExpression(
                TestExpression.createVariableReference(name))
        elif __isMatchAtStart(matchVariableDefinition):
            var = line[0:matchVariableDefinition.end()]
            line = line[matchVariableDefinition.end():]
            colonPos = var.find(":")
            name = var[2:colonPos]
            body = var[colonPos + 1:-2]
            assertion.addExpression(
                TestExpression.createVariableDefinition(name, body))
        else:
            # If we're not currently looking at a special marker, this is a plain
            # text match all the way until the first special marker (or the end
            # of the line).
            firstMatch = __firstMatch([
                matchWhitespace, matchPattern, matchVariableReference,
                matchVariableDefinition
            ], line)
            text = line[0:firstMatch]
            line = line[firstMatch:]
            if isEvalLine:
                assertion.addExpression(TestExpression.createPlainText(text))
            else:
                assertion.addExpression(
                    TestExpression.createPatternFromPlainText(text))
    return assertion
Esempio n. 6
0
 def assertEqualsText(self, string, text):
   self.assertEqual(self.parseExpression(string), TestExpression.createPatternFromPlainText(text))