1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

unit tests for pip.baseparser.ConfigOptionParser

This commit is contained in:
Marcus Smith 2013-09-15 17:24:44 -07:00
parent 924d243de3
commit ed9e3f49a5

View file

@ -0,0 +1,72 @@
import os
from pip.baseparser import ConfigOptionParser
class TestConfigOptionParser(object):
"""
Unit tests for `pip.baseparser.ConfigOptionParser` (our option parser that
overrides defaults from config files and environment vars)
"""
def setup(self):
self.environ_before = os.environ.copy()
self.parser = ConfigOptionParser(name='test')
self.parser.add_option(
'--normal',
default='v1')
self.parser.add_option(
'--append',
action='append',
default=['v1'])
self.parser.add_option(
'--choice',
action='append',
choices=['v1', 'v2', 'v3'],
type='choice',
default=['v1'])
def teardown(self):
os.environ = self.environ_before
def test_env_non_append_override_default(self):
"""
Test that a PIP_* environ variable overrides a non-append option default.
"""
os.environ['PIP_NORMAL'] = 'v2'
options, args = self.parser.parse_args([])
assert options.normal == 'v2'
def test_env_append_single_override_default(self):
"""
Test that a PIP_* environ variable overrides an append option default.
(where the value is one item)
"""
os.environ['PIP_APPEND'] = 'v2'
options, args = self.parser.parse_args([])
assert options.append == ['v2']
def test_env_append_multi_override_default(self):
"""
Test that a PIP_* environ variable overrides an append option default.
(where the value is multiple)
"""
os.environ['PIP_APPEND'] = 'v1 v2'
options, args = self.parser.parse_args([])
assert options.append == ['v1', 'v2']
def test_env_choice_single_override_default(self):
"""
Test that a PIP_* environ variable overrides a choice option default.
(where the value is one item)
"""
os.environ['PIP_CHOICE'] = 'v2'
options, args = self.parser.parse_args([])
assert options.choice == ['v2']
def test_env_choice_multi_override_default(self):
"""
Test that a PIP_* environ variable overrides a choice option default.
(where the value is multiple)
"""
os.environ['PIP_CHOICE'] = 'v1 v2'
options, args = self.parser.parse_args([])
assert options.choice == ['v1', 'v2']