@@ -2139,6 +2139,25 @@ def test_batch_file(monkeypatch):
21392139 os .remove (batch_file .name )
21402140
21412141
2142+ def test_batch_file_no_progress_multiple_statements_per_line (monkeypatch ):
2143+ mycli_main , MockMyCli = _noninteractive_mock_mycli (monkeypatch )
2144+ runner = CliRunner ()
2145+
2146+ with NamedTemporaryFile (prefix = TEMPFILE_PREFIX , mode = 'w' , delete = False ) as batch_file :
2147+ batch_file .write ('select 2; select 3;\n select 4;\n ' )
2148+ batch_file .flush ()
2149+
2150+ try :
2151+ result = runner .invoke (
2152+ mycli_main .click_entrypoint ,
2153+ args = ['--batch' , batch_file .name ],
2154+ )
2155+ assert result .exit_code == 0
2156+ assert MockMyCli .ran_queries == ['select 2;' , 'select 3;' , 'select 4;' ]
2157+ finally :
2158+ os .remove (batch_file .name )
2159+
2160+
21422161def test_batch_file_with_progress (monkeypatch ):
21432162 mycli_main , MockMyCli = _noninteractive_mock_mycli (monkeypatch )
21442163 runner = CliRunner ()
@@ -2182,7 +2201,56 @@ def __call__(self, iterable):
21822201 args = ['--batch' , batch_file .name , '--progress' ],
21832202 )
21842203 assert result .exit_code == 0
2185- assert MockMyCli .ran_queries == ['select 2;\n ' , 'select 2;\n ' , 'select 2;\n ' ]
2204+ assert MockMyCli .ran_queries == ['select 2;' , 'select 2;' , 'select 2;' ]
2205+ assert DummyProgressBar .calls == [[0 , 1 , 2 ]]
2206+ finally :
2207+ os .remove (batch_file .name )
2208+
2209+
2210+ def test_batch_file_with_progress_multiple_statements_per_line (monkeypatch ):
2211+ mycli_main , MockMyCli = _noninteractive_mock_mycli (monkeypatch )
2212+ runner = CliRunner ()
2213+
2214+ class DummyProgressBar :
2215+ calls = []
2216+
2217+ def __init__ (self , * args , ** kwargs ):
2218+ pass
2219+
2220+ def __enter__ (self ):
2221+ return self
2222+
2223+ def __exit__ (self , exc_type , exc , tb ):
2224+ return False
2225+
2226+ def __call__ (self , iterable ):
2227+ values = list (iterable )
2228+ DummyProgressBar .calls .append (values )
2229+ return values
2230+
2231+ monkeypatch .setattr (mycli_main , 'ProgressBar' , DummyProgressBar )
2232+ monkeypatch .setattr (mycli_main .prompt_toolkit .output , 'create_output' , lambda ** kwargs : object ())
2233+ monkeypatch .setattr (
2234+ mycli_main ,
2235+ 'sys' ,
2236+ SimpleNamespace (
2237+ stdin = SimpleNamespace (isatty = lambda : False ),
2238+ stderr = SimpleNamespace (isatty = lambda : True ),
2239+ exit = sys .exit ,
2240+ ),
2241+ )
2242+
2243+ with NamedTemporaryFile (prefix = TEMPFILE_PREFIX , mode = 'w' , delete = False ) as batch_file :
2244+ batch_file .write ('select 2; select 3;\n select 4;\n ' )
2245+ batch_file .flush ()
2246+
2247+ try :
2248+ result = runner .invoke (
2249+ mycli_main .click_entrypoint ,
2250+ args = ['--batch' , batch_file .name , '--progress' ],
2251+ )
2252+ assert result .exit_code == 0
2253+ assert MockMyCli .ran_queries == ['select 2;' , 'select 3;' , 'select 4;' ]
21862254 assert DummyProgressBar .calls == [[0 , 1 , 2 ]]
21872255 finally :
21882256 os .remove (batch_file .name )
0 commit comments