@@ -61,9 +61,7 @@ def test_obfuscate_process_password():
6161
6262def test_format_output ():
6363 settings = OutputSettings (table_format = "psql" , dcmlfmt = "d" , floatfmt = "g" )
64- results = format_output (
65- "Title" , [("abc" , "def" )], ["head1" , "head2" ], "test status" , settings
66- )
64+ results = format_output ("Title" , [("abc" , "def" )], ["head1" , "head2" ], "test status" , settings )
6765 expected = [
6866 "Title" ,
6967 "+-------+-------+" ,
@@ -128,9 +126,7 @@ def test_no_column_date_formats():
128126
129127
130128def test_format_output_truncate_on ():
131- settings = OutputSettings (
132- table_format = "psql" , dcmlfmt = "d" , floatfmt = "g" , max_field_width = 10
133- )
129+ settings = OutputSettings (table_format = "psql" , dcmlfmt = "d" , floatfmt = "g" , max_field_width = 10 )
134130 results = format_output (
135131 None ,
136132 [("first field value" , "second field value" )],
@@ -149,9 +145,7 @@ def test_format_output_truncate_on():
149145
150146
151147def test_format_output_truncate_off ():
152- settings = OutputSettings (
153- table_format = "psql" , dcmlfmt = "d" , floatfmt = "g" , max_field_width = None
154- )
148+ settings = OutputSettings (table_format = "psql" , dcmlfmt = "d" , floatfmt = "g" , max_field_width = None )
155149 long_field_value = ("first field " * 100 ).strip ()
156150 results = format_output (None , [(long_field_value ,)], ["head1" ], None , settings )
157151 lines = list (results )
@@ -207,12 +201,8 @@ def test_format_array_output_expanded(executor):
207201
208202
209203def test_format_output_auto_expand ():
210- settings = OutputSettings (
211- table_format = "psql" , dcmlfmt = "d" , floatfmt = "g" , max_width = 100
212- )
213- table_results = format_output (
214- "Title" , [("abc" , "def" )], ["head1" , "head2" ], "test status" , settings
215- )
204+ settings = OutputSettings (table_format = "psql" , dcmlfmt = "d" , floatfmt = "g" , max_width = 100 )
205+ table_results = format_output ("Title" , [("abc" , "def" )], ["head1" , "head2" ], "test status" , settings )
216206 table = [
217207 "Title" ,
218208 "+-------+-------+" ,
@@ -269,18 +259,18 @@ def test_format_output_auto_expand():
269259def pset_pager_mocks ():
270260 cli = PGCli ()
271261 cli .watch_command = None
272- with mock .patch ("pgcli.main.click.echo" ) as mock_echo , mock .patch (
273- "pgcli.main.click.echo_via_pager"
274- ) as mock_echo_via_pager , mock .patch .object (cli , "prompt_app" ) as mock_app :
262+ with (
263+ mock .patch ("pgcli.main.click.echo" ) as mock_echo ,
264+ mock .patch ("pgcli.main.click.echo_via_pager" ) as mock_echo_via_pager ,
265+ mock .patch .object (cli , "prompt_app" ) as mock_app ,
266+ ):
275267 yield cli , mock_echo , mock_echo_via_pager , mock_app
276268
277269
278270@pytest .mark .parametrize ("term_height,term_width,text" , test_data , ids = test_ids )
279271def test_pset_pager_off (term_height , term_width , text , pset_pager_mocks ):
280272 cli , mock_echo , mock_echo_via_pager , mock_cli = pset_pager_mocks
281- mock_cli .output .get_size .return_value = termsize (
282- rows = term_height , columns = term_width
283- )
273+ mock_cli .output .get_size .return_value = termsize (rows = term_height , columns = term_width )
284274
285275 with mock .patch .object (cli .pgspecial , "pager_config" , PAGER_OFF ):
286276 cli .echo_via_pager (text )
@@ -292,9 +282,7 @@ def test_pset_pager_off(term_height, term_width, text, pset_pager_mocks):
292282@pytest .mark .parametrize ("term_height,term_width,text" , test_data , ids = test_ids )
293283def test_pset_pager_always (term_height , term_width , text , pset_pager_mocks ):
294284 cli , mock_echo , mock_echo_via_pager , mock_cli = pset_pager_mocks
295- mock_cli .output .get_size .return_value = termsize (
296- rows = term_height , columns = term_width
297- )
285+ mock_cli .output .get_size .return_value = termsize (rows = term_height , columns = term_width )
298286
299287 with mock .patch .object (cli .pgspecial , "pager_config" , PAGER_ALWAYS ):
300288 cli .echo_via_pager (text )
@@ -306,14 +294,10 @@ def test_pset_pager_always(term_height, term_width, text, pset_pager_mocks):
306294pager_on_test_data = [l + (r ,) for l , r in zip (test_data , use_pager_when_on )]
307295
308296
309- @pytest .mark .parametrize (
310- "term_height,term_width,text,use_pager" , pager_on_test_data , ids = test_ids
311- )
297+ @pytest .mark .parametrize ("term_height,term_width,text,use_pager" , pager_on_test_data , ids = test_ids )
312298def test_pset_pager_on (term_height , term_width , text , use_pager , pset_pager_mocks ):
313299 cli , mock_echo , mock_echo_via_pager , mock_cli = pset_pager_mocks
314- mock_cli .output .get_size .return_value = termsize (
315- rows = term_height , columns = term_width
316- )
300+ mock_cli .output .get_size .return_value = termsize (rows = term_height , columns = term_width )
317301
318302 with mock .patch .object (cli .pgspecial , "pager_config" , PAGER_LONG_OUTPUT ):
319303 cli .echo_via_pager (text )
@@ -330,7 +314,7 @@ def test_pset_pager_on(term_height, term_width, text, use_pager, pset_pager_mock
330314 "text,expected_length" ,
331315 [
332316 (
333- "22200K .......\u001b [0m\u001b [91m... .......... ...\u001b [0m\u001b [91m.\u001b [0m\u001b [91m...... .........\u001b [0m\u001b [91m.\u001b [0m\u001b [91m \u001b [0m\u001b [91m.\u001b [0m\u001b [91m.\u001b [0m\u001b [91m.\u001b [0m\u001b [91m.\u001b [0m\u001b [91m...... 50% 28.6K 12m55s" ,
317+ "22200K .......\u001b [0m\u001b [91m... .......... ...\u001b [0m\u001b [91m.\u001b [0m\u001b [91m...... .........\u001b [0m\u001b [91m.\u001b [0m\u001b [91m \u001b [0m\u001b [91m.\u001b [0m\u001b [91m.\u001b [0m\u001b [91m.\u001b [0m\u001b [91m.\u001b [0m\u001b [91m...... 50% 28.6K 12m55s" , # noqa: E501
334318 78 ,
335319 ),
336320 ("=\u001b [m=" , 2 ),
@@ -405,34 +389,24 @@ def test_logfile_unwriteable_file(executor):
405389 cli = PGCli (pgexecute = executor )
406390 statement = r"\log-file forbidden.log"
407391 with mock .patch ("builtins.open" ) as mock_open :
408- mock_open .side_effect = PermissionError (
409- "[Errno 13] Permission denied: 'forbidden.log'"
410- )
392+ mock_open .side_effect = PermissionError ("[Errno 13] Permission denied: 'forbidden.log'" )
411393 result = run (executor , statement , pgspecial = cli .pgspecial )
412- assert result == [
413- "[Errno 13] Permission denied: 'forbidden.log'\n Logfile capture disabled"
414- ]
394+ assert result == ["[Errno 13] Permission denied: 'forbidden.log'\n Logfile capture disabled" ]
415395
416396
417397@dbtest
418398def test_watch_works (executor ):
419399 cli = PGCli (pgexecute = executor )
420400
421- def run_with_watch (
422- query , target_call_count = 1 , expected_output = "" , expected_timing = None
423- ):
401+ def run_with_watch (query , target_call_count = 1 , expected_output = "" , expected_timing = None ):
424402 """
425403 :param query: Input to the CLI
426404 :param target_call_count: Number of times the user lets the command run before Ctrl-C
427405 :param expected_output: Substring expected to be found for each executed query
428406 :param expected_timing: value `time.sleep` expected to be called with on every invocation
429407 """
430- with mock .patch .object (cli , "echo_via_pager" ) as mock_echo , mock .patch (
431- "pgcli.main.sleep"
432- ) as mock_sleep :
433- mock_sleep .side_effect = [None ] * (target_call_count - 1 ) + [
434- KeyboardInterrupt
435- ]
408+ with mock .patch .object (cli , "echo_via_pager" ) as mock_echo , mock .patch ("pgcli.main.sleep" ) as mock_sleep :
409+ mock_sleep .side_effect = [None ] * (target_call_count - 1 ) + [KeyboardInterrupt ]
436410 cli .handle_watch_command (query )
437411 # Validate that sleep was called with the right timing
438412 for i in range (target_call_count - 1 ):
@@ -446,16 +420,11 @@ def run_with_watch(
446420 with mock .patch ("pgcli.main.click.secho" ) as mock_secho :
447421 cli .handle_watch_command (r"\watch 2" )
448422 mock_secho .assert_called ()
449- assert (
450- r"\watch cannot be used with an empty query"
451- in mock_secho .call_args_list [0 ][0 ][0 ]
452- )
423+ assert r"\watch cannot be used with an empty query" in mock_secho .call_args_list [0 ][0 ][0 ]
453424
454425 # Usage 1: Run a query and then re-run it with \watch across two prompts.
455426 run_with_watch ("SELECT 111" , expected_output = "111" )
456- run_with_watch (
457- "\\ watch 10" , target_call_count = 2 , expected_output = "111" , expected_timing = 10
458- )
427+ run_with_watch ("\\ watch 10" , target_call_count = 2 , expected_output = "111" , expected_timing = 10 )
459428
460429 # Usage 2: Run a query and \watch via the same prompt.
461430 run_with_watch (
@@ -466,9 +435,7 @@ def run_with_watch(
466435 )
467436
468437 # Usage 3: Re-run the last watched command with a new timing
469- run_with_watch (
470- "\\ watch 5" , target_call_count = 4 , expected_output = "222" , expected_timing = 5
471- )
438+ run_with_watch ("\\ watch 5" , target_call_count = 4 , expected_output = "222" , expected_timing = 5 )
472439
473440
474441def test_missing_rc_dir (tmpdir ):
@@ -482,9 +449,7 @@ def test_quoted_db_uri(tmpdir):
482449 with mock .patch .object (PGCli , "connect" ) as mock_connect :
483450 cli = PGCli (pgclirc_file = str (tmpdir .join ("rcfile" )))
484451 cli .
connect_uri (
"postgres://bar%5E:%[email protected] /testdb%5B" )
485- mock_connect .assert_called_with (
486- database = "testdb[" , host = "baz.com" , user = "bar^" , passwd = "]foo"
487- )
452+ mock_connect .assert_called_with (database = "testdb[" , host = "baz.com" , user = "bar^" , passwd = "]foo" )
488453
489454
490455def test_pg_service_file (tmpdir ):
@@ -544,8 +509,7 @@ def test_ssl_db_uri(tmpdir):
544509 with mock .patch .object (PGCli , "connect" ) as mock_connect :
545510 cli = PGCli (pgclirc_file = str (tmpdir .join ("rcfile" )))
546511 cli .connect_uri (
547- "postgres://bar%5E:%[email protected] /testdb%5B?" 548- "sslmode=verify-full&sslcert=m%79.pem&sslkey=my-key.pem&sslrootcert=c%61.pem"
512+ "postgres://bar%5E:%[email protected] /testdb%5B?sslmode=verify-full&sslcert=m%79.pem&sslkey=my-key.pem&sslrootcert=c%61.pem" 549513 )
550514 mock_connect .assert_called_with (
551515 database = "testdb[" ,
@@ -563,17 +527,13 @@ def test_port_db_uri(tmpdir):
563527 with mock .patch .object (PGCli , "connect" ) as mock_connect :
564528 cli = PGCli (pgclirc_file = str (tmpdir .join ("rcfile" )))
565529 cli .
connect_uri (
"postgres://bar:[email protected] :2543/testdb" )
566- mock_connect .assert_called_with (
567- database = "testdb" , host = "baz.com" , user = "bar" , passwd = "foo" , port = "2543"
568- )
530+ mock_connect .assert_called_with (database = "testdb" , host = "baz.com" , user = "bar" , passwd = "foo" , port = "2543" )
569531
570532
571533def test_multihost_db_uri (tmpdir ):
572534 with mock .patch .object (PGCli , "connect" ) as mock_connect :
573535 cli = PGCli (pgclirc_file = str (tmpdir .join ("rcfile" )))
574- cli .connect_uri (
575- "postgres://bar:[email protected] :2543,baz2.com:2543,baz3.com:2543/testdb" 576- )
536+ cli .
connect_uri (
"postgres://bar:[email protected] :2543,baz2.com:2543,baz3.com:2543/testdb" )
577537 mock_connect .assert_called_with (
578538 database = "testdb" ,
579539 host = "baz1.com,baz2.com,baz3.com" ,
@@ -588,9 +548,7 @@ def test_application_name_db_uri(tmpdir):
588548 mock_pgexecute .return_value = None
589549 cli = PGCli (pgclirc_file = str (tmpdir .join ("rcfile" )))
590550 cli .
connect_uri (
"postgres://[email protected] /?application_name=cow" )
591- mock_pgexecute .assert_called_with (
592- "bar" , "bar" , "" , "baz.com" , "" , "" , notify_callback , application_name = "cow"
593- )
551+ mock_pgexecute .assert_called_with ("bar" , "bar" , "" , "baz.com" , "" , "" , notify_callback , application_name = "cow" )
594552
595553
596554@pytest .mark .parametrize (
0 commit comments