def test_extract_licenses():
    """Test the function extract_licenses()."""
    # TODO: reduce cyclomatic complexity
    # make sure the LRU cache is clear
    get_license_synonyms.cache.clear()
    get_license_synonyms()

    # text/string mode
    with open("/bayesian/tests/data/licenses/licenses.txt") as fin:
        result = extract_licenses([fin])
        _check_extracted_license(result, "bsd-new")

    # binary mode
    with open("/bayesian/tests/data/licenses/licenses.txt", "rb") as fin:
        result = extract_licenses([fin])
        _check_extracted_license(result, "bsd-new")

    # text/string mode
    with open("/bayesian/tests/data/licenses/licenses2.txt") as fin:
        result = extract_licenses([fin])
        _check_extracted_license(result, "gplv2")

    # binary mode
    with open("/bayesian/tests/data/licenses/licenses2.txt", "rb") as fin:
        result = extract_licenses([fin])
        _check_extracted_license(result, "gplv2")
def test_extract_licenses_wrong_file():
    """Test the function extract_licenses()."""
    # make sure the LRU cache is clear
    get_license_synonyms.cache.clear()
    get_license_synonyms()
    result = extract_licenses(["this-is-not-a-file"])
    assert not result
Esempio n. 3
0
def test_extract_licenses(_mocked_object):
    """Test the function extract_licenses()."""
    # TODO: reduce cyclomatic complexity
    # make sure the LRU cache is clear
    get_license_synonyms.cache.clear()
    get_license_synonyms()

    # text/string mode
    with open("/bayesian/tests/data/licenses/licenses.txt") as fin:
        result = extract_licenses([fin])
        assert result
        assert result[1] == "bsd-new"

    # binary mode
    with open("/bayesian/tests/data/licenses/licenses.txt", "rb") as fin:
        result = extract_licenses([fin])
        assert result
        assert result[1] == "bsd-new"

    # text/string mode
    with open("/bayesian/tests/data/licenses/licenses2.txt") as fin:
        result = extract_licenses([fin])
        assert result
        assert result[1] == "gplv2"

    # binary mode
    with open("/bayesian/tests/data/licenses/licenses2.txt", "rb") as fin:
        result = extract_licenses([fin])
        assert result
        assert result[1] == "gplv2"
def test_get_license_synonyms():
    """Test the function get_license_synonyms()."""
    # make sure the LRU cache is clear
    get_license_synonyms.cache.clear()
    result = get_license_synonyms()
    assert len(result) > 0
    assert "bsd" in result
    assert "gpl" in result

    # do the same thing (use LRU actually)
    result = get_license_synonyms()
    assert len(result) > 0
    assert "bsd" in result
    assert "gpl" in result
def test_get_license_synonyms_wrong_response(mocked_get):
    """Test the function get_license_synonyms()."""
    # make sure the LRU cache is clear
    get_license_synonyms.cache.clear()
    result = get_license_synonyms()
    assert not result
    assert mocked_get.called