コード例 #1
0
def test_get_state_returns_excluded_by_default_for_hidden_directories(tmpdir):
    d = Directories()
    p = Path(str(tmpdir))
    hidden_dir_path = p + '.foo'
    io.mkdir(p + '.foo')
    d.add_path(p)
    eq_(d.get_state(hidden_dir_path), DirectoryState.Excluded)
    # But it can be overriden
    d.set_state(hidden_dir_path, DirectoryState.Normal)
    eq_(d.get_state(hidden_dir_path), DirectoryState.Normal)
コード例 #2
0
def test_get_state_returns_excluded_by_default_for_hidden_directories(tmpdir):
    d = Directories()
    p = Path(str(tmpdir))
    hidden_dir_path = p + '.foo'
    io.mkdir(p + '.foo')
    d.add_path(p)
    eq_(d.get_state(hidden_dir_path), DirectoryState.Excluded)
    # But it can be overriden
    d.set_state(hidden_dir_path, DirectoryState.Normal)
    eq_(d.get_state(hidden_dir_path), DirectoryState.Normal)
コード例 #3
0
def setup_module(module):
    # In this unit, we have tests depending on two directory structure. One with only one file in it
    # and another with a more complex structure.
    testpath = Path(tempfile.mkdtemp())
    module.testpath = testpath
    rootpath = testpath + 'onefile'
    io.mkdir(rootpath)
    fp = io.open(rootpath + 'test.txt', 'w')
    fp.write('test_data')
    fp.close()
    create_fake_fs(testpath)
コード例 #4
0
def setup_module(module):
    # In this unit, we have tests depending on two directory structure. One with only one file in it
    # and another with a more complex structure.
    testpath = Path(tempfile.mkdtemp())
    module.testpath = testpath
    rootpath = testpath + 'onefile'
    io.mkdir(rootpath)
    fp = io.open(rootpath + 'test.txt', 'w')
    fp.write('test_data')
    fp.close()
    create_fake_fs(testpath)
コード例 #5
0
def test_unicode_save(tmpdir):
    d = Directories()
    p1 = Path(str(tmpdir)) + 'hello\xe9'
    io.mkdir(p1)
    io.mkdir(p1 + 'foo\xe9')
    d.add_path(p1)
    d.set_state(p1 + 'foo\xe9', DirectoryState.Excluded)
    tmpxml = str(tmpdir.join('directories_testunit.xml'))
    try:
        d.save_to_file(tmpxml)
    except UnicodeDecodeError:
        assert False
コード例 #6
0
def test_unicode_save(tmpdir):
    d = Directories()
    p1 = Path(str(tmpdir)) + 'hello\xe9'
    io.mkdir(p1)
    io.mkdir(p1 + 'foo\xe9')
    d.add_path(p1)
    d.set_state(p1 + 'foo\xe9', DirectoryState.Excluded)
    tmpxml = str(tmpdir.join('directories_testunit.xml'))
    try:
        d.save_to_file(tmpxml)
    except UnicodeDecodeError:
        assert False
コード例 #7
0
 def test_copy_or_move_clean_empty_dirs(self, tmpdir, monkeypatch):
     tmppath = Path(str(tmpdir))
     sourcepath = tmppath + 'source'
     io.mkdir(sourcepath)
     io.open(sourcepath + 'myfile', 'w')
     app = TestApp().app
     app.directories.add_path(tmppath)
     [myfile] = app.directories.get_files()
     monkeypatch.setattr(app, 'clean_empty_dirs', log_calls(lambda path: None))
     app.copy_or_move(myfile, False, tmppath + 'dest', 0)
     calls = app.clean_empty_dirs.calls
     eq_(1, len(calls))
     eq_(sourcepath, calls[0]['path'])
コード例 #8
0
ファイル: phys_test.py プロジェクト: hsoft/musicguru
 def test_handle_subdir_deletion_gracefully(self, tmpdir):
     tmppath = Path(str(tmpdir))
     io.mkdir(tmppath + 'sub')
     io.mkdir(tmppath + 'sub/dir')
     root = phys.Directory(None, str(tmppath))
     root.dirs[0].dirs
     io.rmdir(tmppath + 'sub/dir')
     io.rmdir(tmppath + 'sub')
     root.force_update()
     try:
         root.dirs
     except fs.InvalidPath:
         self.fail()
コード例 #9
0
 def test_handle_subdir_deletion_gracefully(self, tmpdir):
     tmppath = Path(str(tmpdir))
     io.mkdir(tmppath + 'sub')
     io.mkdir(tmppath + 'sub/dir')
     root = phys.Directory(None, str(tmppath))
     root.dirs[0].dirs
     io.rmdir(tmppath + 'sub/dir')
     io.rmdir(tmppath + 'sub')
     root.force_update()
     try:
         root.dirs
     except fs.InvalidPath:
         self.fail()
コード例 #10
0
ファイル: app_test.py プロジェクト: pombredanne/dupeguru
 def test_copy_or_move_clean_empty_dirs(self, tmpdir, monkeypatch):
     tmppath = Path(str(tmpdir))
     sourcepath = tmppath + 'source'
     io.mkdir(sourcepath)
     io.open(sourcepath + 'myfile', 'w')
     app = TestApp().app
     app.directories.add_path(tmppath)
     [myfile] = app.directories.get_files()
     monkeypatch.setattr(app, 'clean_empty_dirs', log_calls(lambda path: None))
     app.copy_or_move(myfile, False, tmppath + 'dest', 0)
     calls = app.clean_empty_dirs.calls
     eq_(1, len(calls))
     eq_(sourcepath, calls[0]['path'])
コード例 #11
0
ファイル: app_test.py プロジェクト: pombredanne/dupeguru
 def pytest_funcarg__do_setup(self, request):
     app = TestApp()
     self.app = app.app
     self.objects,self.matches,self.groups = GetTestGroups()
     self.app.results.groups = self.groups
     self.dpanel = app.dpanel
     self.dtree = app.dtree
     self.rtable = app.rtable
     self.rtable.refresh()
     tmpdir = request.getfuncargvalue('tmpdir')
     tmppath = Path(str(tmpdir))
     io.mkdir(tmppath + 'foo')
     io.mkdir(tmppath + 'bar')
     self.app.directories.add_path(tmppath)
コード例 #12
0
 def pytest_funcarg__do_setup(self, request):
     app = TestApp()
     self.app = app.app
     self.objects,self.matches,self.groups = GetTestGroups()
     self.app.results.groups = self.groups
     self.dpanel = app.dpanel
     self.dtree = app.dtree
     self.rtable = app.rtable
     self.rtable.refresh()
     tmpdir = request.getfuncargvalue('tmpdir')
     tmppath = Path(str(tmpdir))
     io.mkdir(tmppath + 'foo')
     io.mkdir(tmppath + 'bar')
     self.app.directories.add_path(tmppath)
コード例 #13
0
def create_fake_fs(rootpath):
    # We have it as a separate function because other units are using it.
    rootpath = rootpath + 'fs'
    io.mkdir(rootpath)
    io.mkdir(rootpath + 'dir1')
    io.mkdir(rootpath + 'dir2')
    io.mkdir(rootpath + 'dir3')
    fp = io.open(rootpath + 'file1.test', 'w')
    fp.write('1')
    fp.close()
    fp = io.open(rootpath + 'file2.test', 'w')
    fp.write('12')
    fp.close()
    fp = io.open(rootpath + 'file3.test', 'w')
    fp.write('123')
    fp.close()
    fp = io.open(rootpath + ('dir1', 'file1.test'), 'w')
    fp.write('1')
    fp.close()
    fp = io.open(rootpath + ('dir2', 'file2.test'), 'w')
    fp.write('12')
    fp.close()
    fp = io.open(rootpath + ('dir3', 'file3.test'), 'w')
    fp.write('123')
    fp.close()
    return rootpath
コード例 #14
0
def create_fake_fs(rootpath):
    # We have it as a separate function because other units are using it.
    rootpath = rootpath + 'fs'
    io.mkdir(rootpath)
    io.mkdir(rootpath + 'dir1')
    io.mkdir(rootpath + 'dir2')
    io.mkdir(rootpath + 'dir3')
    fp = io.open(rootpath + 'file1.test', 'w')
    fp.write('1')
    fp.close()
    fp = io.open(rootpath + 'file2.test', 'w')
    fp.write('12')
    fp.close()
    fp = io.open(rootpath + 'file3.test', 'w')
    fp.write('123')
    fp.close()
    fp = io.open(rootpath + ('dir1', 'file1.test'), 'w')
    fp.write('1')
    fp.close()
    fp = io.open(rootpath + ('dir2', 'file2.test'), 'w')
    fp.write('12')
    fp.close()
    fp = io.open(rootpath + ('dir3', 'file3.test'), 'w')
    fp.write('123')
    fp.close()
    return rootpath
コード例 #15
0
def test_load_from_file_with_invalid_path(tmpdir):
    #This test simulates a load from file resulting in a
    #InvalidPath raise. Other directories must be loaded.
    d1 = Directories()
    d1.add_path(testpath + 'onefile')
    #Will raise InvalidPath upon loading
    p = Path(str(tmpdir.join('toremove')))
    io.mkdir(p)
    d1.add_path(p)
    io.rmdir(p)
    tmpxml = str(tmpdir.join('directories_testunit.xml'))
    d1.save_to_file(tmpxml)
    d2 = Directories()
    d2.load_from_file(tmpxml)
    eq_(1, len(d2))
コード例 #16
0
def test_load_from_file_with_invalid_path(tmpdir):
    #This test simulates a load from file resulting in a
    #InvalidPath raise. Other directories must be loaded.
    d1 = Directories()
    d1.add_path(testpath + 'onefile')
    #Will raise InvalidPath upon loading
    p = Path(str(tmpdir.join('toremove')))
    io.mkdir(p)
    d1.add_path(p)
    io.rmdir(p)
    tmpxml = str(tmpdir.join('directories_testunit.xml'))
    d1.save_to_file(tmpxml)
    d2 = Directories()
    d2.load_from_file(tmpxml)
    eq_(1, len(d2))
コード例 #17
0
def test_save_and_load(tmpdir):
    d1 = Directories()
    d2 = Directories()
    p1 = Path(str(tmpdir.join('p1')))
    io.mkdir(p1)
    p2 = Path(str(tmpdir.join('p2')))
    io.mkdir(p2)
    d1.add_path(p1)
    d1.add_path(p2)
    d1.set_state(p1, DirectoryState.Reference)
    d1.set_state(p1 + 'dir1', DirectoryState.Excluded)
    tmpxml = str(tmpdir.join('directories_testunit.xml'))
    d1.save_to_file(tmpxml)
    d2.load_from_file(tmpxml)
    eq_(2, len(d2))
    eq_(DirectoryState.Reference, d2.get_state(p1))
    eq_(DirectoryState.Excluded, d2.get_state(p1 + 'dir1'))
コード例 #18
0
def test_save_and_load(tmpdir):
    d1 = Directories()
    d2 = Directories()
    p1 = Path(str(tmpdir.join('p1')))
    io.mkdir(p1)
    p2 = Path(str(tmpdir.join('p2')))
    io.mkdir(p2)
    d1.add_path(p1)
    d1.add_path(p2)
    d1.set_state(p1, DirectoryState.Reference)
    d1.set_state(p1 + 'dir1', DirectoryState.Excluded)
    tmpxml = str(tmpdir.join('directories_testunit.xml'))
    d1.save_to_file(tmpxml)
    d2.load_from_file(tmpxml)
    eq_(2, len(d2))
    eq_(DirectoryState.Reference ,d2.get_state(p1))
    eq_(DirectoryState.Excluded ,d2.get_state(p1 + 'dir1'))
コード例 #19
0
def test_default_path_state_override(tmpdir):
    # It's possible for a subclass to override the default state of a path
    class MyDirectories(Directories):
        def _default_state_for_path(self, path):
            if 'foobar' in path:
                return DirectoryState.Excluded
    
    d = MyDirectories()
    p1 = Path(str(tmpdir))
    io.mkdir(p1 + 'foobar')
    io.open(p1 + 'foobar/somefile', 'w').close()
    io.mkdir(p1 + 'foobaz')
    io.open(p1 + 'foobaz/somefile', 'w').close()
    d.add_path(p1)
    eq_(d.get_state(p1 + 'foobaz'), DirectoryState.Normal)
    eq_(d.get_state(p1 + 'foobar'), DirectoryState.Excluded)
    eq_(len(list(d.get_files())), 1) # only the 'foobaz' file is there
    # However, the default state can be changed
    d.set_state(p1 + 'foobar', DirectoryState.Normal)
    eq_(d.get_state(p1 + 'foobar'), DirectoryState.Normal)
    eq_(len(list(d.get_files())), 2)
コード例 #20
0
def test_default_path_state_override(tmpdir):
    # It's possible for a subclass to override the default state of a path
    class MyDirectories(Directories):
        def _default_state_for_path(self, path):
            if 'foobar' in path:
                return DirectoryState.Excluded

    d = MyDirectories()
    p1 = Path(str(tmpdir))
    io.mkdir(p1 + 'foobar')
    io.open(p1 + 'foobar/somefile', 'w').close()
    io.mkdir(p1 + 'foobaz')
    io.open(p1 + 'foobaz/somefile', 'w').close()
    d.add_path(p1)
    eq_(d.get_state(p1 + 'foobaz'), DirectoryState.Normal)
    eq_(d.get_state(p1 + 'foobar'), DirectoryState.Excluded)
    eq_(len(list(d.get_files())), 1)  # only the 'foobaz' file is there
    # However, the default state can be changed
    d.set_state(p1 + 'foobar', DirectoryState.Normal)
    eq_(d.get_state(p1 + 'foobar'), DirectoryState.Normal)
    eq_(len(list(d.get_files())), 2)
コード例 #21
0
 def pytest_funcarg__do_setup(self, request):
     tmpdir = request.getfuncargvalue('tmpdir')
     p = Path(str(tmpdir))
     io.mkdir(p + 'sub1')
     io.mkdir(p + 'sub2')
     io.mkdir(p + 'sub3')
     app = TestApp()
     self.app = app.app
     self.dtree = app.dtree
     self.dtree.add_directory(p)
     self.dtree.view.clear_calls()
コード例 #22
0
ファイル: app_test.py プロジェクト: pombredanne/dupeguru
 def pytest_funcarg__do_setup(self, request):
     tmpdir = request.getfuncargvalue('tmpdir')
     p = Path(str(tmpdir))
     io.mkdir(p + 'sub1')
     io.mkdir(p + 'sub2')
     io.mkdir(p + 'sub3')
     app = TestApp()
     self.app = app.app
     self.dtree = app.dtree
     self.dtree.add_directory(p)
     self.dtree.view.clear_calls()
コード例 #23
0
ファイル: phys_test.py プロジェクト: hsoft/musicguru
def create_unicode_test_dir(rootpath):
    io.mkdir(rootpath + '\xe9_dir')
    io.open(rootpath + '\xe9_file', 'w').close()
    io.open(rootpath + ('\xe9_dir', '\xe9_file'), 'w').close()
コード例 #24
0
def create_unicode_test_dir(rootpath):
    io.mkdir(rootpath + '\xe9_dir')
    io.open(rootpath + '\xe9_file', 'w').close()
    io.open(rootpath + ('\xe9_dir', '\xe9_file'), 'w').close()