Пример #1
0
def test_without():
    l1 = Localization.from_dict({
        'foo.c:1': 1.0,
        'foo.c:2': 0.5,
        'foo.c:3': 0.1
    })

    l2 = l1.without(l('foo.c:2'))
    assert l2 == \
        Localization.from_dict({
            'foo.c:1': 1.0,
            'foo.c:3': 0.1
        })

    l3 = l2.without(l('foo.c:2'))
    assert l3 == \
        Localization.from_dict({
            'foo.c:1': 1.0,
            'foo.c:3': 0.1
        })

    l4 = l3.without(l('foo.c:1'))
    assert l4 == \
        Localization.from_dict({
            'foo.c:3': 0.1
        })

    with pytest.raises(darjeeling.exceptions.NoImplicatedLines):
        l4.without(l('foo.c:3'))
Пример #2
0
def test_files():
    loc = Localization.from_dict({
        'foo.c:1': 1.0,
        'foo.c:2': 1.0,
        'bar.c:1': 1.0
    })
    assert set(loc.files) == {'foo.c', 'bar.c'}
Пример #3
0
def test_contains():
    loc = Localization.from_dict({
        'foo.c:1': 1.0,
        'foo.c:2': 1.0,
        'foo.c:3': 1.0
    })
    assert l('foo.c:1') in loc
    assert l('foo.c:2') in loc
    assert l('foo.c:3') in loc
    assert l('foo.c:4') not in loc
    assert l('bar.c:1') not in loc
Пример #4
0
def test_get():
    loc = Localization.from_dict({
        'foo.c:1': 1.0,
        'foo.c:2': 0.5,
        'foo.c:3': 0.1
    })
    assert loc[l('foo.c:1')] == 1.0
    assert loc[l('foo.c:2')] == 0.5
    assert loc[l('foo.c:3')] == 0.1
    assert loc[l('foo.c:4')] == 0.0
    assert loc[l('bar.c:1')] == 0.0
Пример #5
0
def test_iter():
    loc = Localization.from_dict({
        'foo.c:1': 1.0,
        'foo.c:2': 1.0,
        'foo.c:3': 1.0
    })

    lines_expected = \
        {l('foo.c:1'), l('foo.c:2'), l('foo.c:3')}
    lines_actual = set(loc)

    assert lines_expected == lines_actual
Пример #6
0
def test_to_and_from_dict():
    loc = Localization({
        l('foo.c:1'): 1.0,
        l('foo.c:2'): 0.1,
        l('foo.c:3'): 0.5,
        l('bar.c:9'): 0.1
    })

    dict_expected = {
        'foo.c:1': 1.0,
        'foo.c:2': 0.1,
        'foo.c:3': 0.5,
        'bar.c:9': 0.1
    }

    assert loc.to_dict() == dict_expected
    assert Localization.from_dict(dict_expected) == loc
Пример #7
0
def test_exclude_files():
    loc = Localization.from_dict({
        'foo.c:1': 1.0,
        'foo.c:2': 1.0,
        'foo.c:3': 1.0,
        'bar.c:1': 1.0,
        'bar.c:2': 1.0,
        'woo.c:1': 1.0
    })

    assert len(loc.exclude_files([])) == 6
    assert len(loc.exclude_files(['buzz.c'])) == 6
    assert len(loc.exclude_files(['foo.c'])) == 3
    assert len(loc.exclude_files(['bar.c'])) == 4
    assert len(loc.exclude_files(['woo.c'])) == 5
    assert len(loc.exclude_files(['bar.c', 'woo.c'])) == 3
    assert len(loc.exclude_files(['bar.c', 'foo.c'])) == 1
Пример #8
0
def test_restrict_to_lines():
    loc = Localization.from_dict({
        'foo.c:1': 1.0,
        'foo.c:2': 0.5,
        'foo.c:3': 0.1
    })

    restricted_to = {l('foo.c:1'), l('foo.c:2')}
    assert set(loc.restrict_to_lines(restricted_to)) == restricted_to

    restricted_to = {l('foo.c:1'), l('foo.c:2'), l('bar.c:7')}
    assert set(loc.restrict_to_lines(restricted_to)) == {
            l('foo.c:1'), l('foo.c:2')}

    restricted_to = {l('foo.c:1')}
    assert set(loc.restrict_to_lines(restricted_to)) == restricted_to

    with pytest.raises(darjeeling.exceptions.NoImplicatedLines):
        loc.restrict_to_lines({})