Specify HGRCPATH for Hg integration tests to make test environment hermetic.

Summary:
Note that we must specify quite a few extensions to get behavior that is
representative of how Hg works at Facebook.

Reviewed By: DurhamG

Differential Revision: D5057478

fbshipit-source-id: ee774a9b8dcebe82e4b19cc52f9b0b5a53e6420c
This commit is contained in:
Michael Bolin 2017-05-15 10:54:42 -07:00 committed by Facebook Github Bot
parent 5ce1151eed
commit 145ca986a7
3 changed files with 33 additions and 13 deletions

View File

@ -8,7 +8,6 @@
# of patent rights can be found in the PATENTS file in the same directory.
from ...lib import find_executables, hgrepo, testcase
from pathlib import Path
import configparser
import os
@ -66,14 +65,29 @@ class HgExtensionTestBase(testcase.EdenTestCase):
def setup_eden_test(self):
super().setup_eden_test()
# Create or update an ~/.hgrc to ensure ui.username is defined.
hgrc = os.path.join(os.environ['HOME'], '.hgrc')
Path(hgrc).touch()
# Create an hgrc to use as the $HGRCPATH.
hgrc = os.path.join(self.tmp_dir, 'hgrc_for_self_dot_repo')
config = configparser.ConfigParser()
config.read(hgrc)
if 'ui' not in config:
config['ui'] = {}
config['ui']['username'] = 'Kevin Flynn <lightcyclist@example.com>'
config['ui'] = {
'username': 'Kevin Flynn <lightcyclist@example.com>',
}
config['experimental'] = {
'evolution': 'createmarkers',
'evolutioncommands': 'prev next split fold obsolete metaedit',
}
config['extensions'] = {
'evolve': '',
'fbamend': '',
'fbhistedit': '',
'fsmonitor': '',
'histedit': '',
'inhibit': '',
'purge': '',
'rebase': '',
'reset': '',
'strip': '',
'tweakdefaults': '',
}
with open(hgrc, 'w') as f:
config.write(f)
@ -81,7 +95,7 @@ class HgExtensionTestBase(testcase.EdenTestCase):
self.backing_repo_name = 'backing_repo'
self.mount = os.path.join(self.mounts_dir, self.backing_repo_name)
self.backing_repo = self.create_repo(self.backing_repo_name,
hgrepo.HgRepository)
hgrepo.HgRepository, hgrc=hgrc)
self.populate_backing_repo(self.backing_repo)
self.eden.add_repository(self.backing_repo_name, self.backing_repo.path)
@ -91,7 +105,7 @@ class HgExtensionTestBase(testcase.EdenTestCase):
self.eden.clone(self.backing_repo_name, self.mount)
# Now create the repository object that refers to the eden client
self.repo = hgrepo.HgRepository(self.mount)
self.repo = hgrepo.HgRepository(self.mount, hgrc=hgrc)
def populate_backing_repo(self, repo):
raise NotImplementedError('individual test classes must implement '

View File

@ -50,10 +50,16 @@ class HgError(subprocess.CalledProcessError):
class HgRepository(repobase.Repository):
def __init__(self, path):
def __init__(self, path, hgrc=None):
'''
If hgrc is specified, it will be used as the value of the HGRCPATH
environment variable when `hg` is run.
'''
super().__init__(path)
self.hg_environment = os.environ.copy()
self.hg_environment['HGPLAIN'] = '1'
if hgrc is not None:
self.hg_environment['HGRCPATH'] = hgrc
self.hg_bin = distutils.spawn.find_executable(
'hg.real') or distutils.spawn.find_executable('hg')

View File

@ -193,7 +193,7 @@ class EdenTestCase(TestParent):
'''
return None
def create_repo(self, name, repo_class):
def create_repo(self, name, repo_class, **kwargs):
'''
Create a new repository.
@ -208,7 +208,7 @@ class EdenTestCase(TestParent):
'''
repo_path = os.path.join(self.repos_dir, name)
os.mkdir(repo_path)
repo = repo_class(repo_path)
repo = repo_class(repo_path, **kwargs)
repo.init()
return repo