def test_get_by_name_and_file_id_exists(with_database):
    file = SourceFile.get_by_file_path("one.r")
    testCase = TestCase.get_by_name_and_file_id("first_test", file.fileID)

    assert testCase is not None
    assert testCase.name == "first_test"
    assert file.fileID in testCase.fileIdsExercised
Exemple #2
0
def parseRTests():
    curString = ""
    status = 0  # not found anything yet
    # fullTests = []
    testMapping = dict()
    testFileNameMapping = dict()
    for filename in os.listdir("AnomalyDetection/tests/testthat"):
        if filename.endswith(".R") and filename.startswith("test-"):
            testFilename = filename
            newTestFilenames = []
            with open(
                    os.path.join("AnomalyDetection/tests/testthat/",
                                 filename)) as fp:
                # content = fp.read()
                # print(content)
                count = 0
                line = fp.readline()
                while line:
                    # print(line)
                    if "test_that" in line:
                        status = 1
                        curString += line
                    elif status == 1:
                        curString += line
                    if curString.count('(') == curString.count(
                            ')') and status == 1:
                        status = 0
                        #fullTests.append(curString)
                        newTestFilename = filename[:-2] + "-" + str(
                            count) + ".R"
                        newTestFilenames.append(newTestFilename)
                        text_file = open(newTestFilename, "w")
                        text_file.write(curString)
                        text_file.close()
                        testMapping[newTestFilename] = curString
                        curString = ""
                        count += 1
                    line = fp.readline()
            testFileNameMapping[testFilename] = newTestFilenames
    # nestedExpr('(',')').parseString(content).asList()
    # print(nestedExpr)
    # for test in fullTests:
    #    print("TEST")
    #    print(test)
    # return fullTests
    src = "AnomalyDetection"
    rCode = "AnomalyDetection"
    repo = Repository.get_by_path(src)
    repo = Repository.create(src) if not repo else repo

    # Add files to files table
    for f in testFileNameMapping.keys():
        filePath = os.path.join(rCode, f)

        if len(f) > 0:
            file = SourceFile.get_by_file_path(filePath)

            if not file:
                file = SourceFile.create(filePath, 1, repo.path)

            funcs = testFileNameMapping[f]

            for func in funcs:
                testCase = TestCase.get_by_name_and_file_id(func, file.fileID)

                if not testCase:
                    testCase = TestCase.create(func, file.fileID)

    return testMapping
def test_get_by_name_and_file_id_not_exists(with_database):
    file = SourceFile.get_by_file_path("one.r")
    testCase = TestCase.get_by_name_and_file_id("apoiwjdaiopwhd", file.fileID)

    assert testCase is None