Пример #1
0
    def checkFileResult(self, test_case):
        working_dir = TESTS_DIR
        if test_case.working_dir is not None:
            working_dir = os.path.join(working_dir, test_case.working_dir)
        os.chdir(working_dir)
        result = parse.matchLine(
            test_case.input,
            validateFileExists=test_case.validate_file_exists,
        )
        if not result:
            self.assertFalse(
                test_case.match,
                'Line "%s" did not match any regex' % test_case.input,
            )
            return

        file, num, match = result
        self.assertTrue(test_case.match,
                        'Line "%s" did match' % test_case.input)

        self.assertEqual(
            test_case.file,
            file,
            "files not equal |%s| |%s|" % (test_case.file, file),
        )

        self.assertEqual(
            test_case.num,
            num,
            "num matches not equal %d %d for %s" %
            (test_case.num, num, test_case.input),
        )
Пример #2
0
 def testUnresolvable(self):
     file_line = ".../something/foo.py"
     result = parse.matchLine(file_line)
     line_obj = format.LineMatch(FormattedText(file_line), result, 0)
     self.assertTrue(not line_obj.isResolvable(),
                     '"%s" should not be resolvable' % file_line)
     print("Tested unresolvable case.")
Пример #3
0
def getLineObjsFromLines(inputLines, validateFileExists=True, allInput=False):
    lineObjs = {}
    for index, line in enumerate(inputLines):
        line = line.replace("\t", "    ")
        # remove the new line as we place the cursor ourselves for each
        # line. this avoids curses errors when we newline past the end of the
        # screen
        line = line.replace("\n", "")
        formattedLine = FormattedText(line)
        result = parse.matchLine(
            str(formattedLine), validateFileExists=validateFileExists, allInput=allInput
        )

        if not result:
            line = format.SimpleLine(formattedLine, index)
        else:
            line = format.LineMatch(
                formattedLine,
                result,
                index,
                validateFileExists=validateFileExists,
                allInput=allInput,
            )

        lineObjs[index] = line

    return lineObjs
Пример #4
0
    def testAllInputMatches(self):
        for test_case in ALL_INPUT_TEST_CASES:
            result = parse.matchLine(test_case.input, False, True)

            if not result:
                self.assertTrue(
                    test_case.match is None,
                    'Expected a match "%s" where one did not occur.' %
                    test_case.match,
                )
                continue

            (match, _, _) = result
            self.assertEqual(
                match,
                test_case.match,
                'Line "%s" did not match.' % test_case.input,
            )

        print("Tested %d cases for all-input matching." %
              len(ALL_INPUT_TEST_CASES))
Пример #5
0
                    this_case.input = test_input
                    self.checkFileResult(this_case)
        print("Tested %d cases for file fuzz." % len(FILE_TEST_CASES))

    def testUnresolvable(self):
        file_line = ".../something/foo.py"
        result = parse.matchLine(file_line)
        line_obj = format.LineMatch(FormattedText(file_line), result, 0)
        self.assertTrue(not line_obj.isResolvable(),
                        '"%s" should not be resolvable' % file_line)
        print("Tested unresolvable case.")

    def testResolvable(self):
        to_check = [case for case in FILE_TEST_CASES if case.match]
        for test_case in to_check:
            result = parse.matchLine(test_case.input)
            line_obj = format.LineMatch(FormattedText(test_case.input), result,
                                        0)
            self.assertTrue(
                line_obj.isResolvable(),
                'Line "%s" was not resolvable' % test_case.input,
            )
        print("Tested %d resolvable cases." % len(to_check))

    def testFileMatch(self):
        for test_case in FILE_TEST_CASES:
            self.checkFileResult(test_case)
        print("Tested %d cases." % len(FILE_TEST_CASES))

    def testAllInputMatches(self):
        for test_case in ALL_INPUT_TEST_CASES: