Решение на In-memory файлова система от Слави Кадиев

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

Към профила на Слави Кадиев

Резултати

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

Код

class FileSystem:
def __init__(self, size):
self.size = size
self.available_size = size - 1
root = Directory('/')
self.all_directories = [root]
self.all_files = []
def get_node(self, path):
for directory in self.all_directories:
if directory.name == path:
return directory
for my_file in self.all_files:
if my_file.name == path:
return my_file
return 'NodeDoesNotExistError'
def create(self, path, directory=False, content=''):
if directory is False:
new_file = File(path)
self.all_files.append(new_file)
else:
new_directory = Directory(path)
self.all_directories.append(new_directory)
class File:
def __init__(self, name):
self.name = name
def is_directory(self):
return False
def append(self, text):
self.text = text
def truncate(self, text):
self.text = text
@property
def size(self):
return len(self.text) + 1
class Directory:
def __init__(self, name):
self.name = name
self.directories = []
self.files = []
def is_directory(self):
return True
def add_subdirectory(self, name):
if name in self.directories:
return 'The directory is exist'
else:
self.directories.append(name)
def add_file(self, name):
if name in self.files:
return 'The file is exist'
else:
new_file = File(name)
self.files.append(new_file)
def nodes(self):
return self.files + self.directories

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

.EEEEEE.EEEEEEEEEE
======================================================================
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_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 32.151s

FAILED (errors=16)

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

Слави обнови решението на 30.04.2015 16:59 (преди над 9 години)

+class FileSystem:
+ def __init__(self, size):
+ self.size = size
+ self.available_size = size - 1
+ root = Directory('/')
+ self.all_directories = [root]
+ self.all_files = []
+
+ def get_node(self, path):
+ for directory in self.all_directories:
+ if directory.name == path:
+ return directory
+ for my_file in self.all_files:
+ if my_file.name == path:
+ return my_file
+ return 'NodeDoesNotExistError'
+
+ def create(self, path, directory=False, content=''):
+ if directory is False:
+ new_file = File(path)
+ self.all_files.append(new_file)
+ else:
+ new_directory = Directory(path)
+ self.all_directories.append(new_directory)
+
+
+class File:
+ def __init__(self, name):
+ self.name = name
+
+ def is_directory(self):
+ return False
+
+ def append(self, text):
+ self.text = text
+
+ def truncate(self, text):
+ self.text = text
+
+ @property
+ def size(self):
+ return len(self.text) + 1
+
+
+class Directory:
+ def __init__(self, name):
+ self.name = name
+ self.directories = []
+ self.files = []
+
+ def is_directory(self):
+ return True
+
+ def add_subdirectory(self, name):
+ if name in self.directories:
+ return 'The directory is exist'
+ else:
+ self.directories.append(name)
+
+ def add_file(self, name):
+ if name in self.files:
+ return 'The file is exist'
+ else:
+ new_file = File(name)
+ self.files.append(new_file)
+
+ def nodes(self):
+ return self.files + self.directories
+