def testOpenClosePathSpec(self):
    file_object = os_file_io.OSFile(self._resolver_context)
    file_object.open(path_spec=self._path_spec1)

    self.assertEqual(file_object.get_size(), 116)
    file_object.close()

    # Try open without a path specification.
    with self.assertRaises(ValueError):
      file_object.open(path_spec=None)

    # Try open with a path specification that has no location.
    test_file = os.path.join(u'test_data', u'password.txt')
    path_spec = os_path_spec.OSPathSpec(location=test_file)
    path_spec.location = None

    with self.assertRaises(errors.PathSpecError):
      file_object.open(path_spec=path_spec)

    # Try open with a path specification that has a parent.
    path_spec = os_path_spec.OSPathSpec(location=test_file)
    path_spec.parent = self._path_spec2

    with self.assertRaises(errors.PathSpecError):
      file_object.open(path_spec=path_spec)
Test the open and close functionality using a path specification.
dataset/ETHPy150Open log2timeline/dfvfs/tests/file_io/os_file_io.py/OSFileTest.testOpenClosePathSpec