@@ -275,6 +275,81 @@ def testFind(self):
275275 # so eval to real list so Equal can do a list compare
276276 self .assertEqual (sorted (eval (out )), ['1' , '2' ])
277277
278+ def testCliParse (self ):
279+ ''' Note the tests will fail if you run this under pdb.
280+ the context managers capture the pdb prompts and this screws
281+ up the stdout strings with (pdb) prefixed to the line.
282+ '''
283+ import sys
284+
285+ self .admin = AdminTool ()
286+ self .install_init ()
287+
288+ # test partial command lookup fin -> calls find
289+
290+ with captured_output () as (out , err ):
291+ ''' assignedto is not a valid property=value, so
292+ report error.
293+ '''
294+ sys .argv = ['main' , '-i' , '_test_admin' , 'fin' , 'issue' ,
295+ 'assignedto=1' ]
296+ ret = self .admin .main ()
297+
298+ out = out .getvalue ().strip ()
299+ print (out )
300+ expected = "[ '1' ]"
301+ self .assertTrue (expected , out )
302+
303+ # Reopen the db closed by previous call
304+ self .admin = AdminTool ()
305+ # test multiple matches
306+ with captured_output () as (out , err ):
307+ ''' assignedto is not a valid property=value, so
308+ report error.
309+ '''
310+ sys .argv = ['main' , '-i' , '_test_admin' , 'f' , 'issue' ,
311+ 'assignedto' ]
312+ ret = self .admin .main ()
313+
314+ out = out .getvalue ().strip ()
315+ print (out )
316+ expected = 'Multiple commands match "f": filter, find'
317+ self .assertEqual (expected , out )
318+
319+ # Reopen the db closed by previous call
320+ self .admin = AdminTool ()
321+ # test broken command lookup xyzzy is not a valid command
322+ with captured_output () as (out , err ):
323+ ''' assignedto is not a valid property=value, so
324+ report error.
325+ '''
326+ sys .argv = ['main' , '-i' , '_test_admin' , 'xyzzy' , 'issue' ,
327+ 'assignedto' ]
328+ ret = self .admin .main ()
329+
330+ out = out .getvalue ().strip ()
331+ print (out )
332+ expected = ('Unknown command "xyzzy" '
333+ '("help commands" for a list)' )
334+ self .assertEqual (expected , out )
335+
336+
337+ # Reopen the db closed by previous call
338+ self .admin = AdminTool ()
339+ # test for keyword=value check
340+ with captured_output () as (out , err ):
341+ ''' assignedto is not a valid property=value, so
342+ report error.
343+ '''
344+ sys .argv = ['main' , '-i' , '_test_admin' , 'find' , 'issue' ,
345+ 'assignedto' ]
346+ ret = self .admin .main ()
347+
348+ out = out .getvalue ().strip ()
349+ print (out )
350+ expected = 'Error: argument "assignedto" not propname=value'
351+ self .assertTrue (expected in out )
352+
278353 def testFilter (self ):
279354 ''' Note the tests will fail if you run this under pdb.
280355 the context managers capture the pdb prompts and this screws
0 commit comments