9
9
import redis
10
10
from redis .connection import ssl_available , to_bool
11
11
12
- from .conftest import _get_client , skip_if_redis_enterprise , skip_if_server_version_lt
12
+ from .conftest import _get_client , skip_if_redis_enterprise , \
13
+ skip_if_server_version_lt
13
14
from .test_pubsub import wait_for_message
14
15
15
16
@@ -45,7 +46,8 @@ def get_pool(
45
46
def test_connection_creation (self ):
46
47
connection_kwargs = {"foo" : "bar" , "biz" : "baz" }
47
48
pool = self .get_pool (
48
- connection_kwargs = connection_kwargs , connection_class = DummyConnection
49
+ connection_kwargs = connection_kwargs ,
50
+ connection_class = DummyConnection
49
51
)
50
52
connection = pool .get_connection ("_" )
51
53
assert isinstance (connection , DummyConnection )
@@ -60,7 +62,8 @@ def test_multiple_connections(self, master_host):
60
62
61
63
def test_max_connections (self , master_host ):
62
64
connection_kwargs = {"host" : master_host [0 ], "port" : master_host [1 ]}
63
- pool = self .get_pool (max_connections = 2 , connection_kwargs = connection_kwargs )
65
+ pool = self .get_pool (max_connections = 2 ,
66
+ connection_kwargs = connection_kwargs )
64
67
pool .get_connection ("_" )
65
68
pool .get_connection ("_" )
66
69
with pytest .raises (redis .ConnectionError ):
@@ -82,7 +85,8 @@ def test_repr_contains_db_info_tcp(self):
82
85
"client_name" : "test-client" ,
83
86
}
84
87
pool = self .get_pool (
85
- connection_kwargs = connection_kwargs , connection_class = redis .Connection
88
+ connection_kwargs = connection_kwargs ,
89
+ connection_class = redis .Connection
86
90
)
87
91
expected = (
88
92
"ConnectionPool<Connection<"
@@ -91,7 +95,8 @@ def test_repr_contains_db_info_tcp(self):
91
95
assert repr (pool ) == expected
92
96
93
97
def test_repr_contains_db_info_unix (self ):
94
- connection_kwargs = {"path" : "/abc" , "db" : 1 , "client_name" : "test-client" }
98
+ connection_kwargs = {"path" : "/abc" , "db" : 1 ,
99
+ "client_name" : "test-client" }
95
100
pool = self .get_pool (
96
101
connection_kwargs = connection_kwargs ,
97
102
connection_class = redis .UnixDomainSocketConnection ,
@@ -330,7 +335,8 @@ def test_boolean_parsing(self):
330
335
assert expected is to_bool (value )
331
336
332
337
def test_client_name_in_querystring (self ):
333
- pool = redis .ConnectionPool .from_url ("redis://location?client_name=test-client" )
338
+ pool = redis .ConnectionPool .from_url (
339
+ "redis://location?client_name=test-client" )
334
340
assert pool .connection_kwargs ["client_name" ] == "test-client"
335
341
336
342
def test_invalid_extra_typed_querystring_options (self ):
@@ -342,7 +348,8 @@ def test_invalid_extra_typed_querystring_options(self):
342
348
def test_extra_querystring_options (self ):
343
349
pool = redis .ConnectionPool .from_url ("redis://localhost?a=1&b=2" )
344
350
assert pool .connection_class == redis .Connection
345
- assert pool .connection_kwargs == {"host" : "localhost" , "a" : "1" , "b" : "2" }
351
+ assert pool .connection_kwargs == {"host" : "localhost" , "a" : "1" ,
352
+ "b" : "2" }
346
353
347
354
def test_calling_from_subclass_returns_correct_instance (self ):
348
355
pool = redis .BlockingConnectionPool .from_url ("redis://localhost" )
@@ -437,13 +444,15 @@ def test_db_in_querystring(self):
437
444
}
438
445
439
446
def test_client_name_in_querystring (self ):
440
- pool = redis .ConnectionPool .from_url ("redis://location?client_name=test-client" )
447
+ pool = redis .ConnectionPool .from_url (
448
+ "redis://location?client_name=test-client" )
441
449
assert pool .connection_kwargs ["client_name" ] == "test-client"
442
450
443
451
def test_extra_querystring_options (self ):
444
452
pool = redis .ConnectionPool .from_url ("unix:///socket?a=1&b=2" )
445
453
assert pool .connection_class == redis .UnixDomainSocketConnection
446
- assert pool .connection_kwargs == {"path" : "/socket" , "a" : "1" , "b" : "2" }
454
+ assert pool .connection_kwargs == {"path" : "/socket" , "a" : "1" ,
455
+ "b" : "2" }
447
456
448
457
449
458
@pytest .mark .skipif (not ssl_available , reason = "SSL not installed" )
@@ -471,10 +480,12 @@ def get_connection(self, *args, **kwargs):
471
480
pool = DummyConnectionPool .from_url ("rediss://?ssl_cert_reqs=required" )
472
481
assert pool .get_connection ("_" ).cert_reqs == ssl .CERT_REQUIRED
473
482
474
- pool = DummyConnectionPool .from_url ("rediss://?ssl_check_hostname=False" )
483
+ pool = DummyConnectionPool .from_url (
484
+ "rediss://?ssl_check_hostname=False" )
475
485
assert pool .get_connection ("_" ).check_hostname is False
476
486
477
- pool = DummyConnectionPool .from_url ("rediss://?ssl_check_hostname=True" )
487
+ pool = DummyConnectionPool .from_url (
488
+ "rediss://?ssl_check_hostname=True" )
478
489
assert pool .get_connection ("_" ).check_hostname is True
479
490
480
491
@@ -497,7 +508,6 @@ def test_on_connect_error(self):
497
508
@pytest .mark .onlynoncluster
498
509
@skip_if_server_version_lt ('2.8.8' )
499
510
@skip_if_redis_enterprise ()
500
-
501
511
def test_busy_loading_disconnects_socket (self , r ):
502
512
"""
503
513
If Redis raises a LOADING error, the connection should be
@@ -510,15 +520,15 @@ def test_busy_loading_disconnects_socket(self, r):
510
520
@pytest .mark .onlynoncluster
511
521
@skip_if_server_version_lt ('2.8.8' )
512
522
@skip_if_redis_enterprise ()
513
-
514
523
def test_busy_loading_from_pipeline_immediate_command (self , r ):
515
524
"""
516
525
BusyLoadingErrors should raise from Pipelines that execute a
517
526
command immediately, like WATCH does.
518
527
"""
519
528
pipe = r .pipeline ()
520
529
with pytest .raises (redis .BusyLoadingError ):
521
- pipe .immediate_execute_command ("DEBUG" , "ERROR" , "LOADING fake message" )
530
+ pipe .immediate_execute_command ("DEBUG" , "ERROR" ,
531
+ "LOADING fake message" )
522
532
pool = r .connection_pool
523
533
assert not pipe .connection
524
534
assert len (pool ._available_connections ) == 1
@@ -527,7 +537,6 @@ def test_busy_loading_from_pipeline_immediate_command(self, r):
527
537
@pytest .mark .onlynoncluster
528
538
@skip_if_server_version_lt ('2.8.8' )
529
539
@skip_if_redis_enterprise ()
530
-
531
540
def test_busy_loading_from_pipeline (self , r ):
532
541
"""
533
542
BusyLoadingErrors should be raised from a pipeline execution
@@ -544,7 +553,6 @@ def test_busy_loading_from_pipeline(self, r):
544
553
545
554
@skip_if_server_version_lt ('2.8.8' )
546
555
@skip_if_redis_enterprise ()
547
-
548
556
def test_read_only_error (self , r ):
549
557
"READONLY errors get turned in ReadOnlyError exceptions"
550
558
with pytest .raises (redis .ReadOnlyError ):
@@ -578,7 +586,8 @@ def test_connect_no_auth_supplied_when_required(self, r):
578
586
"""
579
587
with pytest .raises (redis .AuthenticationError ):
580
588
r .execute_command (
581
- "DEBUG" , "ERROR" , "ERR Client sent AUTH, but no password is set"
589
+ "DEBUG" , "ERROR" ,
590
+ "ERR Client sent AUTH, but no password is set"
582
591
)
583
592
584
593
@skip_if_redis_enterprise ()
@@ -592,7 +601,8 @@ def test_connect_invalid_password_supplied(self, r):
592
601
class TestMultiConnectionClient :
593
602
@pytest .fixture ()
594
603
def r (self , request ):
595
- return _get_client (redis .Redis , request , single_connection_client = False )
604
+ return _get_client (redis .Redis , request ,
605
+ single_connection_client = False )
596
606
597
607
def test_multi_connection_command (self , r ):
598
608
assert not r .connection
@@ -606,7 +616,8 @@ class TestHealthCheck:
606
616
607
617
@pytest .fixture ()
608
618
def r (self , request ):
609
- return _get_client (redis .Redis , request , health_check_interval = self .interval )
619
+ return _get_client (redis .Redis , request ,
620
+ health_check_interval = self .interval )
610
621
611
622
def assert_interval_advanced (self , connection ):
612
623
diff = connection .next_health_check - time .time ()
@@ -622,7 +633,7 @@ def test_arbitrary_command_invokes_health_check(self, r):
622
633
r .get ("foo" )
623
634
r .connection .next_health_check = time .time ()
624
635
with mock .patch .object (
625
- r .connection , "send_command" , wraps = r .connection .send_command
636
+ r .connection , "send_command" , wraps = r .connection .send_command
626
637
) as m :
627
638
r .get ("foo" )
628
639
m .assert_called_with ("PING" , check_health = False )
@@ -638,7 +649,7 @@ def test_arbitrary_command_advances_next_health_check(self, r):
638
649
def test_health_check_not_invoked_within_interval (self , r ):
639
650
r .get ("foo" )
640
651
with mock .patch .object (
641
- r .connection , "send_command" , wraps = r .connection .send_command
652
+ r .connection , "send_command" , wraps = r .connection .send_command
642
653
) as m :
643
654
r .get ("foo" )
644
655
ping_call_spec = (("PING" ,), {"check_health" : False })
@@ -649,7 +660,8 @@ def test_health_check_in_pipeline(self, r):
649
660
pipe .connection = pipe .connection_pool .get_connection ("_" )
650
661
pipe .connection .next_health_check = 0
651
662
with mock .patch .object (
652
- pipe .connection , "send_command" , wraps = pipe .connection .send_command
663
+ pipe .connection , "send_command" ,
664
+ wraps = pipe .connection .send_command
653
665
) as m :
654
666
responses = pipe .set ("foo" , "bar" ).get ("foo" ).execute ()
655
667
m .assert_any_call ("PING" , check_health = False )
@@ -660,7 +672,8 @@ def test_health_check_in_transaction(self, r):
660
672
pipe .connection = pipe .connection_pool .get_connection ("_" )
661
673
pipe .connection .next_health_check = 0
662
674
with mock .patch .object (
663
- pipe .connection , "send_command" , wraps = pipe .connection .send_command
675
+ pipe .connection , "send_command" ,
676
+ wraps = pipe .connection .send_command
664
677
) as m :
665
678
responses = pipe .set ("foo" , "bar" ).get ("foo" ).execute ()
666
679
m .assert_any_call ("PING" , check_health = False )
@@ -672,7 +685,8 @@ def test_health_check_in_watched_pipeline(self, r):
672
685
pipe .connection = pipe .connection_pool .get_connection ("_" )
673
686
pipe .connection .next_health_check = 0
674
687
with mock .patch .object (
675
- pipe .connection , "send_command" , wraps = pipe .connection .send_command
688
+ pipe .connection , "send_command" ,
689
+ wraps = pipe .connection .send_command
676
690
) as m :
677
691
pipe .watch ("foo" )
678
692
# the health check should be called when watching
@@ -696,7 +710,7 @@ def test_health_check_in_pubsub_before_subscribe(self, r):
696
710
p .connection = p .connection_pool .get_connection ("_" )
697
711
p .connection .next_health_check = 0
698
712
with mock .patch .object (
699
- p .connection , "send_command" , wraps = p .connection .send_command
713
+ p .connection , "send_command" , wraps = p .connection .send_command
700
714
) as m :
701
715
assert not p .subscribed
702
716
p .subscribe ("foo" )
@@ -718,7 +732,7 @@ def test_health_check_in_pubsub_after_subscribed(self, r):
718
732
p .connection = p .connection_pool .get_connection ("_" )
719
733
p .connection .next_health_check = 0
720
734
with mock .patch .object (
721
- p .connection , "send_command" , wraps = p .connection .send_command
735
+ p .connection , "send_command" , wraps = p .connection .send_command
722
736
) as m :
723
737
p .subscribe ("foo" )
724
738
subscribe_message = wait_for_message (p )
@@ -746,7 +760,8 @@ def test_health_check_in_pubsub_after_subscribed(self, r):
746
760
assert wait_for_message (p ) is None
747
761
# now that the connection is subscribed, the pubsub health
748
762
# check should have taken over and include the HEALTH_CHECK_MESSAGE
749
- m .assert_any_call ("PING" , p .HEALTH_CHECK_MESSAGE , check_health = False )
763
+ m .assert_any_call ("PING" , p .HEALTH_CHECK_MESSAGE ,
764
+ check_health = False )
750
765
self .assert_interval_advanced (p .connection )
751
766
752
767
def test_health_check_in_pubsub_poll (self , r ):
@@ -757,7 +772,7 @@ def test_health_check_in_pubsub_poll(self, r):
757
772
p = r .pubsub ()
758
773
p .connection = p .connection_pool .get_connection ("_" )
759
774
with mock .patch .object (
760
- p .connection , "send_command" , wraps = p .connection .send_command
775
+ p .connection , "send_command" , wraps = p .connection .send_command
761
776
) as m :
762
777
p .subscribe ("foo" )
763
778
subscribe_message = wait_for_message (p )
@@ -777,5 +792,6 @@ def test_health_check_in_pubsub_poll(self, r):
777
792
# should be advanced
778
793
p .connection .next_health_check = 0
779
794
assert wait_for_message (p ) is None
780
- m .assert_called_with ("PING" , p .HEALTH_CHECK_MESSAGE , check_health = False )
795
+ m .assert_called_with ("PING" , p .HEALTH_CHECK_MESSAGE ,
796
+ check_health = False )
781
797
self .assert_interval_advanced (p .connection )
0 commit comments