1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tests for the VFS file entry interface."""
from __future__ import unicode_literals
import unittest
from dfvfs.lib import errors
from dfvfs.path import fake_path_spec
from dfvfs.resolver import context
from dfvfs.vfs import fake_file_system
from dfvfs.vfs import file_entry
from tests import test_lib as shared_test_lib
class TestFileEntry(file_entry.FileEntry):
"""File entry for testing."""
# pylint: disable=abstract-method
TYPE_INDICATOR = 'test'
def _GetDirectory(self):
"""Retrieves the directory.
Returns:
Directory: a directory or None.
"""
return file_entry.Directory(self._file_system, self.path_spec)
def _GetSubFileEntries(self):
"""Retrieves sub file entries.
Returns:
generator[FileEntry]: a sub file entry generator.
"""
return iter(())
class AttributeTest(shared_test_lib.BaseTestCase):
"""Tests the VFS attribute interface."""
def testTypeIndicator(self):
"""Tests the type_indicator property."""
attribute = file_entry.Attribute()
self.assertIsNone(attribute.type_indicator)
class DataStreamTest(shared_test_lib.BaseTestCase):
"""Tests the VFS data stream interface."""
def testName(self):
"""Test the name property."""
test_data_stream = file_entry.DataStream()
self.assertEqual(test_data_stream.name, '')
def testIsDefault(self):
"""Test the IsDefault function."""
test_data_stream = file_entry.DataStream()
self.assertTrue(test_data_stream.IsDefault())
class DirectoryTest(shared_test_lib.BaseTestCase):
"""Tests the VFS directory interface."""
# pylint: disable=protected-access
def setUp(self):
"""Sets up the needed objects used throughout the test."""
self._resolver_context = context.Context()
self._path_spec = fake_path_spec.FakePathSpec(location='/')
self._file_system = fake_file_system.FakeFileSystem(self._resolver_context)
self._file_system.Open(self._path_spec)
def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
self._file_system.Close()
def testEntriesGenerator(self):
"""Tests the _EntriesGenerator function."""
test_directory = file_entry.Directory(self._file_system, self._path_spec)
generator = test_directory._EntriesGenerator()
self.assertIsNotNone(generator)
def testEntries(self):
"""Tests the entries property."""
test_directory = file_entry.Directory(self._file_system, self._path_spec)
self.assertEqual(list(test_directory.entries), [])
class FileEntryTest(shared_test_lib.BaseTestCase):
"""Tests the VFS file entry interface."""
# pylint: disable=protected-access
def setUp(self):
"""Sets up the needed objects used throughout the test."""
self._resolver_context = context.Context()
self._path_spec = fake_path_spec.FakePathSpec(location='/')
self._file_system = fake_file_system.FakeFileSystem(self._resolver_context)
self._file_system.Open(self._path_spec)
def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
self._file_system.Close()
def testIntialize(self):
"""Tests the __init__ function."""
with self.assertRaises(ValueError):
file_entry.FileEntry(
self._resolver_context, self._file_system, self._path_spec)
def testGetAttributes(self):
"""Tests the _GetAttributes function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
attributes = test_file_entry._GetAttributes()
self.assertEqual(attributes, [])
def testGetDataStreams(self):
"""Tests the _GetDataStreams function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
data_streams = test_file_entry._GetDataStreams()
self.assertEqual(data_streams, [])
def testGetLink(self):
"""Tests the _GetLink function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
symbolic_link = test_file_entry._GetLink()
self.assertIsNotNone(symbolic_link)
def testGetStatProtected(self):
"""Tests the _GetStat function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
stat_object = test_file_entry._GetStat()
self.assertIsNotNone(stat_object)
def testAccessTime(self):
"""Tests the access_time property."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertIsNone(test_file_entry.access_time)
def testAttributes(self):
"""Tests the attributes property."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertEqual(test_file_entry.attributes, [])
def testChangeTime(self):
"""Tests the change_time property."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertIsNone(test_file_entry.change_time)
def testCreationTime(self):
"""Tests the creation_time property."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertIsNone(test_file_entry.creation_time)
def testDataStreams(self):
"""Tests the data_streams property."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertEqual(test_file_entry.data_streams, [])
def testLink(self):
"""Tests the link property."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertIsNotNone(test_file_entry.link)
def testModificationTime(self):
"""Tests the modification_time property."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertIsNone(test_file_entry.modification_time)
def testName(self):
"""Tests the name property."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertIsNone(test_file_entry.name)
def testNumberOfAttributes(self):
"""Tests the number_of_attributes property."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertEqual(test_file_entry.number_of_attributes, 0)
def testNumberOfDataStreams(self):
"""Tests the number_of_data_streams property."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertEqual(test_file_entry.number_of_data_streams, 0)
def testNumberOfSubFileEntries(self):
"""Tests the number_of_sub_file_entries property."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertEqual(test_file_entry.number_of_sub_file_entries, 0)
def testSubFileEntries(self):
"""Tests the sub_file_entries property."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertIsNotNone(test_file_entry.sub_file_entries)
def testTypeIndicator(self):
"""Tests the type_indicator property."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertEqual(test_file_entry.type_indicator, 'test')
def testGetDataStream(self):
"""Tests the GetDataStream function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
data_stream = test_file_entry.GetDataStream('')
self.assertIsNone(data_stream)
with self.assertRaises(ValueError):
test_file_entry.GetDataStream(0)
def testGetFileObject(self):
"""Tests the GetFileObject function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
file_object = test_file_entry.GetFileObject('bogus')
self.assertIsNone(file_object)
with self.assertRaises(errors.NotSupported):
test_file_entry.GetFileObject('')
def testGetFileSystem(self):
"""Tests the GetFileSystem function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
file_system = test_file_entry.GetFileSystem()
self.assertIsNotNone(file_system)
def testGetLinkedFileEntry(self):
"""Tests the GetLinkedFileEntry function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
linked_file_entry = test_file_entry.GetLinkedFileEntry()
self.assertIsNone(linked_file_entry)
def testGetParentFileEntry(self):
"""Tests the GetParentFileEntry function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
parent_file_entry = test_file_entry.GetParentFileEntry()
self.assertIsNone(parent_file_entry)
def testGetSubFileEntryByName(self):
"""Tests the GetSubFileEntryByName function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
sub_file_entry = test_file_entry.GetSubFileEntryByName('bogus')
self.assertIsNone(sub_file_entry)
def testGetStat(self):
"""Tests the GetStat function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
stat_object = test_file_entry.GetStat()
self.assertIsNotNone(stat_object)
def testHasDataStream(self):
"""Tests the HasDataStream function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertFalse(test_file_entry.HasDataStream(''))
with self.assertRaises(ValueError):
test_file_entry.HasDataStream(0)
def testHasExternalData(self):
"""Tests the HasExternalData function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertFalse(test_file_entry.HasExternalData())
def testIsAllocated(self):
"""Tests the IsAllocated function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertTrue(test_file_entry.IsAllocated())
def testIsDevice(self):
"""Tests the IsDevice function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertFalse(test_file_entry.IsDevice())
def testIsDirectory(self):
"""Tests the IsDirectory function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertFalse(test_file_entry.IsDirectory())
def testIsFile(self):
"""Tests the IsFile function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertFalse(test_file_entry.IsFile())
def testIsLink(self):
"""Tests the IsLink function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertFalse(test_file_entry.IsLink())
def testIsPipe(self):
"""Tests the IsPipe function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertFalse(test_file_entry.IsPipe())
def testIsRoot(self):
"""Tests the IsRoot function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertFalse(test_file_entry.IsRoot())
def testIsSocket(self):
"""Tests the IsSocket function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertFalse(test_file_entry.IsSocket())
def testIsVirtual(self):
"""Tests the IsVirtual function."""
test_file_entry = TestFileEntry(
self._resolver_context, self._file_system, self._path_spec)
self.assertFalse(test_file_entry.IsVirtual())
if __name__ == '__main__':
unittest.main()
|