mirror of
https://github.com/powerline/powerline.git
synced 2025-07-27 15:54:30 +02:00
Use setUpClass/tearDownClass to deal with VCS repositories
This commit is contained in:
parent
70fabdc02b
commit
53ab31eeb8
@ -34,6 +34,11 @@ else:
|
|||||||
use_mercurial = True
|
use_mercurial = True
|
||||||
|
|
||||||
|
|
||||||
|
GIT_REPO = 'git_repo' + os.environ.get('PYTHON', '')
|
||||||
|
HG_REPO = 'hg_repo' + os.environ.get('PYTHON', '')
|
||||||
|
BZR_REPO = 'bzr_repo' + os.environ.get('PYTHON', '')
|
||||||
|
|
||||||
|
|
||||||
def thread_number():
|
def thread_number():
|
||||||
return len(threading.enumerate())
|
return len(threading.enumerate())
|
||||||
|
|
||||||
@ -551,19 +556,9 @@ class TestVCS(TestCase):
|
|||||||
else:
|
else:
|
||||||
self.assertTrue(repo.status())
|
self.assertTrue(repo.status())
|
||||||
|
|
||||||
old_HGRCPATH = None
|
@classmethod
|
||||||
old_cwd = None
|
def setUpClass(cls):
|
||||||
|
cls.powerline_old_cwd = os.getcwd()
|
||||||
|
|
||||||
GIT_REPO = 'git_repo' + os.environ.get('PYTHON', '')
|
|
||||||
HG_REPO = 'hg_repo' + os.environ.get('PYTHON', '')
|
|
||||||
BZR_REPO = 'bzr_repo' + os.environ.get('PYTHON', '')
|
|
||||||
|
|
||||||
|
|
||||||
def setUpModule():
|
|
||||||
global old_cwd
|
|
||||||
global old_HGRCPATH
|
|
||||||
old_cwd = os.getcwd()
|
|
||||||
os.chdir(os.path.dirname(__file__))
|
os.chdir(os.path.dirname(__file__))
|
||||||
call(['git', 'init', '--quiet', GIT_REPO])
|
call(['git', 'init', '--quiet', GIT_REPO])
|
||||||
assert os.path.isdir(GIT_REPO)
|
assert os.path.isdir(GIT_REPO)
|
||||||
@ -571,7 +566,7 @@ def setUpModule():
|
|||||||
call(['git', 'config', '--local', 'user.email', 'bar@example.org'], cwd=GIT_REPO)
|
call(['git', 'config', '--local', 'user.email', 'bar@example.org'], cwd=GIT_REPO)
|
||||||
call(['git', 'commit', '--allow-empty', '--message', 'Initial commit', '--quiet'], cwd=GIT_REPO)
|
call(['git', 'commit', '--allow-empty', '--message', 'Initial commit', '--quiet'], cwd=GIT_REPO)
|
||||||
if use_mercurial:
|
if use_mercurial:
|
||||||
old_HGRCPATH = os.environ.get('HGRCPATH')
|
cls.powerline_old_HGRCPATH = os.environ.get('HGRCPATH')
|
||||||
os.environ['HGRCPATH'] = ''
|
os.environ['HGRCPATH'] = ''
|
||||||
call(['hg', 'init', HG_REPO])
|
call(['hg', 'init', HG_REPO])
|
||||||
with open(os.path.join(HG_REPO, '.hg', 'hgrc'), 'w') as hgrc:
|
with open(os.path.join(HG_REPO, '.hg', 'hgrc'), 'w') as hgrc:
|
||||||
@ -583,10 +578,8 @@ def setUpModule():
|
|||||||
call(['bzr', 'config', 'nickname=test_powerline'], cwd=BZR_REPO)
|
call(['bzr', 'config', 'nickname=test_powerline'], cwd=BZR_REPO)
|
||||||
call(['bzr', 'config', 'create_signatures=0'], cwd=BZR_REPO)
|
call(['bzr', 'config', 'create_signatures=0'], cwd=BZR_REPO)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def tearDownModule():
|
def tearDownClass(cls):
|
||||||
global old_cwd
|
|
||||||
global old_HGRCPATH
|
|
||||||
for repo_dir in [GIT_REPO] + ([HG_REPO] if use_mercurial else []) + ([BZR_REPO] if use_bzr else []):
|
for repo_dir in [GIT_REPO] + ([HG_REPO] if use_mercurial else []) + ([BZR_REPO] if use_bzr else []):
|
||||||
for root, dirs, files in list(os.walk(repo_dir, topdown=False)):
|
for root, dirs, files in list(os.walk(repo_dir, topdown=False)):
|
||||||
for file in files:
|
for file in files:
|
||||||
@ -595,11 +588,11 @@ def tearDownModule():
|
|||||||
os.rmdir(os.path.join(root, dir))
|
os.rmdir(os.path.join(root, dir))
|
||||||
os.rmdir(repo_dir)
|
os.rmdir(repo_dir)
|
||||||
if use_mercurial:
|
if use_mercurial:
|
||||||
if old_HGRCPATH is None:
|
if cls.powerline_old_HGRCPATH is None:
|
||||||
os.environ.pop('HGRCPATH')
|
os.environ.pop('HGRCPATH')
|
||||||
else:
|
else:
|
||||||
os.environ['HGRCPATH'] = old_HGRCPATH
|
os.environ['HGRCPATH'] = cls.powerline_old_HGRCPATH
|
||||||
os.chdir(old_cwd)
|
os.chdir(cls.powerline_old_cwd)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user