|  | @@ -0,0 +1,97 @@
 | 
	
		
			
				|  |  | +# coding=utf-8
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import pytest
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import osex
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import os
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +def test_local_db_files(tmpdir):
 | 
	
		
			
				|  |  | +    test_dir_path = tmpdir.strpath
 | 
	
		
			
				|  |  | +    os.chdir(test_dir_path)
 | 
	
		
			
				|  |  | +    # prepare dir
 | 
	
		
			
				|  |  | +    open('file1', 'w').close()
 | 
	
		
			
				|  |  | +    open('file2', 'w').close()
 | 
	
		
			
				|  |  | +    os.makedirs(os.path.join('dir', 'subdir1'))
 | 
	
		
			
				|  |  | +    os.makedirs(os.path.join('dir', 'subdir2'))
 | 
	
		
			
				|  |  | +    # update db
 | 
	
		
			
				|  |  | +    database_path = os.path.join(test_dir_path, 'db')
 | 
	
		
			
				|  |  | +    osex.update_locate_database(database_path = database_path, root_path = test_dir_path, require_visibility = False)
 | 
	
		
			
				|  |  | +    # locate
 | 
	
		
			
				|  |  | +    results = osex.locate(
 | 
	
		
			
				|  |  | +        [test_dir_path + '*file*'],
 | 
	
		
			
				|  |  | +        database_path = database_path
 | 
	
		
			
				|  |  | +        )
 | 
	
		
			
				|  |  | +    assert results == [os.path.join(test_dir_path, p) for p in [
 | 
	
		
			
				|  |  | +        'file1',
 | 
	
		
			
				|  |  | +        'file2',
 | 
	
		
			
				|  |  | +        ]]
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +def test_local_db_files_unicode(tmpdir):
 | 
	
		
			
				|  |  | +    test_dir_path = tmpdir.strpath
 | 
	
		
			
				|  |  | +    os.chdir(test_dir_path)
 | 
	
		
			
				|  |  | +    # prepare dir
 | 
	
		
			
				|  |  | +    open(u'file-ä', 'w').close()
 | 
	
		
			
				|  |  | +    open(u'file-Ö', 'w').close()
 | 
	
		
			
				|  |  | +    open(u'file-ß', 'w').close()
 | 
	
		
			
				|  |  | +    # update db
 | 
	
		
			
				|  |  | +    database_path = os.path.join(test_dir_path, 'db')
 | 
	
		
			
				|  |  | +    osex.update_locate_database(database_path = database_path, root_path = test_dir_path, require_visibility = False)
 | 
	
		
			
				|  |  | +    # locate
 | 
	
		
			
				|  |  | +    results = osex.locate(
 | 
	
		
			
				|  |  | +        [test_dir_path + '*file*'],
 | 
	
		
			
				|  |  | +        database_path = database_path
 | 
	
		
			
				|  |  | +        )
 | 
	
		
			
				|  |  | +    expected_results = [os.path.join(test_dir_path, p) for p in [
 | 
	
		
			
				|  |  | +        u'file-ä',
 | 
	
		
			
				|  |  | +        u'file-Ö',
 | 
	
		
			
				|  |  | +        u'file-ß',
 | 
	
		
			
				|  |  | +        ]]
 | 
	
		
			
				|  |  | +    assert results.sort() == expected_results.sort()
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +def test_local_db_dirs(tmpdir):
 | 
	
		
			
				|  |  | +    test_dir_path = tmpdir.strpath
 | 
	
		
			
				|  |  | +    os.chdir(test_dir_path)
 | 
	
		
			
				|  |  | +    # prepare dir
 | 
	
		
			
				|  |  | +    open('file1', 'w').close()
 | 
	
		
			
				|  |  | +    open('file2', 'w').close()
 | 
	
		
			
				|  |  | +    os.makedirs(os.path.join('dir', 'subdir1'))
 | 
	
		
			
				|  |  | +    os.makedirs(os.path.join('dir', 'subdir2'))
 | 
	
		
			
				|  |  | +    # update db
 | 
	
		
			
				|  |  | +    database_path = os.path.join(test_dir_path, 'db')
 | 
	
		
			
				|  |  | +    osex.update_locate_database(database_path = database_path, root_path = test_dir_path, require_visibility = False)
 | 
	
		
			
				|  |  | +    # locate
 | 
	
		
			
				|  |  | +    results = osex.locate(
 | 
	
		
			
				|  |  | +        [test_dir_path + '*dir*'],
 | 
	
		
			
				|  |  | +        database_path = database_path
 | 
	
		
			
				|  |  | +        )
 | 
	
		
			
				|  |  | +    assert results == [os.path.join(test_dir_path, p) for p in [
 | 
	
		
			
				|  |  | +        'dir',
 | 
	
		
			
				|  |  | +        os.path.join('dir', 'subdir1'),
 | 
	
		
			
				|  |  | +        os.path.join('dir', 'subdir2'),
 | 
	
		
			
				|  |  | +        ]]
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +def test_local_db_subtree(tmpdir):
 | 
	
		
			
				|  |  | +    test_dir_path = tmpdir.strpath
 | 
	
		
			
				|  |  | +    os.chdir(test_dir_path)
 | 
	
		
			
				|  |  | +    # prepare dir
 | 
	
		
			
				|  |  | +    os.makedirs(os.path.join('dir1', 'subdir1'))
 | 
	
		
			
				|  |  | +    os.makedirs(os.path.join('dir1', 'subdir2'))
 | 
	
		
			
				|  |  | +    os.makedirs(os.path.join('dir2', 'subdir3'))
 | 
	
		
			
				|  |  | +    os.makedirs(os.path.join('dir2', 'subdir4'))
 | 
	
		
			
				|  |  | +    # update db
 | 
	
		
			
				|  |  | +    database_path = os.path.join(test_dir_path, 'db')
 | 
	
		
			
				|  |  | +    osex.update_locate_database(
 | 
	
		
			
				|  |  | +            database_path = database_path,
 | 
	
		
			
				|  |  | +            root_path = os.path.join(test_dir_path, 'dir2'),
 | 
	
		
			
				|  |  | +            require_visibility = False
 | 
	
		
			
				|  |  | +            )
 | 
	
		
			
				|  |  | +    # locate
 | 
	
		
			
				|  |  | +    results = osex.locate(
 | 
	
		
			
				|  |  | +        [test_dir_path + '*subdir*'],
 | 
	
		
			
				|  |  | +        database_path = database_path
 | 
	
		
			
				|  |  | +        )
 | 
	
		
			
				|  |  | +    assert results == [os.path.join(test_dir_path, p) for p in [
 | 
	
		
			
				|  |  | +        os.path.join('dir2', 'subdir3'),
 | 
	
		
			
				|  |  | +        os.path.join('dir2', 'subdir4'),
 | 
	
		
			
				|  |  | +        ]]
 |