From 376abc06554fc78c990b83942fca77a64ba15bd2 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Sat, 27 Oct 2018 12:23:01 +0200 Subject: [PATCH] remove last user of SafeConfigParser Fixes #5059 --- news/5059.trivial | 0 src/pip/_internal/vcs/mercurial.py | 2 +- tests/functional/test_vcs_mercurial.py | 28 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 news/5059.trivial create mode 100644 tests/functional/test_vcs_mercurial.py diff --git a/news/5059.trivial b/news/5059.trivial new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/pip/_internal/vcs/mercurial.py b/src/pip/_internal/vcs/mercurial.py index 17cfb67d1f1..5bca55627f5 100644 --- a/src/pip/_internal/vcs/mercurial.py +++ b/src/pip/_internal/vcs/mercurial.py @@ -45,7 +45,7 @@ def fetch_new(self, dest, url, rev_options): def switch(self, dest, url, rev_options): repo_config = os.path.join(dest, self.dirname, 'hgrc') - config = configparser.SafeConfigParser() + config = configparser.RawConfigParser() try: config.read(repo_config) config.set('paths', 'default', url) diff --git a/tests/functional/test_vcs_mercurial.py b/tests/functional/test_vcs_mercurial.py new file mode 100644 index 00000000000..797a392a5b0 --- /dev/null +++ b/tests/functional/test_vcs_mercurial.py @@ -0,0 +1,28 @@ +""" +Contains functional tests of the Mercurial class. +""" + +import os + +from pip._vendor.six.moves import configparser + +from pip._internal.vcs.mercurial import Mercurial +from tests.lib import need_mercurial + + +@need_mercurial +def test_mercurial_switch_updates_config_file_when_found(tmpdir): + hg = Mercurial() + options = hg.make_rev_options() + hg_dir = os.path.join(tmpdir, '.hg') + os.mkdir(hg_dir) + config = configparser.RawConfigParser() + config.add_section('paths') + config.set('paths', 'default', 'old_url') + hgrc_path = os.path.join(hg_dir, 'hgrc') + with open(hgrc_path, 'w') as f: + config.write(f) + hg.switch(tmpdir, 'new_url', options) + config.read(hgrc_path) + default_path = config.get('paths', 'default') + assert default_path == 'new_url'