def test_no_relicense(): args = ArgsMock(license_expression=['GPL-2.0-only and MPL-2.0'], relicense_file='', no_relicense=True) imp = FlictImpl(args) ret = imp.suggest_outbound_candidate() assert ['GPL-2.0-only'] == json.loads(ret) args = ArgsMock(license_expression=['GPL-2.0-only and MPL-2.0'], relicense_file='') ret = FlictImpl(args).suggest_outbound_candidate() assert ['GPL-2.0-only'] == json.loads(ret)
def test_verify_file(): prj_file = os.path.join(TEST_DIR, 'example-data/europe-small.json') args = ArgsMock(project_file=prj_file) ret = FlictImpl(args).verify() assert ret != None args = ArgsMock(project_file=prj_file, license_combination_count=True) ret = FlictImpl(args).verify() assert ret != None args = ArgsMock(project_file=prj_file, list_project_licenses=True) ret = FlictImpl(args).verify() assert ret != None
def test_complex_compat(): expr = ['MIT BSD GPL-2.0-only WITH Classpath-exception-2.0'] args = ArgsMock(license_expression=expr) ret = FlictImpl(args).display_compatibility() jret = json.loads(ret) # this can not be a direct comparism as the result is in random order as of now for lic in ['BSD-3-Clause', 'GPL-2.0-only WITH Classpath-exception-2.0', 'MIT']: assert any(x['license'] == lic for x in jret['compatibilities'])
def test_exceptions(): with pytest.raises(FlictError) as _error: args = ArgsMock(license_expression=['MIT and BSD ,,,']) FlictImpl(args).simplify() assert _error.value.args[0] == ReturnCodes.RET_INVALID_EXPRESSSION with pytest.raises(FlictError) as _error: args = ArgsMock(license_expression=['MIT ,,,']) FlictImpl(args).suggest_outbound_candidate() assert _error.value.args[0] == ReturnCodes.RET_INVALID_EXPRESSSION with pytest.raises(FlictError) as _error: args = ArgsMock(license_expression=['MIT ...']) FlictImpl(args).display_compatibility() assert _error.value.args[0] == ReturnCodes.RET_INVALID_EXPRESSSION with pytest.raises(FlictError) as _error: prj = os.path.join(TEST_DIR, 'example-data') args = ArgsMock(project_file=prj) FlictImpl(args).verify() assert _error.value.args[0] == ReturnCodes.RET_FILE_NOT_FOUND with pytest.raises(FlictError) as _error: prj = os.path.join(TEST_DIR, 'setup.py') args = ArgsMock(project_file=prj) FlictImpl(args).verify() assert _error.value.args[0] == ReturnCodes.RET_INVALID_PROJECT with pytest.raises(FlictError) as _error: prj = os.path.join(TEST_DIR, 'example-data/europe-small-bad.json') args = ArgsMock(project_file=prj) FlictImpl(args).verify() assert _error.value.args[0] == ReturnCodes.RET_INVALID_PROJECT with pytest.raises(FlictError) as _error: rep = os.path.join(TEST_DIR, 'example-data/bad-non-json-file.json') args = ArgsMock(report_file=rep) FlictImpl(args).policy_report() assert _error.value.args[0] == ReturnCodes.RET_INTERNAL_ERROR with pytest.raises(FlictError) as _error: rep = os.path.join(TEST_DIR, 'example-data/valid-empty-json-file.json') prj = os.path.join(TEST_DIR, 'example-data/bad-non-json-file.json') args = ArgsMock(report_file=rep, policy_file=prj) FlictImpl(args).policy_report() assert _error.value.args[0] == ReturnCodes.RET_INTERNAL_ERROR
def policy_report(args): on_error = "Provided file {fname} was not found." on_error_code = ReturnCodes.RET_FILE_NOT_FOUND try: open(args.report_file).close() except (FileNotFoundError, PermissionError): flict_exit(on_error_code, on_error.format(fname=args.report_file)) try: open(args.policy_file).close() except (FileNotFoundError, PermissionError): flict_exit(on_error_code, on_error.format(fname=args.policy_file)) ret = FlictImpl(args).policy_report() flict_print(args, ret)
def test_verify_expression(): args = ArgsMock(license_expression=['MIT']) ret = FlictImpl(args).verify() assert ret != None
def _test_expression(expression, result): args = ArgsMock(license_expression=expression) ret = FlictImpl(args).suggest_outbound_candidate() assert result == json.loads(ret)
def suggest_outbound_candidate(args): ret = FlictImpl(args).suggest_outbound_candidate() flict_print(args, ret)
def display_compatibility(args): ret = FlictImpl(args).display_compatibility() flict_print(args, ret)
def verify(args): ret = FlictImpl(args).verify() flict_print(args, ret)
def list_licenses(args): ret = FlictImpl(args).list_licenses() flict_print(args, ret)
def simplify(args): ret = FlictImpl(args).simplify() flict_print(args, ret)
def test_compat(): args = ArgsMock(license_expression=['MIT']) ret = FlictImpl(args).display_compatibility() assert '{"compatibilities": [{"license": "MIT", "licenses": []}]}' == ret
def _test_expression(expression, result): args = ArgsMock(license_expression=expression) ret = FlictImpl(args).simplify() assert result == ret