Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_pull_api(self):
try:
from cStringIO import StringIO
except ImportError:
from io import StringIO
from vcstool.commands.pull import main
stdout_stderr = StringIO()
# change and restore cwd
cwd_bck = os.getcwd()
os.chdir(TEST_WORKSPACE)
try:
# change and restore USE_COLOR flag
from vcstool import executor
use_color_bck = executor.USE_COLOR
executor.USE_COLOR = False
try:
# change and restore os.environ
env_bck = os.environ
os.environ = dict(os.environ)
os.environ.update(
LANG='en_US.UTF-8',
PYTHONPATH=(
os.path.dirname(os.path.dirname(__file__)) +
os.pathsep + os.environ.get('PYTHONPATH', '')))
try:
rc = main(
args=['--workers', '1'],
stdout=stdout_stderr, stderr=stdout_stderr)
finally:
os.environ = env_bck
# change and restore os.environ
env_bck = os.environ
os.environ = dict(os.environ)
os.environ.update(
LANG='en_US.UTF-8',
PYTHONPATH=(
os.path.dirname(os.path.dirname(__file__)) +
os.pathsep + os.environ.get('PYTHONPATH', '')))
try:
rc = main(
args=['--workers', '1'],
stdout=stdout_stderr, stderr=stdout_stderr)
finally:
os.environ = env_bck
finally:
executor.USE_COLOR = use_color_bck
finally:
os.chdir(cwd_bck)
assert rc == 1
expected = get_expected_output('pull').decode()
assert stdout_stderr.getvalue() == expected
def test_pull_api(self):
try:
from cStringIO import StringIO
except ImportError:
from io import StringIO
from vcstool.commands.pull import main
stdout_stderr = StringIO()
# change and restore cwd
cwd_bck = os.getcwd()
os.chdir(TEST_WORKSPACE)
try:
# change and restore USE_COLOR flag
from vcstool import executor
use_color_bck = executor.USE_COLOR
executor.USE_COLOR = False
try:
# change and restore os.environ
env_bck = os.environ
os.environ = dict(os.environ)
os.environ.update(
LANG='en_US.UTF-8',
PYTHONPATH=(
os.path.dirname(os.path.dirname(__file__)) +
os.pathsep + os.environ.get('PYTHONPATH', '')))
try:
rc = main(
args=['--workers', '1'],
stdout=stdout_stderr, stderr=stdout_stderr)
finally:
os.environ = env_bck
finally:
def _check_color(self, cmd):
if not USE_COLOR:
return
# check if user uses colorization
if GitClient._config_color_is_auto is None:
_cmd = [GitClient._executable, 'config', '--get', 'color.ui']
result = self._run_command(_cmd)
GitClient._config_color_is_auto = result['output'] in ['', 'auto']
# inject arguments to force colorization
if GitClient._config_color_is_auto:
cmd[1:1] = '-c', 'color.ui=always'
def _check_color(self, cmd):
if not USE_COLOR:
return
with HgClient._config_color_lock:
# check if user uses colorization
if HgClient._config_color is None:
HgClient._config_color = False
# check if config extension is available
_cmd = [HgClient._executable, 'config', '--help']
result = self._run_command(_cmd)
if result['returncode']:
return
# check if color extension is available and not disabled
_cmd = [HgClient._executable, 'config', 'extensions.color']
result = self._run_command(_cmd)
if result['returncode'] or result['output'].startswith('!'):
return
# check if color mode is not off or not set