Преглед на файлове

improve file manager test

nico преди 8 години
родител
ревизия
4d5239be85
променени са 2 файла, в които са добавени 14 реда и са изтрити 2 реда
  1. 11 1
      Tests/test_file_manager.py
  2. 3 1
      kalliope/core/Utils/FileManager.py

+ 11 - 1
Tests/test_file_manager.py

@@ -12,6 +12,10 @@ class TestFileManager(unittest.TestCase):
     def setUp(self):
         pass
 
+    def create_file_manager(self):
+        file_manager = FileManager()
+        self.assertIsInstance(FileManager, file_manager)
+
     def test_create_directory(self):
         """
         Test to create a new directory.
@@ -55,6 +59,12 @@ class TestFileManager(unittest.TestCase):
         if os.path.exists(file_path):
             os.remove(file_path)
 
+        # run into IOError by trying to write something in root
+        dir_path = "/root/"
+        file_name = "test_FileManager_writeInFile"
+        file_path = os.path.join(dir_path, file_name)
+        self.assertFalse(FileManager.write_in_file(file_path=file_path, content=in_file_text))
+
     def test_file_is_empty(self):
         """
         Test that the file is empty
@@ -168,4 +178,4 @@ class TestFileManager(unittest.TestCase):
                          "Fail to assert not accessing this path ")
 
 if __name__ == '__main__':
-    unittest.main()
+    unittest.main()

+ 3 - 1
kalliope/core/Utils/FileManager.py

@@ -41,6 +41,7 @@ class FileManager:
             return not FileManager.file_is_empty(file_path)
         except IOError as e:
             logger.error("I/O error(%s): %s", e.errno, e.strerror)
+            return False
 
     @staticmethod
     def file_is_empty(file_path):
@@ -82,5 +83,6 @@ class FileManager:
         """
         try:
             return os.path.exists(pathname) or FileManager.is_path_creatable(pathname)
-        except OSError:
+        except OSError as e:
+            logger.error("OSError(%s): %s", e.errno, e.strerror)
             return False