/ src / analysis / utils / tests / test_path.py
test_path.py
 1  # Python Imports
 2  import os.path
 3  import shutil
 4  import unittest
 5  from pathlib import Path
 6  from unittest.mock import patch
 7  
 8  # Project Imports
 9  from src.analysis.utils import path_utils as path
10  
11  
12  class TestPathUtils(unittest.TestCase):
13  
14      def test_prepare_path(self):
15          test_path = "test_folder/test_file"
16          result_path = Path(test_path)
17          result = path.prepare_path(test_path)
18          self.assertTrue(result.is_ok())
19          self.assertEqual(result_path, result.ok_value)
20          self.assertTrue(os.path.exists("test_folder"))
21          shutil.rmtree("test_folder")
22  
23      @patch("pathlib.Path.mkdir")
24      def test_prepare_path_oserror(self, mock_path_mkdir):
25          mock_path_mkdir.side_effect = OSError
26          test_path = "test_folder/test_file"
27          result = path.prepare_path(test_path)
28          self.assertTrue(result.is_err())
29          self.assertEqual("Error creating test_folder. ", result.err_value)
30          self.assertFalse(os.path.exists("test_folder"))