示例#1
0
 def test_rename_file_not_found_error(self):
     from handlers.util.stochss_errors import StochSSFileNotFoundError
     with tempfile.TemporaryDirectory() as tempdir:
         test_file = "test_file"
         test_path = os.path.join(tempdir, test_file)
         with self.assertRaises(StochSSFileNotFoundError):
             rename(test_path, "test_file2")
示例#2
0
 def test_rename_directory(self):
     with tempfile.TemporaryDirectory() as tempdir:
         test_dir = "test_dir"
         test_path = os.path.join(tempdir, test_dir)
         os.mkdir(test_path)
         rename(test_path, "test_dir2")
         test_new_path = os.path.join(tempdir, "test_dir2")
         assert os.path.isdir(test_new_path)
示例#3
0
 def test_rename_file(self):
     with tempfile.TemporaryDirectory() as tempdir:
         test_file = "test_file"
         test_path = os.path.join(tempdir, test_file)
         Path(test_path).touch()
         rename(test_path, "test_file2")
         test_new_path = os.path.join(tempdir, "test_file2")
         assert os.path.isfile(test_new_path)
示例#4
0
 def test_rename_permission_error(self):
     from handlers.util.stochss_errors import StochSSPermissionsError
     from unittest import mock
     with tempfile.TemporaryDirectory() as tempdir:
         test_dir = "test_dir"
         test_file = "test_file"
         test_dir_path = os.path.join(tempdir, test_dir)
         os.mkdir(test_dir_path)
         test_path = os.path.join(test_dir_path, test_file)
         Path(test_path).touch()
         with mock.patch("shutil.move",
                         side_effect=StochSSPermissionsError(
                             'test_error')) as mock_shutil:
             with self.assertRaises(StochSSPermissionsError):
                 rename(test_path, "test_file2")
示例#5
0
 def test_rename_running_wkfl(self):
     from unittest import mock
     with tempfile.TemporaryDirectory() as tempdir:
         with mock.patch("json.dump") as mock_dump:
             with mock.patch("json.load") as mock_json:
                 with mock.patch('builtins.open',
                                 mock.mock_open(read_data="foo")) as m:
                     test_file = "test_file.wkfl"
                     test_path = os.path.join(tempdir, test_file)
                     target_path = os.path.join(tempdir, "test_file2")
                     os.mkdir(test_path)
                     os.mkdir(target_path)
                     Path(os.path.join(target_path, "RUNNING")).touch()
                     rename(test_path, "test_file2")
                 m.assert_called_with(
                     os.path.join(target_path, "info.json"), 'r+')
示例#6
0
 def test_rename_target_exists(self):
     with tempfile.TemporaryDirectory() as tempdir:
         test_file = "test_file"
         test_path = os.path.join(tempdir, test_file)
         Path(test_path).touch()
         test_file2 = "test_file2"
         test_path2 = os.path.join(tempdir, test_file2)
         Path(test_path2).touch()
         resp = rename(test_path, "test_file2")
         assert resp["changed"] == True