예제 #1
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)
       if statement.isEvalContentStatement():
         statement.addExpression(TestExpression.createPlainText(content))
       elif statement.isPatternMatchContentStatement():
         statement.addExpression(TestExpression.createPatternFromPlainText(content))
   return testFile
예제 #2
0
 def create_file(self, case_list):
     test_file = CheckerFile("<test_file>")
     for caseEntry in case_list:
         case_name = caseEntry[0]
         test_case = TestCase(test_file, case_name, 0)
         statement_list = caseEntry[1]
         for statementEntry in statement_list:
             content = statementEntry[0]
             variant = statementEntry[1]
             statement = TestStatement(test_case, variant, content, 0)
             if statement.is_eval_content_statement():
                 statement.add_expression(
                     TestExpression.create_plain_text(content))
             elif statement.is_pattern_match_content_statement():
                 statement.add_expression(
                     TestExpression.create_pattern_from_plain_text(content))
     return test_file
예제 #3
0
파일: test.py 프로젝트: 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
예제 #4
0
파일: test.py 프로젝트: COS-Temp/art
 def assertEqualsText(self, string, text):
     self.assertEqual(self.parseExpression(string),
                      TestExpression.createPatternFromPlainText(text))
예제 #5
0
파일: test.py 프로젝트: COS-Temp/art
 def test_VariableReference(self):
     self.assertEqual(self.parseExpressions("<<ABC>>"),
                      [TestExpression.createVariableReference("ABC")])
     self.assertEqual(self.parseExpressions("123<<ABC>>"), [
         TestExpression.createPlainText("123"),
         TestExpression.createVariableReference("ABC")
     ])
     self.assertEqual(self.parseExpressions("123  <<ABC>>"), [
         TestExpression.createPlainText("123  "),
         TestExpression.createVariableReference("ABC")
     ])
     self.assertEqual(self.parseExpressions("<<ABC>>XYZ"), [
         TestExpression.createVariableReference("ABC"),
         TestExpression.createPlainText("XYZ")
     ])
     self.assertEqual(self.parseExpressions("<<ABC>>   XYZ"), [
         TestExpression.createVariableReference("ABC"),
         TestExpression.createPlainText("   XYZ")
     ])
     self.assertEqual(self.parseExpressions("123<<ABC>>XYZ"), [
         TestExpression.createPlainText("123"),
         TestExpression.createVariableReference("ABC"),
         TestExpression.createPlainText("XYZ")
     ])
     self.assertEqual(self.parseExpressions("123 <<ABC>>  XYZ"), [
         TestExpression.createPlainText("123 "),
         TestExpression.createVariableReference("ABC"),
         TestExpression.createPlainText("  XYZ")
     ])
예제 #6
0
파일: test.py 프로젝트: COS-Temp/art
 def assertEqualsVarDef(self, string, name, pattern):
     self.assertEqual(
         self.parseExpression(string),
         TestExpression.createVariableDefinition(name, pattern))
예제 #7
0
파일: test.py 프로젝트: COS-Temp/art
 def assertEqualsVarRef(self, string, name):
     self.assertEqual(self.parseExpression(string),
                      TestExpression.createVariableReference(name))
예제 #8
0
파일: test.py 프로젝트: COS-Temp/art
 def assertEqualsPattern(self, string, pattern):
     self.assertEqual(self.parseExpression(string),
                      TestExpression.createPattern(pattern))
예제 #9
0
 def assertEqualsText(self, string, text):
     self.assertEqual(self.parse_expression(string),
                      TestExpression.create_pattern_from_plain_text(text))
예제 #10
0
파일: test.py 프로젝트: BenzoRoms/art
 def assertEqualsVarRef(self, string, name):
   self.assertEqual(self.parseExpression(string), TestExpression.createVariableReference(name))
예제 #11
0
파일: parser.py 프로젝트: COS-Temp/art
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
예제 #12
0
파일: test.py 프로젝트: BenzoRoms/art
 def assertEqualsPattern(self, string, pattern):
   self.assertEqual(self.parseExpression(string), TestExpression.createPattern(pattern))
예제 #13
0
파일: test.py 프로젝트: BenzoRoms/art
 def assertEqualsText(self, string, text):
   self.assertEqual(self.parseExpression(string), TestExpression.createPatternFromPlainText(text))
예제 #14
0
파일: test.py 프로젝트: BenzoRoms/art
 def test_VariableReference(self):
   self.assertEqual(self.parseExpressions("<<ABC>>"),
                    [ TestExpression.createVariableReference("ABC") ])
   self.assertEqual(self.parseExpressions("123<<ABC>>"),
                    [ TestExpression.createPlainText("123"),
                      TestExpression.createVariableReference("ABC") ])
   self.assertEqual(self.parseExpressions("123  <<ABC>>"),
                    [ TestExpression.createPlainText("123  "),
                      TestExpression.createVariableReference("ABC") ])
   self.assertEqual(self.parseExpressions("<<ABC>>XYZ"),
                    [ TestExpression.createVariableReference("ABC"),
                      TestExpression.createPlainText("XYZ") ])
   self.assertEqual(self.parseExpressions("<<ABC>>   XYZ"),
                    [ TestExpression.createVariableReference("ABC"),
                      TestExpression.createPlainText("   XYZ") ])
   self.assertEqual(self.parseExpressions("123<<ABC>>XYZ"),
                    [ TestExpression.createPlainText("123"),
                      TestExpression.createVariableReference("ABC"),
                      TestExpression.createPlainText("XYZ") ])
   self.assertEqual(self.parseExpressions("123 <<ABC>>  XYZ"),
                    [ TestExpression.createPlainText("123 "),
                      TestExpression.createVariableReference("ABC"),
                      TestExpression.createPlainText("  XYZ") ])
예제 #15
0
파일: test.py 프로젝트: BenzoRoms/art
 def assertEqualsVarDef(self, string, name, pattern):
   self.assertEqual(self.parseExpression(string),
                    TestExpression.createVariableDefinition(name, pattern))
예제 #16
0
파일: parser.py 프로젝트: BenzoRoms/art
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
예제 #17
0
def parse_checker_statement(parent, line, variant, line_no):
    """ This method parses the content of a check line stripped of the initial
      comment symbol and the CHECK-* keyword.
  """
    statement = TestStatement(parent, variant, line, line_no)

    if statement.is_no_content_statement() and line:
        Logger.fail("Expected empty statement: '{}'".format(line),
                    statement.filename, statement.line_no)

    # Loop as long as there is something to parse.
    while line:
        # Search for the nearest occurrence of the special markers.
        if statement.is_eval_content_statement():
            # The following constructs are not supported in CHECK-EVAL, -IF and -ELIF lines
            match_whitespace = None
            match_pattern = None
            match_variable_definition = None
        else:
            match_whitespace = re.search(r"\s+", line)
            match_pattern = re.search(TestExpression.Regex.REGEX_PATTERN, line)
            match_variable_definition = re.search(
                TestExpression.Regex.REGEX_VARIABLE_DEFINITION, line)
        match_variable_reference = re.search(
            TestExpression.Regex.REGEX_VARIABLE_REFERENCE, 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 _is_match_at_start(match_whitespace):
            # 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[match_whitespace.end():]
            statement.add_expression(TestExpression.create_separator())
        elif _is_match_at_start(match_pattern):
            pattern = line[0:match_pattern.end()]
            pattern = pattern[2:-2]
            line = line[match_pattern.end():]
            statement.add_expression(TestExpression.create_pattern(pattern))
        elif _is_match_at_start(match_variable_reference):
            var = line[0:match_variable_reference.end()]
            line = line[match_variable_reference.end():]
            name = var[2:-2]
            statement.add_expression(
                TestExpression.create_variable_reference(name))
        elif _is_match_at_start(match_variable_definition):
            var = line[0:match_variable_definition.end()]
            line = line[match_variable_definition.end():]
            colon_pos = var.find(":")
            name = var[2:colon_pos]
            body = var[colon_pos + 1:-2]
            statement.add_expression(
                TestExpression.create_variable_definition(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).
            first_match = _first_match([
                match_whitespace, match_pattern, match_variable_reference,
                match_variable_definition
            ], line)
            text = line[0:first_match]
            line = line[first_match:]
            if statement.is_eval_content_statement():
                statement.add_expression(
                    TestExpression.create_plain_text(text))
            else:
                statement.add_expression(
                    TestExpression.create_pattern_from_plain_text(text))
    return statement
예제 #18
0
 def test_VariableReference(self):
     self.assertEqual(self.parse_expressions("<<ABC>>"),
                      [TestExpression.create_variable_reference("ABC")])
     self.assertEqual(self.parse_expressions("123<<ABC>>"), [
         TestExpression.create_plain_text("123"),
         TestExpression.create_variable_reference("ABC")
     ])
     self.assertEqual(self.parse_expressions("123  <<ABC>>"), [
         TestExpression.create_plain_text("123  "),
         TestExpression.create_variable_reference("ABC")
     ])
     self.assertEqual(self.parse_expressions("<<ABC>>XYZ"), [
         TestExpression.create_variable_reference("ABC"),
         TestExpression.create_plain_text("XYZ")
     ])
     self.assertEqual(self.parse_expressions("<<ABC>>   XYZ"), [
         TestExpression.create_variable_reference("ABC"),
         TestExpression.create_plain_text("   XYZ")
     ])
     self.assertEqual(self.parse_expressions("123<<ABC>>XYZ"), [
         TestExpression.create_plain_text("123"),
         TestExpression.create_variable_reference("ABC"),
         TestExpression.create_plain_text("XYZ")
     ])
     self.assertEqual(self.parse_expressions("123 <<ABC>>  XYZ"), [
         TestExpression.create_plain_text("123 "),
         TestExpression.create_variable_reference("ABC"),
         TestExpression.create_plain_text("  XYZ")
     ])