<commit_before>
import nose.tools
from zope.interface import implementedBy

import cc.license
from cc.license import CCLicenseError
from cc.license._lib.interfaces import ILicenseSelector
from cc.license._lib import all_possible_answers

def test_list_selectors():
    """Test that we can get a list of selector strings."""
    selectors = cc.license.selectors.list()
    assert type(selectors) == list
    for s in selectors:
        assert type(s) == str

def test_get_selector():
    """selectors.choose() must return a valid ISelector for each selector."""
    for selector_id in cc.license.selectors.list():
        s = cc.license.selectors.choose(selector_id)
        assert ILicenseSelector in implementedBy(s.__class__)
        s2 = cc.license.selectors.choose(selector_id)
        assert s2 is s # singletons, in a way

def test_id_and_uri():
    for sid in cc.license.selectors.list():
        s = cc.license.selectors.choose(sid)
        assert s.id == sid
        assert 'http://creativecommons.org/license' in s.uri
    
def test_get_selector_key_error():
    """selectors.choose() should raise a CCLicenseError if supplied 
       with an invalid selector id."""
    nose.tools.assert_raises(CCLicenseError,
                             cc.license.selectors.choose, 'roflcopter')

def test_has_license():
    std = cc.license.selectors.choose('standard')
    has = 'http://creativecommons.org/licenses/by/3.0/'
    hasnt = 'roflcopter'
    assert std.has_license(has)
    assert not std.has_license(hasnt)
    # multiple times, to check caching
    assert std.has_license(has)
    assert not std.has_license(hasnt)
    assert std.has_license(has)
    assert not std.has_license(hasnt)

def test_functional_one():
    std = cc.license.selectors.choose('standard')
    uri = 'http://creativecommons.org/licenses/by-nc/3.0/'
    assert std.has_license(uri)
    by_nc = std.by_uri(uri)
    assert std.has_license(uri)
    assert by_nc == std.by_uri(uri)
    # double-check
    assert type(std.by_uri(uri)) == cc.license.License
    assert std.has_license(uri)

<commit_msg>CC0 breaks our expectency of the beginning of the uri :)<commit_after>
import nose.tools
from zope.interface import implementedBy

import cc.license
from cc.license import CCLicenseError
from cc.license._lib.interfaces import ILicenseSelector
from cc.license._lib import all_possible_answers

def test_list_selectors():
    """Test that we can get a list of selector strings."""
    selectors = cc.license.selectors.list()
    assert type(selectors) == list
    for s in selectors:
        assert type(s) == str

def test_get_selector():
    """selectors.choose() must return a valid ISelector for each selector."""
    for selector_id in cc.license.selectors.list():
        s = cc.license.selectors.choose(selector_id)
        assert ILicenseSelector in implementedBy(s.__class__)
        s2 = cc.license.selectors.choose(selector_id)
        assert s2 is s # singletons, in a way

def test_id_and_uri():
    for sid in cc.license.selectors.list():
        s = cc.license.selectors.choose(sid)
        assert s.id == sid
        if s.id == 'CC0':
            assert s.uri == 'http://creativecommons.org/choose/zero/'
        else:
            assert 'http://creativecommons.org/license' in s.uri
    
def test_get_selector_key_error():
    """selectors.choose() should raise a CCLicenseError if supplied 
       with an invalid selector id."""
    nose.tools.assert_raises(CCLicenseError,
                             cc.license.selectors.choose, 'roflcopter')

def test_has_license():
    std = cc.license.selectors.choose('standard')
    has = 'http://creativecommons.org/licenses/by/3.0/'
    hasnt = 'roflcopter'
    assert std.has_license(has)
    assert not std.has_license(hasnt)
    # multiple times, to check caching
    assert std.has_license(has)
    assert not std.has_license(hasnt)
    assert std.has_license(has)
    assert not std.has_license(hasnt)

def test_functional_one():
    std = cc.license.selectors.choose('standard')
    uri = 'http://creativecommons.org/licenses/by-nc/3.0/'
    assert std.has_license(uri)
    by_nc = std.by_uri(uri)
    assert std.has_license(uri)
    assert by_nc == std.by_uri(uri)
    # double-check
    assert type(std.by_uri(uri)) == cc.license.License
    assert std.has_license(uri)


{'fraction_non_alphanumeric': 0.10756419153365718, 'fraction_numerical': 0.003238491788110109, 'mean_word_length': 3.22265625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '345355', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1338, 'n_words': 331}