Debian Codegraph @

tests/test_exceptions.py

raw symbols SCIP
1 from doit import exceptions
2
3
4 class TestInvalidCommand(object):
5 def test_just_string(self):
6 exception = exceptions.InvalidCommand('whatever string')
7 assert 'whatever string' == str(exception)
8
9 def test_task_not_found(self):
10 exception = exceptions.InvalidCommand(not_found='my_task')
11 exception.cmd_used = 'build'
12 assert 'command `build` invalid parameter: "my_task".' in str(exception)
13
14 def test_param_not_found(self):
15 exception = exceptions.InvalidCommand(not_found='my_task')
16 exception.cmd_used = None
17 want = 'Invalid parameter: "my_task". Must be a command,'
18 assert want in str(exception)
19 assert 'Type "doit help" to see' in str(exception)
20
21 def test_custom_binary_name(self):
22 exception = exceptions.InvalidCommand(not_found='my_task')
23 exception.cmd_used = None
24 exception.bin_name = 'my_tool'
25 assert 'Type "my_tool help" to see ' in str(exception)
26
27
28
29 class TestBaseFail(object):
30 def test_name(self):
31 class XYZ(exceptions.BaseFail):
32 pass
33 my_excp = XYZ("hello")
34 assert 'XYZ' == my_excp.get_name()
35 assert 'XYZ' in str(my_excp)
36 assert 'XYZ' in repr(my_excp)
37
38 def test_msg_notraceback(self):
39 my_excp = exceptions.BaseFail('got you')
40 msg = my_excp.get_msg()
41 assert 'got you' in msg
42
43 def test_exception(self):
44 try:
45 raise IndexError('too big')
46 except Exception as e:
47 my_excp = exceptions.BaseFail('got this', e)
48 msg = my_excp.get_msg()
49 assert 'got this' in msg
50 assert 'too big' in msg
51 assert 'IndexError' in msg
52
53 def test_caught(self):
54 try:
55 raise IndexError('too big')
56 except Exception as e:
57 my_excp = exceptions.BaseFail('got this', e)
58 my_excp2 = exceptions.BaseFail('handle that', my_excp)
59 msg = my_excp2.get_msg()
60 assert 'handle that' in msg
61 assert 'got this' not in msg # could be there too...
62 assert 'too big' in msg
63 assert 'IndexError' in msg
64
65
66 class TestAllCaught(object):
67 def test(self):
68 assert issubclass(exceptions.TaskFailed, exceptions.BaseFail)
69 assert issubclass(exceptions.TaskError, exceptions.BaseFail)
70 assert issubclass(exceptions.SetupError, exceptions.BaseFail)
71 assert issubclass(exceptions.DependencyError, exceptions.BaseFail)