Merge pull request #2451 from xonsh/epadd

EnvPath __add__() and __radd__() methods
This commit is contained in:
Morten Enemark Lund 2017-07-22 23:15:17 +02:00 committed by GitHub
commit 983b3205f1
3 changed files with 36 additions and 0 deletions

13
news/epadd.rst Normal file
View file

@ -0,0 +1,13 @@
**Added:**
* Added ``__add__()`` and ``__radd__()`` methods to ``EnvPath``.
**Changed:** None
**Deprecated:** None
**Removed:** None
**Fixed:** None
**Security:** None

View file

@ -684,6 +684,19 @@ def test_env_path_to_str(inp, exp):
assert exp == obs
@pytest.mark.parametrize('left, right, exp', [
(EnvPath(['/home/wakka']), ['/home/jawaka'], EnvPath(['/home/wakka', '/home/jawaka'])),
(['a'], EnvPath(['b']), EnvPath(['a', 'b'])),
(EnvPath(['c']), EnvPath(['d']), EnvPath(['c', 'd'])),
])
def test_env_path_add(left, right, exp):
obs = left + right
assert is_env_path(obs)
assert exp == obs
# helper
def expand(path):
return os.path.expanduser(os.path.expandvars(path))

View file

@ -218,6 +218,16 @@ class EnvPath(collections.MutableSequence):
p.breakable()
p.pretty(item)
def __add__(self, other):
if isinstance(other, EnvPath):
other = other._l
return EnvPath(self._l + other)
def __radd__(self, other):
if isinstance(other, EnvPath):
other = other._l
return EnvPath(other + self._l)
class DefaultNotGivenType(object):
"""Singleton for representing when no default value is given."""