5
5
from pyln .testing .utils import VALGRIND
6
6
import pytest
7
7
import os
8
+ import re
8
9
import shutil
9
10
import time
10
11
import unittest
@@ -91,25 +92,51 @@ def canned_github_server(directory):
91
92
server .terminate ()
92
93
93
94
95
+ class RecklessResult :
96
+ def __init__ (self , process , returncode , stdout , stderr ):
97
+ self .process = process
98
+ self .returncode = returncode
99
+ self .stdout = stdout
100
+ self .stderr = stderr
101
+
102
+ def __repr__ (self ):
103
+ return f'self.returncode, self.stdout, self.stderr'
104
+
105
+ def search_stdout (self , regex ):
106
+ """return the matching regex line from reckless output."""
107
+ ex = re .compile (regex )
108
+ matching = []
109
+ for line in self .stdout :
110
+ if ex .search (line ):
111
+ matching .append (line )
112
+ return matching
113
+
114
+
94
115
def reckless (cmds : list , dir : PosixPath = None ,
95
- autoconfirm = True , timeout : int = 15 ):
116
+ autoconfirm = True , timeout : int = 60 ):
96
117
'''Call the reckless executable, optionally with a directory.'''
97
118
if dir is not None :
98
119
cmds .insert (0 , "-l" )
99
120
cmds .insert (1 , str (dir ))
100
121
cmds .insert (0 , "tools/reckless" )
122
+ if autoconfirm :
123
+ process_input = 'Y\n '
124
+ else :
125
+ process_input = None
101
126
r = subprocess .run (cmds , capture_output = True , encoding = 'utf-8' , env = my_env ,
102
- input = 'Y\n ' )
127
+ input = process_input , timeout = timeout )
128
+ stdout = r .stdout .splitlines ()
129
+ stderr = r .stderr .splitlines ()
103
130
print (" " .join (r .args ), "\n " )
104
131
print ("***RECKLESS STDOUT***" )
105
- for l in r . stdout . splitlines () :
132
+ for l in stdout :
106
133
print (l )
107
134
print ('\n ' )
108
135
print ("***RECKLESS STDERR***" )
109
- for l in r . stderr . splitlines () :
136
+ for l in stderr :
110
137
print (l )
111
138
print ('\n ' )
112
- return r
139
+ return RecklessResult ( r , r . returncode , stdout , stderr )
113
140
114
141
115
142
def get_reckless_node (node_factory ):
@@ -119,28 +146,13 @@ def get_reckless_node(node_factory):
119
146
return node
120
147
121
148
122
- def check_stderr (stderr ):
123
- def output_okay (out ):
124
- for warning in ['[notice]' , 'WARNING:' , 'npm WARN' ,
125
- 'npm notice' , 'DEPRECATION:' , 'Creating virtualenv' ,
126
- 'config file not found:' , 'press [Y]' ]:
127
- if out .startswith (warning ):
128
- return True
129
- return False
130
- for e in stderr .splitlines ():
131
- if len (e ) < 1 :
132
- continue
133
- # Don't err on verbosity from pip, npm
134
- assert output_okay (e )
135
-
136
-
137
149
def test_basic_help ():
138
150
'''Validate that argparse provides basic help info.
139
151
This requires no config options passed to reckless.'''
140
152
r = reckless (["-h" ])
141
153
assert r .returncode == 0
142
- assert "positional arguments:" in r . stdout . splitlines ( )
143
- assert "options:" in r .stdout . splitlines () or "optional arguments:" in r . stdout . splitlines ( )
154
+ assert r . search_stdout ( "positional arguments:" )
155
+ assert r . search_stdout ( "options:" ) or r .search_stdout ( "optional arguments:" )
144
156
145
157
146
158
def test_contextual_help (node_factory ):
@@ -149,7 +161,7 @@ def test_contextual_help(node_factory):
149
161
'enable' , 'disable' , 'source' ]:
150
162
r = reckless ([subcmd , "-h" ], dir = n .lightning_dir )
151
163
assert r .returncode == 0
152
- assert "positional arguments:" in r . stdout . splitlines ( )
164
+ assert r . search_stdout ( "positional arguments:" )
153
165
154
166
155
167
def test_sources (node_factory ):
@@ -194,17 +206,17 @@ def test_search(node_factory):
194
206
n = get_reckless_node (node_factory )
195
207
r = reckless ([f"--network={ NETWORK } " , "search" , "testplugpass" ], dir = n .lightning_dir )
196
208
assert r .returncode == 0
197
- assert 'found testplugpass in source: https://github.com/lightningd/plugins' in r . stdout
209
+ assert r . search_stdout ( 'found testplugpass in source: https://github.com/lightningd/plugins' )
198
210
199
211
200
212
def test_install (node_factory ):
201
213
"""test search, git clone, and installation to folder."""
202
214
n = get_reckless_node (node_factory )
203
215
r = reckless ([f"--network={ NETWORK } " , "-v" , "install" , "testplugpass" ], dir = n .lightning_dir )
204
216
assert r .returncode == 0
205
- assert 'dependencies installed successfully' in r . stdout
206
- assert 'plugin installed:' in r . stdout
207
- assert 'testplugpass enabled' in r . stdout
217
+ assert r . search_stdout ( 'dependencies installed successfully' )
218
+ assert r . search_stdout ( 'plugin installed:' )
219
+ assert r . search_stdout ( 'testplugpass enabled' )
208
220
check_stderr (r .stderr )
209
221
plugin_path = Path (n .lightning_dir ) / 'reckless/testplugpass'
210
222
print (plugin_path )
@@ -217,9 +229,9 @@ def test_poetry_install(node_factory):
217
229
n = get_reckless_node (node_factory )
218
230
r = reckless ([f"--network={ NETWORK } " , "-v" , "install" , "testplugpyproj" ], dir = n .lightning_dir )
219
231
assert r .returncode == 0
220
- assert 'dependencies installed successfully' in r . stdout
221
- assert 'plugin installed:' in r . stdout
222
- assert 'testplugpyproj enabled' in r . stdout
232
+ assert r . search_stdout ( 'dependencies installed successfully' )
233
+ assert r . search_stdout ( 'plugin installed:' )
234
+ assert r . search_stdout ( 'testplugpyproj enabled' )
223
235
check_stderr (r .stderr )
224
236
plugin_path = Path (n .lightning_dir ) / 'reckless/testplugpyproj'
225
237
print (plugin_path )
@@ -240,7 +252,7 @@ def test_local_dir_install(node_factory):
240
252
assert r .returncode == 0
241
253
r = reckless ([f"--network={ NETWORK } " , "-v" , "install" , "testplugpass" ], dir = n .lightning_dir )
242
254
assert r .returncode == 0
243
- assert 'testplugpass enabled' in r . stdout
255
+ assert r . search_stdout ( 'testplugpass enabled' )
244
256
plugin_path = Path (n .lightning_dir ) / 'reckless/testplugpass'
245
257
print (plugin_path )
246
258
assert os .path .exists (plugin_path )
@@ -249,9 +261,9 @@ def test_local_dir_install(node_factory):
249
261
r = reckless (['uninstall' , 'testplugpass' , '-v' ], dir = n .lightning_dir )
250
262
assert not os .path .exists (plugin_path )
251
263
r = reckless (['source' , 'remove' , source_dir ], dir = n .lightning_dir )
252
- assert 'plugin source removed' in r . stdout
264
+ assert r . search_stdout ( 'plugin source removed' )
253
265
r = reckless (['install' , '-v' , source_dir ], dir = n .lightning_dir )
254
- assert 'testplugpass enabled' in r . stdout
266
+ assert r . search_stdout ( 'testplugpass enabled' )
255
267
assert os .path .exists (plugin_path )
256
268
257
269
@@ -263,9 +275,9 @@ def test_disable_enable(node_factory):
263
275
r = reckless ([f"--network={ NETWORK } " , "-v" , "install" , "testPlugPass" ],
264
276
dir = n .lightning_dir )
265
277
assert r .returncode == 0
266
- assert 'dependencies installed successfully' in r . stdout
267
- assert 'plugin installed:' in r . stdout
268
- assert 'testplugpass enabled' in r . stdout
278
+ assert r . search_stdout ( 'dependencies installed successfully' )
279
+ assert r . search_stdout ( 'plugin installed:' )
280
+ assert r . search_stdout ( 'testplugpass enabled' )
269
281
check_stderr (r .stderr )
270
282
plugin_path = Path (n .lightning_dir ) / 'reckless/testplugpass'
271
283
print (plugin_path )
@@ -278,7 +290,7 @@ def test_disable_enable(node_factory):
278
290
r = reckless ([f"--network={ NETWORK } " , "-v" , "enable" , "testplugpass.py" ],
279
291
dir = n .lightning_dir )
280
292
assert r .returncode == 0
281
- assert 'testplugpass enabled' in r . stdout
293
+ assert r . search_stdout ( 'testplugpass enabled' )
282
294
test_plugin = {'name' : str (plugin_path / 'testplugpass.py' ),
283
295
'active' : True , 'dynamic' : True }
284
296
time .sleep (1 )
0 commit comments