예제 #1
0
def test_change_property(name, value, pattern, item):
    '''Change property.'''
    collection = Collection('head.', '.tail', 0, indexes=set([1]))

    setattr(collection, name, value)
    assert getattr(collection, name) == value

    assert collection._expression.pattern == pattern
    assert list(collection)[0] == item
예제 #2
0
def test_repr():
    '''Repr representation.'''
    collection = Collection('head.', '.tail', 0, indexes=set([1, 2, 3]))
    assert repr(collection) == '<Collection "head.%d.tail [1-3]">'
예제 #3
0
def test_str():
    '''String representation.'''
    collection = Collection('head.', '.tail', 0, indexes=set([1, 2, 3]))
    assert str(collection) == 'head.%d.tail [1-3]'
예제 #4
0
def test_unsettable_indexes():
    '''Set new indexes by attribute assignment.'''
    collection = Collection('head.', '.tail', 0, indexes=set([1]))
    with pytest.raises(AttributeError):
        collection.indexes = [1, 3]
예제 #5
0
def test_escaping_expression():
    '''Escape non-regular expression components.'''
    collection = Collection('prefix\\file.', '.ext', 1, [1])
    assert 'prefix\\file.1.ext' in collection
예제 #6
0
def PaddedCollection(**kw):
    '''Return a padded collection.'''
    return Collection('/head.', '.ext', padding=4, **kw)
예제 #7
0
def UnpaddedCollection(**kw):
    '''Return an unpadded collection.'''
    return Collection('/head.', '.ext', padding=0, **kw)
예제 #8
0
@pytest.mark.parametrize(('item', 'expected'), [('/head.0001.ext', True),
                                                ('/diff_head.0001.ext', False),
                                                ('/head.0001.diff_ext', False),
                                                ('/head.1000.ext', False)],
                         ids=[
                             'valid member', 'different head',
                             'different tail', 'non-member index'
                         ])
def test_contains(item, expected):
    '''Collection contains item.'''
    collection = PaddedCollection(indexes=set([1]))
    assert (item in collection) == expected


@pytest.mark.parametrize(('collection_a', 'collection_b', 'expected'), [
    (Collection('head', 'tail', 0), Collection('head', 'tail', 0), 0),
    (Collection('head', 'tail', 0), Collection('diff_head', 'tail', 0), -1),
    (Collection('head', 'tail', 0), Collection('head', 'diff_tail', 0), -1),
    (Collection('head', 'tail', 0), Collection('head', 'tail', 4), 1),
    (Collection('head', 'tail', 0, indexes=set(
        [1, 2])), Collection('head', 'tail', 0, indexes=set([1])), -1),
],
                         ids=[
                             'equal', 'different head (b > a)',
                             'different tail (b > a)',
                             'different padding (a > b)',
                             'different indexes (b > a)'
                         ])
def test_comparisons(collection_a, collection_b, expected):
    '''Compare collections.'''
    equal = (expected == 0)