@@ -94,13 +94,50 @@ def install_init(self, type="classic",
9494 self .assertEqual (ret , 0 )
9595
9696
97+ def testBasicInteractive (self ):
98+ # first command is an error that should be handled
99+ inputs = iter (["'quit" , "quit" ])
100+
101+ orig_input = AdminTool .my_input
102+
103+ AdminTool .my_input = lambda _self , _prompt : next (inputs )
104+
105+ self .install_init ()
106+ self .admin = AdminTool ()
107+ sys .argv = ['main' , '-i' , self .dirname ]
108+
109+ with captured_output () as (out , err ):
110+ ret = self .admin .main ()
111+
112+ out = out .getvalue ().strip ()
113+
114+ print (ret )
115+ self .assertTrue (ret == 0 )
116+ expected = 'ready for input.\n Type "help" for help.'
117+ self .assertEqual (expected , out [- 1 * len (expected ):])
118+
119+ inputs = iter (["list user" , "quit" ])
120+
121+ AdminTool .my_input = lambda _self , _prompt : next (inputs )
122+
123+ with captured_output () as (out , err ):
124+ ret = self .admin .main ()
125+
126+ out = out .getvalue ().strip ()
127+
128+ print (ret )
129+ self .assertTrue (ret == 0 )
130+ expected = 'help.\n 1: admin\n 2: anonymous'
131+ self .assertEqual (expected , out [- 1 * len (expected ):])
132+
133+
134+ AdminTool .my_input = orig_input
135+
97136 def testGet (self ):
98137 ''' Note the tests will fail if you run this under pdb.
99138 the context managers capture the pdb prompts and this screws
100139 up the stdout strings with (pdb) prefixed to the line.
101140 '''
102- import sys
103-
104141 self .install_init ()
105142 self .admin = AdminTool ()
106143
@@ -187,7 +224,6 @@ def testGet(self):
187224 self .assertEqual (len (err ), 0 )
188225
189226 def testInit (self ):
190- import sys
191227 self .admin = AdminTool ()
192228 sys .argv = ['main' , '-i' , self .dirname , 'install' , 'classic' , self .backend ]
193229 ret = self .admin .main ()
@@ -197,7 +233,6 @@ def testInit(self):
197233 self .assertTrue (os .path .isfile (self .dirname + "/schema.py" ))
198234
199235 def testInitWithConfig_ini (self ):
200- import sys
201236 from roundup .configuration import CoreConfig
202237 self .admin = AdminTool ()
203238 sys .argv = ['main' , '-i' , self .dirname , 'install' , 'classic' , self .backend ]
@@ -233,8 +268,6 @@ def testFind(self):
233268 the context managers capture the pdb prompts and this screws
234269 up the stdout strings with (pdb) prefixed to the line.
235270 '''
236- import sys
237-
238271 self .admin = AdminTool ()
239272 self .install_init ()
240273
@@ -304,7 +337,7 @@ def testGenconfigUpdate(self):
304337 the context managers capture the pdb prompts and this screws
305338 up the stdout strings with (pdb) prefixed to the line.
306339 '''
307- import sys , filecmp
340+ import filecmp
308341
309342 self .admin = AdminTool ()
310343 self .install_init ()
@@ -369,8 +402,6 @@ def testCliParse(self):
369402 the context managers capture the pdb prompts and this screws
370403 up the stdout strings with (pdb) prefixed to the line.
371404 '''
372- import sys
373-
374405 self .admin = AdminTool ()
375406 self .install_init ()
376407
@@ -443,8 +474,6 @@ def testFilter(self):
443474 the context managers capture the pdb prompts and this screws
444475 up the stdout strings with (pdb) prefixed to the line.
445476 '''
446- import sys
447-
448477 self .admin = AdminTool ()
449478 self .install_init ()
450479
@@ -664,8 +693,6 @@ def disabletestHelpInitopts(self):
664693 the context managers capture the pdb prompts and this screws
665694 up the stdout strings with (pdb) prefixed to the line.
666695 '''
667- import sys
668-
669696 self .install_init ()
670697 self .admin = AdminTool ()
671698
@@ -687,8 +714,6 @@ def testSecurity(self):
687714 the context managers capture the pdb prompts and this screws
688715 up the stdout strings with (pdb) prefixed to the line.
689716 '''
690- import sys
691-
692717 self .install_init ()
693718 self .admin = AdminTool ()
694719
@@ -759,8 +784,6 @@ def testSecurityInvalidAttribute(self):
759784 the context managers capture the pdb prompts and this screws
760785 up the stdout strings with (pdb) prefixed to the line.
761786 '''
762- import sys
763-
764787 self .maxDiff = None # we want full diff
765788
766789 self .install_init ()
@@ -838,8 +861,6 @@ def testSet(self):
838861 the context managers capture the pdb prompts and this screws
839862 up the stdout strings with (pdb) prefixed to the line.
840863 '''
841- import sys
842-
843864 self .install_init ()
844865 self .admin = AdminTool ()
845866
@@ -945,8 +966,6 @@ def testSetOnClass(self):
945966 the context managers capture the pdb prompts and this screws
946967 up the stdout strings with (pdb) prefixed to the line.
947968 '''
948- import sys
949-
950969 self .install_init ()
951970
952971 self .admin = AdminTool ()
@@ -1018,8 +1037,6 @@ def testSpecification(self):
10181037 the context managers capture the pdb prompts and this screws
10191038 up the stdout strings with (pdb) prefixed to the line.
10201039 '''
1021- import sys
1022-
10231040 self .install_init ()
10241041 self .admin = AdminTool ()
10251042
@@ -1048,8 +1065,6 @@ def testRetireRestore(self):
10481065 the context managers capture the pdb prompts and this screws
10491066 up the stdout strings with (pdb) prefixed to the line.
10501067 '''
1051- import sys
1052-
10531068 # create user1 at id 3
10541069 self .install_init ()
10551070 self .admin = AdminTool ()
@@ -1136,8 +1151,6 @@ def testTable(self):
11361151 the context managers capture the pdb prompts and this screws
11371152 up the stdout strings with (pdb) prefixed to the line.
11381153 '''
1139- import sys
1140-
11411154 self .install_init ()
11421155 self .admin = AdminTool ()
11431156
0 commit comments