forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
isis_command_interface_test.py
56 lines (43 loc) · 1.97 KB
/
isis_command_interface_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2020 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
import os
import tempfile
import unittest
import uuid
from unittest import mock
from sans.command_interface.ISISCommandInterface import MaskFile
class ISISCommandInterfaceTest(unittest.TestCase):
def test_mask_file_raises_for_empty_file_name(self):
with self.assertRaises(ValueError):
MaskFile(file_name="")
def test_mask_file_handles_folder_paths(self):
tmp_dir = tempfile.gettempdir()
non_existent_folder = str(uuid.uuid1())
path_not_there = os.path.join(tmp_dir, non_existent_folder)
self.assertFalse(os.path.exists(path_not_there))
with self.assertRaises(FileNotFoundError):
MaskFile(path_not_there)
def test_mask_file_handles_non_existent_user_files(self):
tmp_dir = tempfile.gettempdir()
non_existent_file = str(uuid.uuid1())
file_not_there = os.path.join(tmp_dir, non_existent_file)
self.assertFalse(os.path.exists(file_not_there))
with self.assertRaises(FileNotFoundError):
MaskFile(file_not_there)
def test_mask_file_works_for_full_path(self):
tmp_file = tempfile.NamedTemporaryFile(mode='r')
path = tmp_file.name
self.assertTrue(os.path.isfile(path))
self.assertIsNone(MaskFile(path))
def test_mask_file_for_existing_file(self):
tmp_file = tempfile.NamedTemporaryFile(mode='r')
file_name = os.path.basename(tmp_file.name)
with mock.patch('sans.command_interface.ISISCommandInterface.find_full_file_path') as mocked_finder:
mocked_finder.return_value = tmp_file.name
self.assertIsNone(MaskFile(file_name))
if __name__ == '__main__':
unittest.main()