Beispiel #1
0
 def test_read(self):
     fs = Filesystem(MockBackend())
     assert fs.read(None)
     assert fs[None]
Beispiel #2
0
 def test_read(self):
     fs = Filesystem(MockBackend())
     assert fs.read(None)
     assert fs[None]
Beispiel #3
0
 def setup(self):
     self.fs = Filesystem(
         backends.S3(
             aws_access_key=os.environ['AWS_ACCESS_KEY_ID'],
             aws_secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY'],
             bucket='watson-filesystem'), )
class TestLocal(object):
    def setup(self):
        self.fs = Filesystem(backends.Local())
        self.output_path = os.path.join(
            os.path.dirname(
                os.path.dirname(os.path.dirname(os.path.dirname(__file__)))),
            '_output')

    def file(self, path):
        return os.path.join(self.output_path, path)

    def test_factory(self):
        fs = backends.Local.factory()
        assert isinstance(fs, Filesystem)
        assert isinstance(fs.backend, backends.Local)

    def test_read(self):
        content = self.fs.read(__file__)
        assert content.startswith(b'# -*- coding:')

    def test_read_not_found(self):
        with raises(exceptions.NotFoundError):
            self.fs.read('../support.py')

    def test_exists(self):
        assert self.fs.exists(__file__)
        assert not self.fs.exists('../support.py')
        assert __file__ in self.fs

    def test_write(self):
        path = self.file('test')
        self.fs.write(path, 'test')
        assert self.fs.exists(path)
        assert self.fs.read(path) == b'test'
        non_existent_path = self.file('testing/test')
        self.fs.write(non_existent_path, 'test')
        assert self.fs.exists(non_existent_path)
        self.fs.delete(non_existent_path)

    def test_append(self):
        path = self.file('test')
        self.fs.append(path, 'test')
        assert self.fs.read(path) == b'testtest'

    def test_create_delete(self):
        path = self.file('test-delete')
        self.fs.delete(path)
        assert not self.fs.exists(path)
        self.fs.create(path)
        assert self.fs.exists(path)
        self.fs.delete(path)
        assert not self.fs.exists(path)
        path = self.file('test-delete-folder')
        self.fs.create(path, is_dir=True)
        self.fs.delete(path)

    def test_delete_recursive(self):
        path = self.file('testing/sub/folder')
        self.fs.create(path, is_dir=True)
        assert self.fs.exists(path)
        self.fs.delete(self.file('testing'))
        assert not self.fs.exists(path)

    def test_move(self):
        path = self.file('testing')
        new_path = self.file('testing_new')
        self.fs.create(path)
        self.fs.move(path, new_path)
        assert not self.fs.exists(path)
        assert self.fs.exists(new_path)
        self.fs.delete(new_path)

    def test_copy(self):
        path = self.file('testing')
        new_path = self.file('testing_new')
        self.fs.create(path)
        self.fs.copy(path, new_path)
        assert self.fs.exists(path)
        assert self.fs.exists(new_path)
        self.fs.delete(path)
        self.fs.delete(new_path)
        dir_path = self.file('testing/sub/directory')
        new_dir_path = self.file('testing2')
        self.fs.create(dir_path, is_dir=True)
        self.fs.copy(dir_path, new_dir_path)
        assert self.fs.exists(new_dir_path)
        self.fs.delete(dir_path)
        self.fs.delete(new_dir_path)
Beispiel #5
0
 def test_move(self):
     fs = Filesystem(MockBackend())
     assert fs.move(None, None)
Beispiel #6
0
 def test_create(self):
     fs = Filesystem(MockBackend())
     assert fs.create(None)
     assert fs.create(None, is_dir=True)
Beispiel #7
0
 def test_copy(self):
     fs = Filesystem(MockBackend())
     assert fs.copy(None, None)
Beispiel #8
0
 def test_append(self):
     fs = Filesystem(MockBackend())
     assert fs.append(None, None)
Beispiel #9
0
 def test_delete(self):
     fs = Filesystem(MockBackend())
     assert fs.delete(None)
Beispiel #10
0
 def test_move(self):
     fs = Filesystem(MockBackend())
     assert fs.move(None, None)
Beispiel #11
0
 def test_append(self):
     fs = Filesystem(MockBackend())
     assert fs.append(None, None)
Beispiel #12
0
 def test_write(self):
     fs = Filesystem(MockBackend())
     assert fs.write(None, None)
     fs['test'] = 'test'
Beispiel #13
0
 def test_exists(self):
     fs = Filesystem(MockBackend())
     assert fs.exists(None)
     assert None in fs
Beispiel #14
0
 def test_exists(self):
     fs = Filesystem(MockBackend())
     assert fs.exists(None)
     assert None in fs
Beispiel #15
0
 def test_create(self):
     fs = Filesystem(MockBackend())
     assert fs.create(None)
     assert fs.create(None, is_dir=True)
Beispiel #16
0
 def test_write(self):
     fs = Filesystem(MockBackend())
     assert fs.write(None, None)
     fs['test'] = 'test'
class TestLocal(object):

    def setup(self):
        self.fs = Filesystem(backends.Local())
        self.output_path = os.path.join(
            os.path.dirname(
                os.path.dirname(
                    os.path.dirname(os.path.dirname(__file__)))), '_output')

    def file(self, path):
        return os.path.join(self.output_path, path)

    def test_factory(self):
        fs = backends.Local.factory()
        assert isinstance(fs, Filesystem)
        assert isinstance(fs.backend, backends.Local)

    def test_read(self):
        content = self.fs.read(__file__)
        assert content.startswith(b'# -*- coding:')

    def test_read_not_found(self):
        with raises(exceptions.NotFoundError):
            self.fs.read('../support.py')

    def test_exists(self):
        assert self.fs.exists(__file__)
        assert not self.fs.exists('../support.py')
        assert __file__ in self.fs

    def test_write(self):
        path = self.file('test')
        self.fs.write(path, 'test')
        assert self.fs.exists(path)
        assert self.fs.read(path) == b'test'
        non_existent_path = self.file('testing/test')
        self.fs.write(non_existent_path, 'test')
        assert self.fs.exists(non_existent_path)
        self.fs.delete(non_existent_path)

    def test_append(self):
        path = self.file('test')
        self.fs.append(path, 'test')
        assert self.fs.read(path) == b'testtest'

    def test_create_delete(self):
        path = self.file('test-delete')
        self.fs.delete(path)
        assert not self.fs.exists(path)
        self.fs.create(path)
        assert self.fs.exists(path)
        self.fs.delete(path)
        assert not self.fs.exists(path)
        path = self.file('test-delete-folder')
        self.fs.create(path, is_dir=True)
        self.fs.delete(path)

    def test_delete_recursive(self):
        path = self.file('testing/sub/folder')
        self.fs.create(path, is_dir=True)
        assert self.fs.exists(path)
        self.fs.delete(self.file('testing'))
        assert not self.fs.exists(path)

    def test_move(self):
        path = self.file('testing')
        new_path = self.file('testing_new')
        self.fs.create(path)
        self.fs.move(path, new_path)
        assert not self.fs.exists(path)
        assert self.fs.exists(new_path)
        self.fs.delete(new_path)

    def test_copy(self):
        path = self.file('testing')
        new_path = self.file('testing_new')
        self.fs.create(path)
        self.fs.copy(path, new_path)
        assert self.fs.exists(path)
        assert self.fs.exists(new_path)
        self.fs.delete(path)
        self.fs.delete(new_path)
        dir_path = self.file('testing/sub/directory')
        new_dir_path = self.file('testing2')
        self.fs.create(dir_path, is_dir=True)
        self.fs.copy(dir_path, new_dir_path)
        assert self.fs.exists(new_dir_path)
        self.fs.delete(dir_path)
        self.fs.delete(new_dir_path)
Beispiel #18
0
 def test_delete(self):
     fs = Filesystem(MockBackend())
     assert fs.delete(None)
 def setup(self):
     self.fs = Filesystem(backends.Local())
     self.output_path = os.path.join(
         os.path.dirname(
             os.path.dirname(
                 os.path.dirname(os.path.dirname(__file__)))), '_output')
Beispiel #20
0
 def test_copy(self):
     fs = Filesystem(MockBackend())
     assert fs.copy(None, None)
Beispiel #21
0
 def setup(self):
     self.fs = Filesystem(backends.S3(
         aws_access_key=os.environ['AWS_ACCESS_KEY_ID'],
         aws_secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY'],
         bucket='watson-filesystem'),
     )
Beispiel #22
0
 def test_no_backend(self):
     with raises(TypeError):
         Filesystem()
Beispiel #23
0
class TestS3(object):

    def setup(self):
        self.fs = Filesystem(backends.S3(
            aws_access_key=os.environ['AWS_ACCESS_KEY_ID'],
            aws_secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY'],
            bucket='watson-filesystem'),
        )

    def test_write(self):
        self.fs.write('test.txt', 'this is a test')
        assert self.fs.exists('test.txt')

    def test_read(self):
        self.fs.write('test.txt', 'test')
        content = self.fs.read('test.txt')
        assert content == b'test'

    def test_read_not_found(self):
        with raises(exceptions.NotFoundError):
            self.fs.read('not-found')

    def test_append(self):
        self.fs.write('test.txt', 'testing')
        assert self.fs.read('test.txt')
        self.fs.append('test.txt', b' with new test copy')
        assert self.fs.read('test.txt') == b'testing with new test copy'

    def test_create_delete(self):
        self.fs.create('blah.txt')
        assert self.fs.exists('blah.txt')
        self.fs.delete('blah.txt')
        assert not self.fs.exists('blah.txt')
        self.fs.create('directory', is_dir=True)
        assert self.fs.exists('directory/')
        self.fs.delete('directory/')
        assert not self.fs.exists('directory/')

    def test_delete_recursive(self):
        self.fs.create('subdirectory/file.txt')
        assert self.fs.exists('subdirectory/file.txt')
        self.fs.delete('subdirectory/file.txt')
        assert not self.fs.exists('subdirectory/file.txt')

    def test_move(self):
        self.fs.create('to_move.txt')
        self.fs.move('to_move.txt', 'moved.txt')
        assert not self.fs.exists('to_move.txt')
        assert self.fs.exists('moved.txt')
        self.fs.delete('moved.txt')

    def test_copy(self):
        self.fs.create('copy.txt')
        self.fs.copy('copy.txt', 'copied.txt')
        assert self.fs.exists('copy.txt')
        assert self.fs.exists('copied.txt')
        self.fs.delete('copy.txt')
        self.fs.delete('copied.txt')
Beispiel #24
0
class TestS3(object):
    def setup(self):
        self.fs = Filesystem(
            backends.S3(
                aws_access_key=os.environ['AWS_ACCESS_KEY_ID'],
                aws_secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY'],
                bucket='watson-filesystem'), )

    def test_write(self):
        self.fs.write('test.txt', 'this is a test')
        assert self.fs.exists('test.txt')

    def test_read(self):
        self.fs.write('test.txt', 'test')
        content = self.fs.read('test.txt')
        assert content == b'test'

    def test_read_not_found(self):
        with raises(exceptions.NotFoundError):
            self.fs.read('not-found')

    def test_append(self):
        self.fs.write('test.txt', 'testing')
        assert self.fs.read('test.txt')
        self.fs.append('test.txt', b' with new test copy')
        assert self.fs.read('test.txt') == b'testing with new test copy'

    def test_create_delete(self):
        self.fs.create('blah.txt')
        assert self.fs.exists('blah.txt')
        self.fs.delete('blah.txt')
        assert not self.fs.exists('blah.txt')
        self.fs.create('directory', is_dir=True)
        assert self.fs.exists('directory/')
        self.fs.delete('directory/')
        assert not self.fs.exists('directory/')

    def test_delete_recursive(self):
        self.fs.create('subdirectory/file.txt')
        assert self.fs.exists('subdirectory/file.txt')
        self.fs.delete('subdirectory/file.txt')
        assert not self.fs.exists('subdirectory/file.txt')

    def test_move(self):
        self.fs.create('to_move.txt')
        self.fs.move('to_move.txt', 'moved.txt')
        assert not self.fs.exists('to_move.txt')
        assert self.fs.exists('moved.txt')
        self.fs.delete('moved.txt')

    def test_copy(self):
        self.fs.create('copy.txt')
        self.fs.copy('copy.txt', 'copied.txt')
        assert self.fs.exists('copy.txt')
        assert self.fs.exists('copied.txt')
        self.fs.delete('copy.txt')
        self.fs.delete('copied.txt')
Beispiel #25
0
 def test_with_backend(self):
     assert Filesystem(MockBackend())
 def setup(self):
     self.fs = Filesystem(backends.Local())
     self.output_path = os.path.join(
         os.path.dirname(
             os.path.dirname(os.path.dirname(os.path.dirname(__file__)))),
         '_output')
Beispiel #27
0
 def factory(cls, **kwargs):
     """Provides a convenient method of initializing the filesystem
     directly off the backend.
     """
     return Filesystem(cls(**kwargs))