@@ -160,10 +160,8 @@ def setUp(self):
160160
161161 def tearDown (self ):
162162 import os
163- if self .old_env :
164- os .environ ['GOOGLE_APPLICATION_CREDENTIALS' ] = self .old_env
165- elif (not self .old_env and
166- 'GOOGLE_APPLICATION_CREDENTIALS' in os .environ ):
163+ if (not self .old_env and
164+ 'GOOGLE_APPLICATION_CREDENTIALS' in os .environ ):
167165 del os .environ ['GOOGLE_APPLICATION_CREDENTIALS' ]
168166
169167 def test_success (self ):
@@ -177,9 +175,6 @@ def test_success(self):
177175 self .assertEqual ('test-project-id' , self ._callFUT ())
178176
179177 def test_no_environment (self ):
180- import os
181- if 'GOOGLE_APPLICATION_CREDENTIALS' in os .environ :
182- del os .environ ['GOOGLE_APPLICATION_CREDENTIALS' ]
183178 self .assertEqual (None , self ._callFUT ())
184179
185180
@@ -188,30 +183,22 @@ class Test__get_default_service_project_id(unittest2.TestCase):
188183 def callFUT (self , project_result = '' ):
189184 from gcloud ._helpers import _default_service_project_id
190185 import subprocess
191- self .check_output_called_with = []
192186
193- def check_output_mock ( called_with = None ):
194- self . check_output_called_with = called_with
195- return project_result
187+ def popen_communicate_mock ( popen_object ):
188+ popen_object . kill ()
189+ return ( project_result ,)
196190
197191 from gcloud ._testing import _Monkey
198- with _Monkey (subprocess , check_output = check_output_mock ):
199- return _default_service_project_id (), self . check_output_called_with
192+ with _Monkey (subprocess . Popen , communicate = popen_communicate_mock ):
193+ return _default_service_project_id ()
200194
201195 def test_read_from_cli_info (self ):
202- project_id , called_with = self .callFUT ('Project: [test-project-id]' )
196+ project_id = self .callFUT (b 'Project: [test-project-id]' )
203197 self .assertEqual ('test-project-id' , project_id )
204- self .assertEqual (['gcloud' , 'info' ], called_with )
205-
206- def test_cli_info_not_set (self ):
207- project_id , called_with = self .callFUT ()
208- self .assertEqual (None , project_id )
209- self .assertEqual (['gcloud' , 'info' ], called_with )
210198
211199 def test_info_value_not_present (self ):
212- project_id , called_with = self .callFUT ('Active Configuration' )
200+ project_id = self .callFUT (b 'Active Configuration' )
213201 self .assertEqual (None , project_id )
214- self .assertEqual (['gcloud' , 'info' ], called_with )
215202
216203
217204class Test__compute_engine_id (unittest2 .TestCase ):
0 commit comments