def test_posix_backend_open(self):
     """test opening a file from posix backend"""
     filepath = '1234'
     mode = 'w'
     backend = PosixBackendArchive('/tmp', None, None)
     my_file = backend.open(filepath, mode)
     self.assertTrue(isinstance(my_file, PosixBackendArchive))
     #easiest way to unit test is look at class variable
     # pylint: disable=protected-access
     self.assertTrue(isinstance(backend._file, ExtendedFile))
     # pylint: enable=protected-access
     my_file.close()
     # opening twice in a row is okay
     my_file = backend.open(filepath, mode)
     my_file = backend.open(filepath, mode)
     # force a close to throw an error
     def close_error():
         raise ArchiveInterfaceError("this is an error")
     orig_close = backend._file.close
     backend._file.close = close_error
     hit_exception = False
     try:
         my_file = backend.open(filepath, mode)
     except ArchiveInterfaceError, ex:
         hit_exception = True
 def test_posix_backend_write(self):
     """test writing a file from posix backend"""
     filepath = '1234'
     mode = 'w'
     backend = PosixBackendArchive('/tmp/', None, None)
     my_file = backend.open(filepath, mode)
     error = my_file.write("i am a test string")
     self.assertEqual(error, None)
     my_file.close()
 def test_posix_backend_read(self):
     """test reading a file from posix backend"""
     self.test_posix_backend_write()
     filepath = '1234'
     mode = 'r'
     backend = PosixBackendArchive('/tmp/', None, None)
     my_file = backend.open(filepath, mode)
     buf = my_file.read(-1)
     self.assertEqual(buf, "i am a test string")
     my_file.close()
 def test_posix_backend_close(self):
     """test closing a file from posix backend"""
     filepath = '1234'
     mode = 'w'
     backend = PosixBackendArchive('/tmp/', None, None)
     my_file = backend.open(filepath, mode)
     #easiest way to unit test is look at class variable
     # pylint: disable=protected-access
     self.assertTrue(isinstance(backend._file, ExtendedFile))
     my_file.close()
     self.assertEqual(backend._file, None)
 def test_posix_backend_close(self):
     """test closing a file from posix backend"""
     filepath = '1234'
     mode = 'w'
     backend = PosixBackendArchive('/tmp/')
     my_file = backend.open(filepath, mode)
     #easiest way to unit test is look at class variable
     # pylint: disable=protected-access
     self.assertTrue(isinstance(backend._file, ExtendedFile))
     my_file.close()
     self.assertEqual(backend._file, None)
 def test_posix_backend_failed_write(self):
     """test writing to a failed file"""
     filepath = '1234'
     mode = 'w'
     backend = PosixBackendArchive('/tmp/', None, None)
     # test failed write
     my_file = backend.open(filepath, mode)
     def write_error():
         raise IOError("Unable to Write!")
     backend._file.write = write_error
     hit_exception = False
     try:
         backend.write('write stuff')
     except ArchiveInterfaceError, ex:
         hit_exception = True
         self.assertTrue("Can't write posix file with error" in str(ex))
 def test_posix_backend_create(self):
     """test creating a posix backend """
     backend = PosixBackendArchive('/tmp')
     self.assertTrue(isinstance(backend, PosixBackendArchive))
     #easiest way to unit test is look at class variable
     # pylint: disable=protected-access
     self.assertEqual(backend._prefix, '/tmp')
    def test_posix_backend_failed_write(self):
        """test writing to a failed file"""
        filepath = '1234'
        mode = 'w'
        backend = PosixBackendArchive('/tmp/')
        # test failed write
        my_file = backend.open(filepath, mode)

        def write_error():
            raise IOError("Unable to Write!")

        backend._file.write = write_error
        hit_exception = False
        try:
            backend.write('write stuff')
        except ArchiveInterfaceError, ex:
            hit_exception = True
            self.assertTrue("Can't write posix file with error" in str(ex))