2 Copyright (c) 2018-2019 Intel Corporation
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
21 from unittest.mock import patch
25 from mo.utils.cli_parser import get_placeholder_shapes, get_tuple_values, get_mean_scale_dictionary, get_model_name, \
26 get_absolute_path, parse_tuple_pairs, check_positive, writable_dir, readable_dirs, \
28 from mo.utils.error import Error
31 class TestingMeanScaleGetter(unittest.TestCase):
32 def test_tuple_parser(self):
33 tuple_values = "data(1.1,22.22,333.333),info[2.2,33.33,444.444]"
34 result = parse_tuple_pairs(tuple_values)
36 'data': np.array([1.1, 22.22, 333.333]),
37 'info': np.array([2.2, 33.33, 444.444])
39 for el in exp_res.keys():
40 np.array_equal(result[el], exp_res[el])
42 def test_tuple_parser_same_values(self):
43 tuple_values = "data(1.1,22.22,333.333),info[1.1,22.22,333.333]"
44 result = parse_tuple_pairs(tuple_values)
46 'data': np.array([1.1, 22.22, 333.333]),
47 'info': np.array([1.1, 22.22, 333.333])
49 for el in exp_res.keys():
50 np.array_equal(result[el], exp_res[el])
52 def test_tuple_parser_no_inputs(self):
53 tuple_values = "(1.1,22.22,333.333),[2.2,33.33,444.444]"
54 result = parse_tuple_pairs(tuple_values)
55 exp_res = [np.array([1.1, 22.22, 333.333]),
56 np.array([2.2, 33.33, 444.444])]
57 for i in range(0, len(exp_res)):
58 np.array_equal(result[i], exp_res[i])
60 def test_tuple_parser_error(self):
61 tuple_values = "(1.1,22.22,333.333),data[2.2,33.33,444.444]"
62 self.assertRaises(Error, parse_tuple_pairs, tuple_values)
64 def test_mean_scale_no_input(self):
65 mean_values = "data(1.1,22.22,333.333)"
66 scale_values = "info[1.1,22.22,333.333]"
67 result = get_mean_scale_dictionary(parse_tuple_pairs(mean_values), parse_tuple_pairs(scale_values), None)
70 'mean': np.array([1.1, 22.22, 333.333]),
75 'scale': np.array([1.1, 22.22, 333.333])
78 for input in exp_res.keys():
79 for key in exp_res[input].keys():
80 if type(exp_res[input][key]) is np.ndarray:
81 np.array_equal(exp_res[input][key], result[input][key])
83 self.assertEqual(exp_res[input][key], result[input][key])
85 def test_mean_scale_no_input_diff_len(self):
86 mean_values = "data(1.1,22.22,333.333),info(2.1,33.22,333.333)"
87 scale_values = "info[1.1,22.22,333.333]"
88 result = get_mean_scale_dictionary(parse_tuple_pairs(mean_values), parse_tuple_pairs(scale_values), None)
91 'mean': np.array([1.1, 22.22, 333.333]),
95 'mean': np.array([2.1, 33.22, 333.333]),
96 'scale': np.array([1.1, 22.22, 333.333])
99 for input in exp_res.keys():
100 for key in exp_res[input].keys():
101 if type(exp_res[input][key]) is np.ndarray:
102 np.array_equal(exp_res[input][key], result[input][key])
104 self.assertEqual(exp_res[input][key], result[input][key])
106 def test_mean_only_input(self):
107 mean_values = "data(1.1,22.22,333.333)"
108 result = get_mean_scale_dictionary(parse_tuple_pairs(mean_values), parse_tuple_pairs(''), None)
111 'mean': np.array([1.1, 22.22, 333.333]),
115 for input in exp_res.keys():
116 for key in exp_res[input].keys():
117 if type(exp_res[input][key]) is np.ndarray:
118 np.array_equal(exp_res[input][key], result[input][key])
120 self.assertEqual(exp_res[input][key], result[input][key])
122 def test_scale_only_input(self):
123 scale_values = "data(1.1,22.22,333.333)"
124 result = get_mean_scale_dictionary(parse_tuple_pairs(''), parse_tuple_pairs(scale_values), None)
128 'scale': np.array([1.1, 22.22, 333.333])
131 for input in exp_res.keys():
132 for key in exp_res[input].keys():
133 if type(exp_res[input][key]) is np.ndarray:
134 np.array_equal(exp_res[input][key], result[input][key])
136 self.assertEqual(exp_res[input][key], result[input][key])
138 def test_scale_only_no_input(self):
139 scale_values = "(1.1,22.22,333.333)"
141 mean = parse_tuple_pairs(mean_values)
142 scale = parse_tuple_pairs(scale_values)
143 result = get_mean_scale_dictionary(mean, scale, None)
147 np.array([1.1, 22.22, 333.333])
150 for i in range(len(exp_res)):
151 for j in range(len(exp_res[i])):
152 if type(exp_res[i][j]) is np.ndarray:
153 np.array_equal(exp_res[i][j], result[i][j])
155 self.assertEqual(exp_res[i][j], result[i][j])
157 def test_scale_only_with_input(self):
158 scale_values = "(1.1,22.22,333.333)"
160 mean = parse_tuple_pairs(mean_values)
161 scale = parse_tuple_pairs(scale_values)
162 result = get_mean_scale_dictionary(mean, scale, 'data')
166 'scale': np.array([1.1, 22.22, 333.333])
169 for input in exp_res.keys():
170 for key in exp_res[input].keys():
171 if type(exp_res[input][key]) is np.ndarray:
172 np.array_equal(exp_res[input][key], result[input][key])
174 self.assertEqual(exp_res[input][key], result[input][key])
176 def test_2_scale_only_with_input(self):
177 scale_values = "(1.1,22.22,333.333),(1.2,22.33,333.444)"
179 mean = parse_tuple_pairs(mean_values)
180 scale = parse_tuple_pairs(scale_values)
181 result = get_mean_scale_dictionary(mean, scale, 'data,info')
185 'scale': np.array([1.1, 22.22, 333.333])
189 'scale': np.array([1.2, 22.33, 333.444])
192 for input in exp_res.keys():
193 for key in exp_res[input].keys():
194 if type(exp_res[input][key]) is np.ndarray:
195 np.array_equal(exp_res[input][key], result[input][key])
197 self.assertEqual(exp_res[input][key], result[input][key])
199 def test_2_mean_only_with_input(self):
201 mean_values = "(1.1,22.22,333.333),(1.2,22.33,333.444)"
202 mean = parse_tuple_pairs(mean_values)
203 scale = parse_tuple_pairs(scale_values)
204 result = get_mean_scale_dictionary(mean, scale, 'data,info')
207 'mean': np.array([1.1, 22.22, 333.333]),
211 'mean': np.array([1.2, 22.33, 333.444]),
215 for input in exp_res.keys():
216 for key in exp_res[input].keys():
217 if type(exp_res[input][key]) is np.ndarray:
218 np.array_equal(exp_res[input][key], result[input][key])
220 self.assertEqual(exp_res[input][key], result[input][key])
222 def test_mean_only_with_input(self):
224 mean_values = "(1.1,22.22,333.333)"
225 mean = parse_tuple_pairs(mean_values)
226 scale = parse_tuple_pairs(scale_values)
227 result = get_mean_scale_dictionary(mean, scale, 'data')
230 'mean': np.array([1.1, 22.22, 333.333]),
234 for input in exp_res.keys():
235 for key in exp_res[input].keys():
236 if type(exp_res[input][key]) is np.ndarray:
237 np.array_equal(exp_res[input][key], result[input][key])
239 self.assertEqual(exp_res[input][key], result[input][key])
241 def test_mean_scale_diff_no_input(self):
242 scale_values = "(1.1,22.22,333.333),(1.1,22.22,333.333)"
243 mean_values = "(2.1,11.22,444.333)"
244 mean = parse_tuple_pairs(mean_values)
245 scale = parse_tuple_pairs(scale_values)
246 result = get_mean_scale_dictionary(mean, scale, None)
249 np.array([2.1, 11.22, 444.333]), # mean
250 np.array([1.1, 22.22, 333.333]) # scale
254 np.array([1.1, 22.22, 333.333]) # scale
257 for i in range(len(exp_res)):
258 for j in range(len(exp_res[i])):
259 if type(exp_res[i][j]) is np.ndarray:
260 np.array_equal(exp_res[i][j], result[i][j])
262 self.assertEqual(exp_res[i][j], result[i][j])
264 def test_multi_mean_scale_no_input(self):
265 mean_values = "data(1.1,22.22,333.333),info(2.1,33.22,444.333)"
266 scale_values = "data[1.1,22.22,333.333],info[2.1,33.22,444.333]"
267 result = get_mean_scale_dictionary(parse_tuple_pairs(mean_values), parse_tuple_pairs(scale_values), None)
270 'mean': np.array([1.1, 22.22, 333.333]),
271 'scale': np.array([1.1, 22.22, 333.333])
274 'mean': np.array([2.1, 33.22, 444.333]),
275 'scale': np.array([2.1, 33.22, 444.333])
278 for input in exp_res.keys():
279 for key in exp_res[input].keys():
280 if type(exp_res[input][key]) is np.ndarray:
281 np.array_equal(exp_res[input][key], result[input][key])
283 self.assertEqual(exp_res[input][key], result[input][key])
285 def test_multi_mean_scale_input(self):
286 mean_values = "data(1.1,22.22,333.333),info(2.1,33.22,444.333)"
287 scale_values = "data[1.1,22.22,333.333],info[2.1,33.22,444.333]"
288 input_names = 'data,info'
289 result = get_mean_scale_dictionary(parse_tuple_pairs(mean_values), parse_tuple_pairs(scale_values), input_names)
292 'mean': np.array([1.1, 22.22, 333.333]),
293 'scale': np.array([1.1, 22.22, 333.333])
296 'mean': np.array([2.1, 33.22, 444.333]),
297 'scale': np.array([2.1, 33.22, 444.333])
300 for input in exp_res.keys():
301 for key in exp_res[input].keys():
302 if type(exp_res[input][key]) is np.ndarray:
303 np.array_equal(exp_res[input][key], result[input][key])
305 self.assertEqual(exp_res[input][key], result[input][key])
307 def test_multi_mean_scale_input_arrays(self):
308 mean_values = "(1.1,22.22,333.333),(2.1,33.22,444.333)"
309 scale_values = "[1.1,22.22,333.333],[2.1,33.22,444.333]"
310 input_names = 'data,info'
311 result = get_mean_scale_dictionary(parse_tuple_pairs(mean_values), parse_tuple_pairs(scale_values), input_names)
314 'mean': np.array([1.1, 22.22, 333.333]),
315 'scale': np.array([1.1, 22.22, 333.333])
318 'mean': np.array([2.1, 33.22, 444.333]),
319 'scale': np.array([2.1, 33.22, 444.333])
322 for input in exp_res.keys():
323 for key in exp_res[input].keys():
324 if type(exp_res[input][key]) is np.ndarray:
325 np.array_equal(exp_res[input][key], result[input][key])
327 self.assertEqual(exp_res[input][key], result[input][key])
329 def test_multi_mean_scale_arrays_no_input(self):
330 mean_values = "(1.1,22.22,333.333),(2.1,33.22,444.333)"
331 scale_values = "[1.1,22.22,333.333],[2.1,33.22,444.333]"
332 result = get_mean_scale_dictionary(parse_tuple_pairs(mean_values), parse_tuple_pairs(scale_values), None)
335 np.array([1.1, 22.22, 333.333]), # mean
336 np.array([1.1, 22.22, 333.333]) # scale
339 np.array([2.1, 33.22, 444.333]), # mean
340 np.array([2.1, 33.22, 444.333]) # scale
343 for i in range(0, len(exp_res)):
344 for j in range(0, len(exp_res[i])):
345 np.array_equal(exp_res[i][j], result[i][j])
348 class TestSingleTupleParsing(unittest.TestCase):
349 def test_get_values_ideal(self):
350 values = "(1.11, 22.22, 333.333)"
351 result = get_tuple_values(values)
352 exp_res = ['1.11, 22.22, 333.333']
353 self.assertEqual(exp_res, result)
355 def test_get_values_ideal_spaces(self):
356 values = "(1 , 22 ,333)"
357 result = get_tuple_values(values)
358 exp_res = ['1 , 22 ,333']
359 self.assertEqual(exp_res, result)
361 def test_get_values_ideal_square(self):
362 values = "[1,22,333]"
363 result = get_tuple_values(values)
364 exp_res = ['1,22,333']
365 self.assertEqual(exp_res, result)
367 def test_get_values_ideal_square_spaces(self):
368 values = "[1 , 22 ,333]"
369 result = get_tuple_values(values)
370 exp_res = ['1 , 22 ,333']
371 self.assertEqual(exp_res, result)
373 def test_get_neg_values_ideal(self):
374 values = "(-1,-22,-333)"
375 result = get_tuple_values(values)
376 exp_res = ['-1,-22,-333']
377 self.assertEqual(exp_res, result)
379 def test_get_neg_values_minus(self):
380 values = "(-1,--22,-3-33)"
381 self.assertRaises(Error, get_tuple_values, values)
383 def test_get_values_unbalanced(self):
384 values = "(1,22,333]"
385 self.assertRaises(Error, get_tuple_values, values)
387 def test_get_values_unbalanced2(self):
388 values = "[1,22,333)"
389 self.assertRaises(Error, get_tuple_values, values)
391 def test_get_values_exactly_3(self):
392 values = "[1,22,333,22]"
393 self.assertRaises(Error, get_tuple_values, values)
395 def test_get_values_exactly_3_1(self):
397 self.assertRaises(Error, get_tuple_values, values)
399 def test_get_values_empty(self):
401 self.assertRaises(Error, get_tuple_values, values)
403 def test_get_values_empty_tuple(self):
405 result = get_tuple_values(values)
407 self.assertEqual(exp_res, result)
410 class TestShapesParsing(unittest.TestCase):
411 def test_get_shapes_several_inputs_several_shapes(self):
412 argv_input = "inp1,inp2"
413 input_shapes = "(1,22,333,123), (-1,45,7,1)"
414 result = get_placeholder_shapes(argv_input, input_shapes)
415 exp_res = {'inp1': np.array([1, 22, 333, 123]), 'inp2': np.array([-1, 45, 7, 1])}
416 self.assertEqual(list(exp_res.keys()), list(result.keys()))
417 for i in exp_res.keys():
418 np.testing.assert_array_equal(result[i], exp_res[i])
420 def test_get_shapes_several_inputs_several_shapes_not_equal(self):
421 argv_input = "inp1,inp2,inp3"
422 input_shapes = "(1,22,333,123), (-1,45,7,1)"
423 self.assertRaises(Error, get_placeholder_shapes, argv_input, input_shapes)
425 def test_get_shapes_several_shapes_one_input(self):
427 input_shapes = "(1,22,333,123), (-1,45,7,1), (-1,456,7,1)"
428 self.assertRaises(Error, get_placeholder_shapes, argv_input, input_shapes)
430 def test_get_shapes_several_shapes_no_input(self):
432 input_shapes = "(1,22,333,123), (-1,45,7,1), (-1,456,7,1)"
433 self.assertRaises(Error, get_placeholder_shapes, argv_input, input_shapes)
435 def test_get_shapes_one_input_one_shape(self):
437 input_shapes = "(1,22,333,123)"
438 result = get_placeholder_shapes(argv_input, input_shapes)
439 exp_res = {'inp1': np.array([1, 22, 333, 123])}
440 self.assertEqual(list(exp_res.keys()), list(result.keys()))
441 for i in exp_res.keys():
442 np.testing.assert_array_equal(result[i], exp_res[i])
444 def test_get_shapes_no_input_no_shape(self):
447 result = get_placeholder_shapes(argv_input, input_shapes)
448 exp_res = np.array([None])
449 np.testing.assert_array_equal(result, exp_res)
451 def test_get_shapes_no_input_one_shape(self):
453 input_shapes = "(12,4,1)"
454 result = get_placeholder_shapes(argv_input, input_shapes)
455 exp_res = np.array([12, 4, 1])
456 np.testing.assert_array_equal(result, exp_res)
458 def test_get_shapes_no_input_one_shape2(self):
460 input_shapes = "[12,4,1]"
461 result = get_placeholder_shapes(argv_input, input_shapes)
462 exp_res = np.array([12, 4, 1])
463 np.testing.assert_array_equal(result, exp_res)
465 def test_get_shapes_no_input_two_shapes(self):
467 input_shapes = "(12,4,1),(5,4,3)"
468 self.assertRaises(Error, get_placeholder_shapes, argv_input, input_shapes)
470 def test_get_shapes_one_input_no_shape(self):
473 result = get_placeholder_shapes(argv_input, input_shapes)
474 exp_res = {'inp1': np.array([None])}
475 self.assertEqual(list(exp_res.keys()), list(result.keys()))
476 for i in exp_res.keys():
477 np.testing.assert_array_equal(result[i], exp_res[i])
479 def test_get_shapes_one_input_wrong_shape8(self):
481 input_shapes = "[2,4,1)"
482 self.assertRaises(Error, get_placeholder_shapes, argv_input, input_shapes)
484 def test_get_shapes_one_input_wrong_shape9(self):
486 input_shapes = "(2,4,1]"
487 self.assertRaises(Error, get_placeholder_shapes, argv_input, input_shapes)
489 def test_get_shapes_one_input_wrong_shape10(self):
491 input_shapes = "(2,,,4,1]"
492 self.assertRaises(Error, get_placeholder_shapes, argv_input, input_shapes)
494 def test_get_shapes_one_input_wrong_shape2(self):
496 input_shapes = "(2,4,1"
497 self.assertRaises(Error, get_placeholder_shapes, argv_input, input_shapes)
499 def test_get_shapes_one_input_wrong_shape3(self):
501 input_shapes = "2,4,1"
502 self.assertRaises(Error, get_placeholder_shapes, argv_input, input_shapes)
504 def test_get_shapes_one_input_wrong_shape4(self):
506 input_shapes = "2;4;1"
507 self.assertRaises(Error, get_placeholder_shapes, argv_input, input_shapes)
509 def test_get_shapes_one_input_wrong_shape5(self):
511 input_shapes = "2, 4,1"
512 self.assertRaises(Error, get_placeholder_shapes, argv_input, input_shapes)
514 def test_get_shapes_one_input_wrong_shape6(self):
516 input_shapes = "(2, 4,1),[4,6,8]"
517 self.assertRaises(Error, get_placeholder_shapes, argv_input, input_shapes)
519 def test_get_shapes_one_input_wrong_shape7(self):
521 input_shapes = "[2,4,1],(4,6,8)"
522 self.assertRaises(Error, get_placeholder_shapes, argv_input, input_shapes)
524 def test_get_shapes_one_input_several_shapes(self):
526 input_shapes = "(2,4,1),(4,6,8)"
527 self.assertRaises(Error, get_placeholder_shapes, argv_input, input_shapes)
529 def test_get_shapes_one_input_first_neg_shape1(self):
530 argv_input = "inp1,inp2"
531 input_shapes = "(-1,4,1),(4,6,8)"
532 result = get_placeholder_shapes(argv_input, input_shapes)
533 exp_res = {'inp1': np.array([-1, 4, 1]), 'inp2': np.array([4, 6, 8])}
534 self.assertEqual(list(exp_res.keys()), list(result.keys()))
535 for i in exp_res.keys():
536 np.testing.assert_array_equal(result[i], exp_res[i])
538 def test_get_shapes_one_input_first_neg_shape_not_one(self):
540 input_shapes = "(-12,4,1),(4,6,8)"
541 self.assertRaises(Error, get_placeholder_shapes, argv_input, input_shapes)
543 def test_get_shapes_one_input_any_neg_shape(self):
544 argv_input = "inp1, inp2"
545 input_shapes = "(12,4,1),(4,-6,8)"
546 self.assertRaises(Error, get_placeholder_shapes, argv_input, input_shapes)
549 class TestModelNameParsing(unittest.TestCase):
550 def test_model_name_ideal(self):
551 model_name = '/home/models/mymodel.caffemodel'
552 res = get_model_name(model_name)
554 self.assertEqual(exp_res, res)
556 def test_model_name_no_name(self):
557 model_name = '/home/models/.caffemodel'
558 res = get_model_name(model_name)
560 self.assertEqual(exp_res, res)
562 def test_model_name_no_ext(self):
563 model_name = '/home/models/caffemodel'
564 res = get_model_name(model_name)
565 exp_res = 'caffemodel'
566 self.assertEqual(exp_res, res)
568 def test_model_name_no_name_no_path(self):
569 model_name = '.caffemodel'
570 res = get_model_name(model_name)
572 self.assertEqual(exp_res, res)
574 @patch("mo.utils.cli_parser.os")
575 def test_model_name_win(self, old_os):
576 old_os.path.basename.return_value = "caffemodel"
577 old_os.path.splitext.return_value = ("caffemodel", "")
578 model_name = r'\home\models\caffemodel'
579 res = get_model_name(model_name)
581 exp_res = 'caffemodel'
582 self.assertEqual(exp_res, res)
584 def test_model_name_dots(self):
585 model_name = r'/home/models/squeezenet_v1.1.caffemodel'
586 res = get_model_name(model_name)
587 exp_res = 'squeezenet_v1.1'
588 self.assertEqual(exp_res, res)
591 class PositiveChecker(unittest.TestCase):
592 def test_positive_checker_batch(self):
593 res = check_positive('1')
594 self.assertEqual(res, 1)
596 def test_positive_checker_batch_negative(self):
597 self.assertRaises(argparse.ArgumentTypeError, check_positive, '-1')
599 def test_positive_checker_batch_not_int(self):
600 self.assertRaises(argparse.ArgumentTypeError, check_positive, 'qwe')
603 class PathCheckerFunctions(unittest.TestCase):
604 READABLE_DIR = tempfile.gettempdir()
605 WRITABLE_DIR = os.path.join(tempfile.gettempdir(), 'writable_dir')
606 WRITABLE_NON_EXISTING_DIR = os.path.join(WRITABLE_DIR, 'non_existing_dir')
607 NOT_WRITABLE_DIR = os.path.join(tempfile.gettempdir(), 'not_writable_dir')
608 NOT_WRITABLE_SUB_DIR = os.path.join(tempfile.gettempdir(), 'another_not_writable_dir', 'not_existing_dir')
609 EXISTING_FILE = tempfile.NamedTemporaryFile(mode='r+', delete=False).name
610 NOT_EXISTING_FILE = '/abcd/efgh/ijkl'
614 if not os.path.exists(__class__.WRITABLE_DIR):
615 os.makedirs(__class__.WRITABLE_DIR)
616 if os.path.exists(__class__.WRITABLE_NON_EXISTING_DIR):
617 os.removedirs(__class__.WRITABLE_NON_EXISTING_DIR)
619 if not os.path.exists(__class__.NOT_WRITABLE_DIR):
620 os.makedirs(__class__.NOT_WRITABLE_DIR)
621 os.chmod(__class__.NOT_WRITABLE_DIR, 0)
623 if not os.path.exists(os.path.dirname(__class__.NOT_WRITABLE_SUB_DIR)):
624 os.makedirs(os.path.dirname(__class__.NOT_WRITABLE_SUB_DIR))
625 os.chmod(os.path.dirname(__class__.NOT_WRITABLE_SUB_DIR), 0)
626 if os.path.exists(__class__.NOT_EXISTING_FILE):
627 os.remove(__class__.NOT_EXISTING_FILE)
630 def tearDownClass(cls):
631 if os.path.exists(__class__.WRITABLE_DIR):
632 os.removedirs(__class__.WRITABLE_DIR)
633 if os.path.exists(__class__.NOT_WRITABLE_DIR):
634 os.removedirs(__class__.NOT_WRITABLE_DIR)
635 if os.path.exists(os.path.dirname(__class__.NOT_WRITABLE_SUB_DIR)):
636 os.removedirs(os.path.dirname(__class__.NOT_WRITABLE_SUB_DIR))
637 if os.path.exists(__class__.EXISTING_FILE):
638 os.remove(__class__.EXISTING_FILE)
640 def test_single_writable_dir(self):
641 self.assertEqual(__class__.WRITABLE_DIR, writable_dir(__class__.WRITABLE_DIR))
643 def test_single_non_writable_dir(self):
644 with self.assertRaises(Error) as cm:
645 writable_dir(__class__.NOT_WRITABLE_DIR)
647 def test_single_non_writable_sub_dir(self):
648 with self.assertRaises(Error) as cm:
649 writable_dir(__class__.NOT_WRITABLE_SUB_DIR)
651 def test_multiple_writable_dirs(self):
652 dirs_str = ','.join([__class__.WRITABLE_DIR, __class__.WRITABLE_NON_EXISTING_DIR])
653 self.assertEqual(dirs_str, writable_dir(dirs_str))
655 def test_single_writable_non_existing_dir(self):
656 self.assertEqual(__class__.WRITABLE_NON_EXISTING_DIR, writable_dir(__class__.WRITABLE_NON_EXISTING_DIR))
658 def test_readable_dirs(self):
659 dirs_str = ','.join([__class__.WRITABLE_DIR, __class__.READABLE_DIR])
660 self.assertEqual(dirs_str, readable_dirs(dirs_str))
662 def test_not_readable_dirs(self):
663 dirs_str = ','.join([__class__.WRITABLE_DIR, __class__.WRITABLE_NON_EXISTING_DIR])
664 with self.assertRaises(Error) as cm:
665 readable_dirs(dirs_str)
667 def test_readable_file(self):
668 self.assertEqual(__class__.EXISTING_FILE, readable_file(__class__.EXISTING_FILE))
670 def test_non_readable_file(self):
671 with self.assertRaises(Error) as cm:
672 readable_file(__class__.NOT_EXISTING_FILE)