@@ -22,7 +22,7 @@ def _callFUT(self, client):
2222 from google .cloud .bigtable .client import _make_data_stub
2323 return _make_data_stub (client )
2424
25- def test_it (self ):
25+ def test_without_emulator (self ):
2626 from unit_tests ._testing import _Monkey
2727 from google .cloud .bigtable import client as MUT
2828
@@ -50,14 +50,39 @@ def mock_make_secure_stub(*args):
5050 ),
5151 ])
5252
53+ def test_with_emulator (self ):
54+ from unit_tests ._testing import _Monkey
55+ from google .cloud .bigtable import client as MUT
56+
57+ emulator_host = object ()
58+ client = _Client (None , None , emulator_host = emulator_host )
59+
60+ fake_stub = object ()
61+ make_insecure_stub_args = []
62+
63+ def mock_make_insecure_stub (* args ):
64+ make_insecure_stub_args .append (args )
65+ return fake_stub
66+
67+ with _Monkey (MUT , make_insecure_stub = mock_make_insecure_stub ):
68+ result = self ._callFUT (client )
69+
70+ self .assertIs (result , fake_stub )
71+ self .assertEqual (make_insecure_stub_args , [
72+ (
73+ MUT .bigtable_pb2 .BigtableStub ,
74+ emulator_host ,
75+ ),
76+ ])
77+
5378
5479class Test__make_instance_stub (unittest .TestCase ):
5580
5681 def _callFUT (self , client ):
5782 from google .cloud .bigtable .client import _make_instance_stub
5883 return _make_instance_stub (client )
5984
60- def test_it (self ):
85+ def test_without_emulator (self ):
6186 from unit_tests ._testing import _Monkey
6287 from google .cloud .bigtable import client as MUT
6388
@@ -85,14 +110,39 @@ def mock_make_secure_stub(*args):
85110 ),
86111 ])
87112
113+ def test_with_emulator (self ):
114+ from unit_tests ._testing import _Monkey
115+ from google .cloud .bigtable import client as MUT
116+
117+ emulator_host = object ()
118+ client = _Client (None , None , emulator_host = emulator_host )
119+
120+ fake_stub = object ()
121+ make_insecure_stub_args = []
122+
123+ def mock_make_insecure_stub (* args ):
124+ make_insecure_stub_args .append (args )
125+ return fake_stub
126+
127+ with _Monkey (MUT , make_insecure_stub = mock_make_insecure_stub ):
128+ result = self ._callFUT (client )
129+
130+ self .assertIs (result , fake_stub )
131+ self .assertEqual (make_insecure_stub_args , [
132+ (
133+ MUT .bigtable_instance_admin_pb2 .BigtableInstanceAdminStub ,
134+ emulator_host ,
135+ ),
136+ ])
137+
88138
89139class Test__make_operations_stub (unittest .TestCase ):
90140
91141 def _callFUT (self , client ):
92142 from google .cloud .bigtable .client import _make_operations_stub
93143 return _make_operations_stub (client )
94144
95- def test_it (self ):
145+ def test_without_emulator (self ):
96146 from unit_tests ._testing import _Monkey
97147 from google .cloud .bigtable import client as MUT
98148
@@ -120,14 +170,39 @@ def mock_make_secure_stub(*args):
120170 ),
121171 ])
122172
173+ def test_with_emulator (self ):
174+ from unit_tests ._testing import _Monkey
175+ from google .cloud .bigtable import client as MUT
176+
177+ emulator_host = object ()
178+ client = _Client (None , None , emulator_host = emulator_host )
179+
180+ fake_stub = object ()
181+ make_insecure_stub_args = []
182+
183+ def mock_make_insecure_stub (* args ):
184+ make_insecure_stub_args .append (args )
185+ return fake_stub
186+
187+ with _Monkey (MUT , make_insecure_stub = mock_make_insecure_stub ):
188+ result = self ._callFUT (client )
189+
190+ self .assertIs (result , fake_stub )
191+ self .assertEqual (make_insecure_stub_args , [
192+ (
193+ MUT .operations_grpc_pb2 .OperationsStub ,
194+ emulator_host ,
195+ ),
196+ ])
197+
123198
124199class Test__make_table_stub (unittest .TestCase ):
125200
126201 def _callFUT (self , client ):
127202 from google .cloud .bigtable .client import _make_table_stub
128203 return _make_table_stub (client )
129204
130- def test_it (self ):
205+ def test_without_emulator (self ):
131206 from unit_tests ._testing import _Monkey
132207 from google .cloud .bigtable import client as MUT
133208
@@ -155,6 +230,31 @@ def mock_make_secure_stub(*args):
155230 ),
156231 ])
157232
233+ def test_with_emulator (self ):
234+ from unit_tests ._testing import _Monkey
235+ from google .cloud .bigtable import client as MUT
236+
237+ emulator_host = object ()
238+ client = _Client (None , None , emulator_host = emulator_host )
239+
240+ fake_stub = object ()
241+ make_insecure_stub_args = []
242+
243+ def mock_make_insecure_stub (* args ):
244+ make_insecure_stub_args .append (args )
245+ return fake_stub
246+
247+ with _Monkey (MUT , make_insecure_stub = mock_make_insecure_stub ):
248+ result = self ._callFUT (client )
249+
250+ self .assertIs (result , fake_stub )
251+ self .assertEqual (make_insecure_stub_args , [
252+ (
253+ MUT .bigtable_table_admin_pb2 .BigtableTableAdminStub ,
254+ emulator_host ,
255+ ),
256+ ])
257+
158258
159259class TestClient (unittest .TestCase ):
160260
@@ -532,9 +632,10 @@ def __eq__(self, other):
532632
533633class _Client (object ):
534634
535- def __init__ (self , credentials , user_agent ):
635+ def __init__ (self , credentials , user_agent , emulator_host = None ):
536636 self .credentials = credentials
537637 self .user_agent = user_agent
638+ self .emulator_host = emulator_host
538639
539640
540641class _MakeStubMock (object ):
0 commit comments