Решение на In-memory файлова система от Асен Леков

Обратно към всички решения

Към профила на Асен Леков

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 18 неуспешни тест(а)

Код

class FileSystemNode:
def __init__(self, name, directory=False):
self.is_directory = directory
self.size = 1
self.name = name
class FileNode(FileSystemNode):
def __init__(self, name):
super().__init__(name, False)
def append(text):
pass
def truncate(test):
pass
class DirectoryNode(FileSystemNode):
directories = []
files = []
def __init__(self, name):
super().__init__(name, True)
def __iter__(self):
return self
def __next__(self):
if not self.directories and not self.files:
raise StopIteration()
else:
if self.directories:
self.directories.next()
if self.files:
self.files.next()
def nodes(self):
return self.directories+self.files
class NodeDoesNotExistError(Exception):
pass
class SourceNodeDoesNotExistError(NodeDoesNotExistError):
pass
class DestinationNodeDoesNotExistError(NodeDoesNotExistError):
pass
class FileSystemMountError(Exception):
pass
class MountPointDoesNotExistError(FileSystemMountError):
pass
class MountPointNotADirectoryError(FileSystemMountError):
pass
class MountPointNotEmptyError(FileSystemMountError):
pass
class FileSystem:
root = DirectoryNode("/")
def __init__(self, size):
self.size = size
self.available_size = size
def get_node(self, path):
if path == "/":
return self.root
else:
self.root.__next__()
def create(self, path, directory=False, content=''):
folders = filter(None, path.split("/"))
print(len(folders))
for p in range(len(folders) - 1):
if folders[p] is not "":
for entry in self.root:
print(entry.name)
def remove(self, directory=False, force=True):
pass
def move(self, source, destination):
pass
def link(self, source, destination, symbolic=True):
pass
def mount(self, file_system, path):
pass
def unmount(self, path):
pass

Лог от изпълнението

EEEEEEEEEEEEEEEEEE
======================================================================
ERROR: test_create_directory (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_create_file (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_hard_link_create (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_hard_link_space_consumption (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_hard_link_to_directory (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_hard_link_to_missing_file (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_link_create (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_minimal (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_mounting (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_move_not_to_a_directory (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_move_overwrite (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_out_of_space (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_overwrite (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_remove_empty_directory (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_remove_file (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_remove_nonempty_directory (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_symlink_to_missing_file (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_valid_move (test.TestFileSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

----------------------------------------------------------------------
Ran 18 tests in 36.123s

FAILED (errors=18)

История (1 версия и 0 коментара)

Асен обнови решението на 30.04.2015 15:09 (преди над 9 години)

+class FileSystemNode:
+ def __init__(self, name, directory=False):
+ self.is_directory = directory
+ self.size = 1
+ self.name = name
+
+
+class FileNode(FileSystemNode):
+
+ def __init__(self, name):
+ super().__init__(name, False)
+
+ def append(text):
+ pass
+
+ def truncate(test):
+ pass
+
+
+class DirectoryNode(FileSystemNode):
+ directories = []
+ files = []
+
+ def __init__(self, name):
+ super().__init__(name, True)
+
+ def __iter__(self):
+ return self
+
+ def __next__(self):
+ if not self.directories and not self.files:
+ raise StopIteration()
+ else:
+ if self.directories:
+ self.directories.next()
+ if self.files:
+ self.files.next()
+
+ def nodes(self):
+ return self.directories+self.files
+
+
+class NodeDoesNotExistError(Exception):
+ pass
+
+
+class SourceNodeDoesNotExistError(NodeDoesNotExistError):
+ pass
+
+
+class DestinationNodeDoesNotExistError(NodeDoesNotExistError):
+ pass
+
+
+class FileSystemMountError(Exception):
+ pass
+
+
+class MountPointDoesNotExistError(FileSystemMountError):
+ pass
+
+
+class MountPointNotADirectoryError(FileSystemMountError):
+ pass
+
+
+class MountPointNotEmptyError(FileSystemMountError):
+ pass
+
+
+class FileSystem:
+
+ root = DirectoryNode("/")
+
+ def __init__(self, size):
+ self.size = size
+ self.available_size = size
+
+ def get_node(self, path):
+ if path == "/":
+ return self.root
+ else:
+ self.root.__next__()
+
+ def create(self, path, directory=False, content=''):
+ folders = filter(None, path.split("/"))
+
+ print(len(folders))
+
+ for p in range(len(folders) - 1):
+ if folders[p] is not "":
+ for entry in self.root:
+ print(entry.name)
+
+
+ def remove(self, directory=False, force=True):
+ pass
+
+ def move(self, source, destination):
+ pass
+
+ def link(self, source, destination, symbolic=True):
+ pass
+
+ def mount(self, file_system, path):
+ pass
+
+ def unmount(self, path):
+ pass