Ejemplo n.º 1
0
def test_file_scan(fs):
    datadir = path.sep + 'data'
    fs.create_dir(datadir)
    files = []
    for d, p, o in itertools.product(dates, params, options):
        filename = '{}{}test_{}_{:.1f}{}.ext'.format(d.year, path.sep,
                                                     d.strftime('%F'), p,
                                                     '_yes' if o else '')
        files.append(filename)
        fs.create_file(path.join(datadir, filename))
    files.sort()

    finder = Finder(
        datadir, ('%(Y){}test_%(Y)-%(m)-%(d)_'
                  '%(param:fmt=.1f)%(option:opt=:_yes).ext').format(path.sep))
    assert len(finder.files) == len(files)
    for f, f_ref in zip(finder.get_files(relative=True), files):
        assert f == f_ref
Ejemplo n.º 2
0
def test_get_matchers():
    def assert_get_matchers(finder, key, indices):
        assert indices == [m.idx for m in finder.get_matchers(key)]

    finder = Finder('', 'test_%(time:m)_%(c:fmt=.1f)_%(time:d)_%(d)')
    assert_get_matchers(finder, 'm', [0])
    assert_get_matchers(finder, 'c', [1])
    assert_get_matchers(finder, 'd', [2, 3])
    assert_get_matchers(finder, 'time:d', [2])
Ejemplo n.º 3
0
def test_get_filename():
    root = path.join('data', 'root')
    filename_rel = 'test_01_5.00_yes'
    filename_abs = path.join(root, filename_rel)
    finder = Finder(root, 'test_%(m)_%(c:fmt=.2f)_%(b:opt=:yes)')

    # Without fix
    assert finder.get_filename(m=1, c=5, b=True) == filename_abs
    # With dictionnary
    assert finder.get_filename(dict(m=1, c=5, b=True)) == filename_abs
    # With mix
    assert finder.get_filename(dict(m=1, c=5), b=True) == filename_abs
    # Relative file
    assert finder.get_filename(relative=True, m=1, c=5, b=True) == filename_rel

    # With fix
    finder.fix_matchers(m=1)
    assert finder.get_filename(c=5, b=True) == filename_abs
    assert finder.get_filename(dict(c=5), b=True) == filename_abs
Ejemplo n.º 4
0
def test_fix_matcher_value():
    finder = Finder('', 'test_%(m)_%(c:fmt=.1f)_%(b:opt=A:B)')
    finder.fix_matcher(0, 1)
    finder.fix_matcher(1, 11)
    finder.fix_matcher(2, True)
    assert finder.regex == r'test_(01)_(11\.0)_(B)'
Ejemplo n.º 5
0
def test_fix_matcher_string():
    finder = Finder('', 'test_%(m)_%(c:fmt=.1f)')
    finder.fix_matcher(0, '01')
    finder.fix_matcher(1, r'11\.1')
    assert finder.regex == r'test_(01)_(11\.1)'
Ejemplo n.º 6
0
 def assert_group_name(pregex, names):
     finder = Finder('', pregex)
     for m, (group, name) in zip(finder.matchers, names):
         assert (m.group == group)
         assert (m.name == name)
Ejemplo n.º 7
0
def test_multiple_matchers():
    finder = Finder('', 'test_%(m)_%(d)')
    assert finder.n_matchers == 2
    assert finder.matchers[0].name == 'm'
    assert finder.matchers[1].name == 'd'
Ejemplo n.º 8
0
def assert_pregex(pregex, regex):
    finder = Finder('', pregex)
    assert finder.regex == regex