예제 #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
 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
 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
 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
 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
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()