def test_create_mapping_between_test_and_function(with_database): file = SourceFile.get_by_file_path("one.r") testCase = TestCase.create("apoijwdapoijwd", file.fileID) function = Function.create("paoiwdjaowidj", file.fileID) testCase.create_mapping(function) function = Function.get_by_name_and_file_id(function.name, file.fileID) assert testCase.name in function.testCaseNames
def test_assigns_all_fields_but_exercised_with_mappings(with_database): file = SourceFile.create("blah.r", 0, ".") testCase = TestCase.create("apoijwdapoijwd", file.fileID) assert testCase.filesExercised is None or len(testCase.filesExercised) == 0 assert testCase.functionsExercised is None or len( testCase.functionsExercised) == 0 assert testCase.fileIdsExercised is not None and file.fileID in testCase.fileIdsExercised assert testCase.testCaseID is not None assert testCase.name is not None
def test_assigns_all_fields_with_mappings(with_database): file = SourceFile.get_by_file_path("one.r") testCase = TestCase.create("apoijwdapoijwd", file.fileID) function = Function.create("paoiwdjaowidj", file.fileID) testCase.create_mapping(function) assert testCase.filesExercised is not None assert testCase.functionsExercised is not None assert testCase.fileIdsExercised is not None assert testCase.testCaseID is not None assert testCase.name is not None
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_create(with_database): file = SourceFile.get_by_file_path("one.r") testCase = TestCase.create("someTest", file.fileID) assert testCase is not None assert testCase.name == "someTest"