def check_position(self, test_path, expected): """ Check license detection in file or folder against expected result. """ test_location = self.get_test_loc(test_path) result = [] for detected in detect.detect_license(test_location): dlicense, sline, eline, schar, echar, _rid, _score = detected keys = dlicense, sline, eline, schar, echar result.append(keys) assert expected == result
def validate_license_detection(self): # ignore anything returned but the license key detections = detect.detect_license(license_file) # the detected license key is the first member of the returned tuple # for each detection # FIXME: we should check that we have one and only one exact match detected = [d[0] for d in detections] msg = ('%(expected_license)r is not in ' 'detected: %(detected)r' 'through full detection: %(detections)r') % locals() assert expected_license in detected, msg
def data_driven_test_function(self): test_loc = self.get_test_loc(test_file) result = list(detect.detect_license(test_loc, perfect=True)) # the detected license is the first member of the returned tuple license_result = [d[0] for d in result] try: if sort: assert sorted(expected_licenses) == sorted(license_result) else: assert expected_licenses == license_result except: # on failure, we compare against the full results to get # additional failure details, including the test_file if sort: assert sorted(expected_licenses) == ['test file: '+ test_file] + sorted(license_result) else: assert expected_licenses == ['test file: '+ test_file] + result
def data_driven_test_function(self): test_loc = self.get_test_loc(test_file) result = list(detect.detect_license(test_loc, perfect=True)) # the detected license is the first member of the returned tuple license_result = [d[0] for d in result] try: if sort: assert sorted(expected_licenses) == sorted(license_result) else: assert expected_licenses == license_result except: # on failure, we compare against the full results to get # additional failure details, including the test_file if sort: assert sorted(expected_licenses) == [ 'test file: ' + test_file ] + sorted(license_result) else: assert expected_licenses == ['test file: ' + test_file ] + result
def detect_lic(): for location in locations: list(detect.detect_license(location, perfect=True))