-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
69 lines (53 loc) · 2.56 KB
/
tests.py
File metadata and controls
69 lines (53 loc) · 2.56 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
import unittest
from unittest.mock import patch
from luigibio.parameter import FileParameter, FileExistence
class FileParameterTests(unittest.TestCase):
def check_consistency(self, param: FileParameter, existence: FileExistence):
self.assertIs(param.existence, existence)
for e in FileExistence:
if e is not existence:
self.assertIsNot(param.existence, e)
def get_file_param(self, existence: FileExistence):
param = FileParameter(existence)
self.check_consistency(param, existence)
return param
@staticmethod
def parse(param: FileParameter):
param.parse("foo")
def parse_something_with_value_error(self, param: FileParameter):
with self.assertRaises(ValueError):
FileParameterTests.parse(param)
#######################################################
# Tests that will FileParameter let raise a Value Error
#######################################################
@patch('luigibio.parameter.isfile', return_value=True)
@patch('luigibio.parameter.islink', return_value=True)
def test_links_are_not_allowed_1(self, islink, isfile):
self.parse_something_with_value_error(
self.get_file_param(FileExistence.EXISTING))
@patch('luigibio.parameter.isfile', return_value=True)
@patch('luigibio.parameter.islink', return_value=True)
def test_links_are_not_allowed_2(self, islink, isfile):
self.parse_something_with_value_error(
self.get_file_param(FileExistence.NON_EXISTING))
@patch('luigibio.parameter.isfile', return_value=False)
def test_file_must_exist(self, isfile):
self.parse_something_with_value_error(
self.get_file_param(FileExistence.EXISTING))
@patch('luigibio.parameter.exists', return_value=True)
def test_file_must_not_exist(self, exists):
self.parse_something_with_value_error(
self.get_file_param(FileExistence.NON_EXISTING))
#######################################################
# Tests that do not let raise a Value Error
#######################################################
@patch('luigibio.parameter.isfile', return_value=True)
def test_file_exits(self, isfile):
param = self.get_file_param(FileExistence.EXISTING)
FileParameterTests.parse(param)
@patch('luigibio.parameter.exists', return_value=False)
def test_file_does_not_exist(self, exists):
param = self.get_file_param(FileExistence.NON_EXISTING)
FileParameterTests.parse(param)
if __name__ == '__main__':
unittest.main()