def testIsFunctions(self): """Test the Is? functionality.""" path_spec = tar_path_spec.TarPathSpec(location=u'/syslog', parent=self._os_path_spec) file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) self.assertFalse(file_entry.IsRoot()) self.assertFalse(file_entry.IsVirtual()) self.assertTrue(file_entry.IsAllocated()) self.assertFalse(file_entry.IsDevice()) self.assertFalse(file_entry.IsDirectory()) self.assertTrue(file_entry.IsFile()) self.assertFalse(file_entry.IsLink()) self.assertFalse(file_entry.IsPipe()) self.assertFalse(file_entry.IsSocket()) path_spec = tar_path_spec.TarPathSpec(location=u'/', parent=self._os_path_spec) file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) self.assertTrue(file_entry.IsRoot()) self.assertTrue(file_entry.IsVirtual()) self.assertTrue(file_entry.IsAllocated()) self.assertFalse(file_entry.IsDevice()) self.assertTrue(file_entry.IsDirectory()) self.assertFalse(file_entry.IsFile()) self.assertFalse(file_entry.IsLink()) self.assertFalse(file_entry.IsPipe()) self.assertFalse(file_entry.IsSocket())
def testFileEntryExistsByPathSpec(self): """Test the file entry exists by path specification functionality.""" file_system = tar_file_system.TarFileSystem(self._resolver_context) self.assertNotEqual(file_system, None) file_system.Open(path_spec=self._tar_path_spec) path_spec = tar_path_spec.TarPathSpec(location=u'/syslog', parent=self._os_path_spec) self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec)) path_spec = tar_path_spec.TarPathSpec(location=u'/bogus', parent=self._os_path_spec) self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec)) file_system.Close()
def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() test_file = os.path.join(u'test_data', u'syslog.tar') self._os_path_spec = os_path_spec.OSPathSpec(location=test_file) self._tar_path_spec = tar_path_spec.TarPathSpec( location=u'/syslog', parent=self._os_path_spec)
def testInitialize(self): """Tests the path specification initialization.""" path_spec = tar_path_spec.TarPathSpec(location=u'/test', parent=self._path_spec) self.assertNotEqual(path_spec, None) with self.assertRaises(ValueError): _ = tar_path_spec.TarPathSpec(location=u'/test', parent=None) with self.assertRaises(ValueError): _ = tar_path_spec.TarPathSpec(location=None, parent=self._path_spec) with self.assertRaises(ValueError): _ = tar_path_spec.TarPathSpec(location=u'/test', parent=self._path_spec, bogus=u'BOGUS')
def GetRootFileEntry(self): """Retrieves the root file entry. Returns: A file entry (instance of vfs.FileEntry). """ path_spec = tar_path_spec.TarPathSpec(location=self.LOCATION_ROOT, parent=self._path_spec.parent) return self.GetFileEntryByPathSpec(path_spec)
def testGetStat(self): """Test the get stat functionality.""" path_spec = tar_path_spec.TarPathSpec(location=u'/syslog', parent=self._os_path_spec) file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) stat_object = file_entry.GetStat() self.assertNotEqual(stat_object, None) self.assertEqual(stat_object.type, stat_object.TYPE_FILE)
def testComparable(self): """Tests the path specification comparable property.""" path_spec = tar_path_spec.TarPathSpec(location=u'/test', parent=self._path_spec) self.assertNotEqual(path_spec, None) expected_comparable = u'\n'.join( [u'type: TEST', u'type: TAR, location: /test', u'']) self.assertEqual(path_spec.comparable, expected_comparable)
def testGetFileEntryByPathSpec(self): """Test the get entry by path specification functionality.""" file_system = tar_file_system.TarFileSystem(self._resolver_context) self.assertNotEqual(file_system, None) file_system.Open(path_spec=self._tar_path_spec) path_spec = tar_path_spec.TarPathSpec(location=u'/syslog', parent=self._os_path_spec) file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertNotEqual(file_entry, None) self.assertEqual(file_entry.name, u'syslog') path_spec = tar_path_spec.TarPathSpec(location=u'/bogus', parent=self._os_path_spec) file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertEqual(file_entry, None) file_system.Close()
def testGetParentFileEntry(self): """Test the get parent file entry functionality.""" path_spec = tar_path_spec.TarPathSpec(location=u'/syslog', parent=self._os_path_spec) file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) self.assertNotEqual(file_entry, None) parent_file_entry = file_entry.GetParentFileEntry() self.assertNotEqual(parent_file_entry, None) self.assertEqual(parent_file_entry.name, u'')
def testSubFileEntries(self): """Test the sub file entries iteration functionality.""" path_spec = tar_path_spec.TarPathSpec(location=u'/', parent=self._os_path_spec) file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) self.assertNotEqual(file_entry, None) self.assertEqual(file_entry.number_of_sub_file_entries, 1) expected_sub_file_entry_names = [u'syslog'] sub_file_entry_names = [] for sub_file_entry in file_entry.sub_file_entries: sub_file_entry_names.append(sub_file_entry.name) self.assertEqual(len(sub_file_entry_names), len(expected_sub_file_entry_names)) self.assertEqual(sorted(sub_file_entry_names), sorted(expected_sub_file_entry_names))