Beispiel #1
0
    def test_close(self, fake_open, fake_os):
        """FileHandle - ``close`` closes the file handle"""
        fake_os.stat.return_value.st_size = 100
        handle = ova.FileHandle('/not/a/file')
        handle.close()

        self.assertTrue(fake_open.return_value.close.called)
Beispiel #2
0
    def test_init(self, fake_open, fake_os):
        """FileHandle - ``__init__`` sets the st_size attribute"""
        fake_os.stat.return_value.st_size = 100
        handle = ova.FileHandle('/not/a/file')
        expected = 100

        self.assertEqual(handle.st_size, expected)
Beispiel #3
0
    def test_read(self, fake_open, fake_os):
        """FileHandle - ``read`` proxies to the file handle"""
        fake_os.stat.return_value.st_size = 100
        handle = ova.FileHandle('/not/a/file')

        handle.read(100)

        self.assertTrue(fake_open.return_value.read.called)
Beispiel #4
0
    def test_seek(self, fake_open, fake_os):
        """FileHandle - ``seek`` proxies call to the file handle"""
        fake_os.stat.return_value.st_size = 100
        handle = ova.FileHandle('/not/a/file')

        handle.seek(500)

        self.assertTrue(fake_open.return_value.seek.called)
Beispiel #5
0
    def test_seek_whence_2(self, fake_open, fake_os):
        """FileHandle - ``seek`` subtracts the size and offset when whence is 2"""
        fake_os.stat.return_value.st_size = 100
        handle = ova.FileHandle('/not/a/file')

        handle.seek(50, whence=2)
        expected = 50

        self.assertEqual(handle.offset, expected)
Beispiel #6
0
    def test_seek_math(self, fake_open, fake_os):
        """FileHandle - ``seek`` updates the offset correctly"""
        fake_os.stat.return_value.st_size = 100
        handle = ova.FileHandle('/not/a/file')

        handle.seek(500)
        expected = 500

        self.assertEqual(handle.offset, expected)
Beispiel #7
0
    def test_progress(self, fake_open, fake_os):
        """FileHandle - ``progress`` returns how much of the file has been read"""
        fake_os.stat.return_value.st_size = 10
        handle = ova.FileHandle('/not/a/file')
        handle.offset = 5

        result = handle.progress()
        expected = 50

        self.assertEqual(result, expected)
Beispiel #8
0
    def test_seek_whence_1(self, fake_open, fake_os):
        """FileHandle - ``seek`` sums the offset when whence is 1"""
        fake_os.stat.return_value.st_size = 100
        handle = ova.FileHandle('/not/a/file')
        handle.offset = 100

        handle.seek(500, whence=1)
        expected = 600

        self.assertEqual(handle.offset, expected)
Beispiel #9
0
    def test_seekable(self, fake_open, fake_os):
        """FileHandle - ``seekable`` is True"""
        fake_os.stat.return_value.st_size = 100
        handle = ova.FileHandle('/not/a/file')

        self.assertTrue(handle.seekable())