10
10
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11
11
# License for the specific language governing permissions and limitations
12
12
# under the License.
13
-
13
+ from google .cloud import pubsub
14
+ import grpc
15
+ from typing import Optional
14
16
from testcontainers .core .container import DockerContainer
15
17
16
18
@@ -34,9 +36,8 @@ def test_docker_run_pubsub():
34
36
topic_path = publisher.topic_path(pubsub.project, "my-topic")
35
37
topic = publisher.create_topic(topic_path)
36
38
"""
37
-
38
- def __init__ (self , image = "google/cloud-sdk:emulators" ,
39
- project = "test-project" , port = 8432 , ** kwargs ):
39
+ def __init__ (self , image : str = "google/cloud-sdk:emulators" , project : str = "test-project" ,
40
+ port : int = 8432 , ** kwargs ) -> None :
40
41
super (PubSubContainer , self ).__init__ (image = image , ** kwargs )
41
42
self .project = project
42
43
self .port = port
@@ -46,21 +47,19 @@ def __init__(self, image="google/cloud-sdk:emulators",
46
47
project = self .project , port = self .port ,
47
48
))
48
49
49
- def get_pubsub_emulator_host (self ):
50
+ def get_pubsub_emulator_host (self ) -> str :
50
51
return "{host}:{port}" .format (host = self .get_container_host_ip (),
51
52
port = self .get_exposed_port (self .port ))
52
53
53
- def _get_channel (self , channel = None ):
54
+ def _get_channel (self , channel : Optional [ grpc . Channel ] = None ) -> grpc . Channel :
54
55
if channel is None :
55
- import grpc
56
56
return grpc .insecure_channel (target = self .get_pubsub_emulator_host ())
57
+ return channel
57
58
58
- def get_publisher_client (self , ** kwargs ):
59
- from google .cloud import pubsub
59
+ def get_publisher_client (self , ** kwargs ) -> pubsub .PublisherClient :
60
60
kwargs ['channel' ] = self ._get_channel (kwargs .get ('channel' ))
61
61
return pubsub .PublisherClient (** kwargs )
62
62
63
- def get_subscriber_client (self , ** kwargs ):
64
- from google .cloud import pubsub
63
+ def get_subscriber_client (self , ** kwargs ) -> pubsub .SubscriberClient :
65
64
kwargs ['channel' ] = self ._get_channel (kwargs .get ('channel' ))
66
65
return pubsub .SubscriberClient (** kwargs )
0 commit comments