7
7
8
8
9
9
class NonServingRemoteServer (RobotRemoteServer ):
10
+
10
11
def __init__ (self , library ):
11
12
self ._library = library
12
13
14
+
13
15
class StaticLibrary :
16
+
14
17
def passing_keyword (self ):
15
18
pass
16
- def failing_keyword (self , exception , message = 'Hello, world!' ):
17
- raise exception (message )
19
+
20
+ def failing_keyword (self , exception = AssertionError , message = 'Hello, world!' ,
21
+ ** kwargs ):
22
+ err = exception (message )
23
+ for name , value in kwargs .items ():
24
+ setattr (err , name , value )
25
+ raise err
26
+
27
+ def returning_keyword (self , value ):
28
+ return value
29
+
18
30
def logging_keyword (self , stdout , stderr ):
19
31
if stdout :
20
32
sys .stdout .write (stdout )
21
33
if stderr :
22
34
sys .stderr .write (stderr )
23
35
self .streams = (sys .stdout , sys .stderr )
36
+
24
37
def _not_included (self ):
25
38
"""Starts with an underscore"""
39
+
26
40
not_included = "Not a method or function"
27
41
not_included_2 = NonServingRemoteServer # Callable but not method/function
28
42
43
+
29
44
class HybridLibrary :
45
+
30
46
def __init__ (self ):
31
47
self .library = StaticLibrary ()
48
+
32
49
def get_keyword_names (self ):
33
50
return [n for n in dir (self .library ) if n .endswith ('_keyword' )]
51
+
34
52
def __getattr__ (self , name ):
35
53
return getattr (self .library , name )
54
+
36
55
def not_included (self ):
37
56
"""Not returned by get_keyword_names"""
38
57
@@ -46,43 +65,65 @@ def setUp(self):
46
65
def test_get_keyword_names (self ):
47
66
self .assertEquals (self .server .get_keyword_names (),
48
67
['failing_keyword' , 'logging_keyword' ,
49
- 'passing_keyword' , 'stop_remote_server' ])
68
+ 'passing_keyword' , 'returning_keyword' ,
69
+ 'stop_remote_server' ])
50
70
51
71
def test_run_passing_keyword (self ):
52
- self .assertEquals (self .server .run_keyword ('passing_keyword' , []),
53
- {'status' : 'PASS' , 'output' : '' , 'traceback' : '' ,
54
- 'return' : '' , 'error' : '' })
72
+ self .assertEquals (self ._run ('passing_keyword' ), {'status' : 'PASS' })
73
+
74
+ def test_returning_keyword (self ):
75
+ for ret in 'Hello, world!' , 42 , True :
76
+ self .assertEquals (self ._run ('returning_keyword' , ret ),
77
+ {'status' : 'PASS' , 'return' : ret })
55
78
56
79
def test_run_failing_keyword (self ):
57
- ret = self .server .run_keyword ('failing_keyword' , [ValueError ])
58
- self .assertEquals (ret ['status' ], 'FAIL' )
59
- self .assertEquals (ret ['error' ], 'ValueError: Hello, world!' )
80
+ ret = self ._run ('failing_keyword' , ValueError )
81
+ self ._verify_failed (ret , 'ValueError: Hello, world!' )
60
82
61
83
def test_strip_generic_exception_names_from_error_messages (self ):
62
84
for exception in AssertionError , Exception , RuntimeError :
63
- ret = self .server .run_keyword ('failing_keyword' , [exception ])
64
- self .assertEquals (ret ['status' ], 'FAIL' )
65
- self .assertEquals (ret ['error' ], 'Hello, world!' )
85
+ ret = self ._run ('failing_keyword' , exception )
86
+ self ._verify_failed (ret , 'Hello, world!' )
66
87
67
88
def test_return_only_exception_name_if_no_error_message (self ):
68
89
for exception in AssertionError , ValueError :
69
- ret = self .server .run_keyword ('failing_keyword' , [exception , '' ])
70
- self .assertEquals (ret ['status' ], 'FAIL' )
71
- self .assertEquals (ret ['error' ], exception .__name__ )
90
+ ret = self ._run ('failing_keyword' , exception , '' )
91
+ self ._verify_failed (ret , exception .__name__ )
92
+
93
+ def test_continuable_error (self ):
94
+ ret = self ._run ('failing_keyword' , ROBOT_CONTINUE_ON_FAILURE = True )
95
+ self ._verify_failed (ret , continuable = True )
96
+
97
+ def test_fatal_error (self ):
98
+ ret = self ._run ('failing_keyword' , ROBOT_EXIT_ON_FAILURE = 'yes please' )
99
+ self ._verify_failed (ret , fatal = True )
72
100
73
101
def test_logging_to_stdout (self ):
74
- ret = self .server .run_keyword ('logging_keyword' , ['out' , '' ])
75
- self .assertEquals (ret ['output' ], 'out' )
76
- self .assertTrue (all (s .closed for s in self .library .streams ))
102
+ ret = self ._run ('logging_keyword' , 'out' , '' )
103
+ self ._verify_logged (ret , 'out' )
77
104
78
105
def test_logging_to_stderr (self ):
79
- ret = self .server .run_keyword ('logging_keyword' , ['' , 'err' ])
80
- self .assertEquals (ret ['output' ], 'err' )
81
- self .assertTrue (all (s .closed for s in self .library .streams ))
106
+ ret = self ._run ('logging_keyword' , '' , 'err' )
107
+ self ._verify_logged (ret , 'err' )
82
108
83
109
def test_logging_to_stdout_and_stderr (self ):
84
- ret = self .server .run_keyword ('logging_keyword' , ['out' , 'err' ])
85
- self .assertEquals (ret ['output' ], 'out\n *INFO* err' )
110
+ ret = self ._run ('logging_keyword' , 'out' , 'err' )
111
+ self ._verify_logged (ret , 'out\n *INFO* err' )
112
+
113
+ def _run (self , kw , * args , ** kwargs ):
114
+ return self .server .run_keyword (kw , args , kwargs )
115
+
116
+ def _verify_failed (self , ret , error = 'Hello, world!' , continuable = False ,
117
+ fatal = False ):
118
+ ret .pop ('traceback' )
119
+ if continuable :
120
+ self .assertEquals (ret .pop ('continuable' ), True )
121
+ if fatal :
122
+ self .assertEquals (ret .pop ('fatal' ), True )
123
+ self .assertEquals (ret , {'error' : error , 'status' : 'FAIL' })
124
+
125
+ def _verify_logged (self , ret , output ):
126
+ self .assertEquals (ret , {'output' : output , 'status' : 'PASS' })
86
127
self .assertTrue (all (s .closed for s in self .library .streams ))
87
128
88
129
0 commit comments