Beispiel #1
0
    def test_open_close(self):
        """Tests the open and close functions."""
        test_source = unittest.source
        if not test_source:
            return

        if unittest.offset:
            raise unittest.SkipTest("source defines offset")

        fsext_volume = pyfsext.volume()

        # Test open and close.
        fsext_volume.open(test_source)
        fsext_volume.close()

        # Test open and close a second time to validate clean up on close.
        fsext_volume.open(test_source)
        fsext_volume.close()

        if os.path.isfile(test_source):
            with open(test_source, "rb") as file_object:

                # Test open_file_object and close.
                fsext_volume.open_file_object(file_object)
                fsext_volume.close()

                # Test open_file_object and close a second time to validate clean up on close.
                fsext_volume.open_file_object(file_object)
                fsext_volume.close()

                # Test open_file_object and close and dereferencing file_object.
                fsext_volume.open_file_object(file_object)
                del file_object
                fsext_volume.close()
Beispiel #2
0
    def test_open_file_object(self):
        """Tests the open_file_object function."""
        test_source = unittest.source
        if not test_source:
            raise unittest.SkipTest("missing source")

        if not os.path.isfile(test_source):
            raise unittest.SkipTest("source not a regular file")

        fsext_volume = pyfsext.volume()

        with DataRangeFileObject(test_source, unittest.offset or 0,
                                 None) as file_object:

            fsext_volume.open_file_object(file_object)

            with self.assertRaises(IOError):
                fsext_volume.open_file_object(file_object)

            fsext_volume.close()

            with self.assertRaises(TypeError):
                fsext_volume.open_file_object(None)

            with self.assertRaises(ValueError):
                fsext_volume.open_file_object(file_object, mode="w")
Beispiel #3
0
  def test_open_close(self):
    """Tests the open and close functions."""
    if not unittest.source:
      return

    fsext_volume = pyfsext.volume()

    # Test open and close.
    fsext_volume.open(unittest.source)
    fsext_volume.close()

    # Test open and close a second time to validate clean up on close.
    fsext_volume.open(unittest.source)
    fsext_volume.close()

    file_object = open(unittest.source, "rb")

    # Test open_file_object and close.
    fsext_volume.open_file_object(file_object)
    fsext_volume.close()

    # Test open_file_object and close a second time to validate clean up on close.
    fsext_volume.open_file_object(file_object)
    fsext_volume.close()

    # Test open_file_object and close and dereferencing file_object.
    fsext_volume.open_file_object(file_object)
    del file_object
    fsext_volume.close()
Beispiel #4
0
    def test_open_close(self):
        """Tests the open and close functions."""
        if not unittest.source:
            return

        fsext_volume = pyfsext.volume()

        # Test open and close.
        fsext_volume.open(unittest.source)
        fsext_volume.close()

        # Test open and close a second time to validate clean up on close.
        fsext_volume.open(unittest.source)
        fsext_volume.close()

        file_object = open(unittest.source, "rb")

        # Test open_file_object and close.
        fsext_volume.open_file_object(file_object)
        fsext_volume.close()

        # Test open_file_object and close a second time to validate clean up on close.
        fsext_volume.open_file_object(file_object)
        fsext_volume.close()

        # Test open_file_object and close and dereferencing file_object.
        fsext_volume.open_file_object(file_object)
        del file_object
        fsext_volume.close()
Beispiel #5
0
    def _Open(self, path_spec, mode='rb'):
        """Opens the file system defined by path specification.

    Args:
      path_spec (PathSpec): path specification.
      mode (Optional[str]): file access mode.

    Raises:
      AccessError: if the access to open the file was denied.
      IOError: if the file system object could not be opened.
      PathSpecError: if the path specification is incorrect.
      ValueError: if the path specification is invalid.
    """
        if not path_spec.HasParent():
            raise errors.PathSpecError(
                'Unsupported path specification without parent.')

        file_object = resolver.Resolver.OpenFileObject(
            path_spec.parent, resolver_context=self._resolver_context)

        try:
            fsext_volume = pyfsext.volume()
            fsext_volume.open_file_object(file_object)
        except:
            file_object.close()
            raise

        self._file_object = file_object
        self._fsext_volume = fsext_volume
Beispiel #6
0
    def test_close(self):
        """Tests the close function."""
        if not unittest.source:
            return

        fsext_volume = pyfsext.volume()

        with self.assertRaises(IOError):
            fsext_volume.close()
Beispiel #7
0
  def test_close(self):
    """Tests the close function."""
    if not unittest.source:
      return

    fsext_volume = pyfsext.volume()

    with self.assertRaises(IOError):
      fsext_volume.close()
Beispiel #8
0
    def test_close(self):
        """Tests the close function."""
        test_source = unittest.source
        if not test_source:
            raise unittest.SkipTest("missing source")

        fsext_volume = pyfsext.volume()

        with self.assertRaises(IOError):
            fsext_volume.close()
Beispiel #9
0
    def test_get_number_of_file_entries(self):
        """Tests the get_number_of_file_entries function and number_of_file_entries property."""
        test_source = unittest.source
        if not test_source:
            raise unittest.SkipTest("missing source")

        fsext_volume = pyfsext.volume()

        with DataRangeFileObject(test_source, unittest.offset or 0,
                                 None) as file_object:

            fsext_volume = pyfsext.volume()
            fsext_volume.open_file_object(file_object)

            number_of_file_entries = fsext_volume.get_number_of_file_entries()
            self.assertIsNotNone(number_of_file_entries)

            self.assertIsNotNone(fsext_volume.number_of_file_entries)

            fsext_volume.close()
Beispiel #10
0
    def test_get_last_written_time(self):
        """Tests the get_last_written_time function and last_written_time property."""
        test_source = unittest.source
        if not test_source:
            raise unittest.SkipTest("missing source")

        fsext_volume = pyfsext.volume()

        with DataRangeFileObject(test_source, unittest.offset or 0,
                                 None) as file_object:

            fsext_volume = pyfsext.volume()
            fsext_volume.open_file_object(file_object)

            last_written_time = fsext_volume.get_last_written_time()
            self.assertIsNotNone(last_written_time)

            self.assertIsNotNone(fsext_volume.last_written_time)

            fsext_volume.close()
Beispiel #11
0
    def test_get_root_directory(self):
        """Tests the get_root_directory function and root_directory property."""
        test_source = unittest.source
        if not test_source:
            raise unittest.SkipTest("missing source")

        fsext_volume = pyfsext.volume()

        with DataRangeFileObject(test_source, unittest.offset or 0,
                                 None) as file_object:

            fsext_volume = pyfsext.volume()
            fsext_volume.open_file_object(file_object)

            root_directory = fsext_volume.get_root_directory()
            self.assertIsNotNone(root_directory)

            self.assertIsNotNone(fsext_volume.root_directory)

            fsext_volume.close()
Beispiel #12
0
  def test_open(self):
    """Tests the open function."""
    if not unittest.source:
      return

    fsext_volume = pyfsext.volume()

    fsext_volume.open(unittest.source)

    with self.assertRaises(IOError):
      fsext_volume.open(unittest.source)

    fsext_volume.close()

    with self.assertRaises(TypeError):
      fsext_volume.open(None)

    with self.assertRaises(ValueError):
      fsext_volume.open(unittest.source, mode="w")
Beispiel #13
0
    def test_open(self):
        """Tests the open function."""
        if not unittest.source:
            return

        fsext_volume = pyfsext.volume()

        fsext_volume.open(unittest.source)

        with self.assertRaises(IOError):
            fsext_volume.open(unittest.source)

        fsext_volume.close()

        with self.assertRaises(TypeError):
            fsext_volume.open(None)

        with self.assertRaises(ValueError):
            fsext_volume.open(unittest.source, mode="w")
Beispiel #14
0
    def test_open_file_object(self):
        """Tests the open_file_object function."""
        if not unittest.source:
            return

        file_object = open(unittest.source, "rb")

        fsext_volume = pyfsext.volume()

        fsext_volume.open_file_object(file_object)

        with self.assertRaises(IOError):
            fsext_volume.open_file_object(file_object)

        fsext_volume.close()

        # TODO: change IOError into TypeError
        with self.assertRaises(IOError):
            fsext_volume.open_file_object(None)

        with self.assertRaises(ValueError):
            fsext_volume.open_file_object(file_object, mode="w")
Beispiel #15
0
  def test_open_file_object(self):
    """Tests the open_file_object function."""
    if not unittest.source:
      return

    file_object = open(unittest.source, "rb")

    fsext_volume = pyfsext.volume()

    fsext_volume.open_file_object(file_object)

    with self.assertRaises(IOError):
      fsext_volume.open_file_object(file_object)

    fsext_volume.close()

    # TODO: change IOError into TypeError
    with self.assertRaises(IOError):
      fsext_volume.open_file_object(None)

    with self.assertRaises(ValueError):
      fsext_volume.open_file_object(file_object, mode="w")
Beispiel #16
0
    def test_open(self):
        """Tests the open function."""
        test_source = unittest.source
        if not test_source:
            raise unittest.SkipTest("missing source")

        if unittest.offset:
            raise unittest.SkipTest("source defines offset")

        fsext_volume = pyfsext.volume()

        fsext_volume.open(test_source)

        with self.assertRaises(IOError):
            fsext_volume.open(test_source)

        fsext_volume.close()

        with self.assertRaises(TypeError):
            fsext_volume.open(None)

        with self.assertRaises(ValueError):
            fsext_volume.open(test_source, mode="w")
Beispiel #17
0
    def test_signal_abort(self):
        """Tests the signal_abort function."""
        fsext_volume = pyfsext.volume()

        fsext_volume.signal_abort()
Beispiel #18
0
  def test_signal_abort(self):
    """Tests the signal_abort function."""
    fsext_volume = pyfsext.volume()

    fsext_volume.signal_abort()