Skip to content

Commit

Permalink
Merge pull request #1871 from tseaver/avoid-tempdir-clash
Browse files Browse the repository at this point in the history
Avoid a clash over temporary '.config' directory.
  • Loading branch information
tseaver authored Jun 20, 2016
2 parents 08464f7 + b8a088d commit cf481d4
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions gcloud/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ def test_no_environment(self):


class Test__get_default_service_project_id(unittest2.TestCase):
temp_config_path = None
config_path = '.config/gcloud/configurations/'
config_file = 'config_default'

def setUp(self):
import tempfile
import os
self.temp_config_path = tempfile.gettempdir()

self.temp_config_path = tempfile.mkdtemp()

conf_path = os.path.join(self.temp_config_path, self.config_path)
os.makedirs(conf_path)
Expand All @@ -200,23 +200,20 @@ def setUp(self):
conf_file.write('[core]\nproject = test-project-id')

def tearDown(self):
import os
import shutil

if self.temp_config_path:
shutil.rmtree(os.path.join(self.temp_config_path,
'.config'))
shutil.rmtree(self.temp_config_path)

def callFUT(self, project_id=None):
from gcloud._helpers import _default_service_project_id
import os
from gcloud._helpers import _default_service_project_id
from gcloud._testing import _Monkey

def mock_expanduser(path=''):
if project_id and path.startswith('~'):
return self.temp_config_file
return ''

from gcloud._testing import _Monkey
with _Monkey(os.path, expanduser=mock_expanduser):
return _default_service_project_id()

Expand Down

0 comments on commit cf481d4

Please sign in to comment.