mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00
Merge pull request #2451 from xonsh/epadd
EnvPath __add__() and __radd__() methods
This commit is contained in:
commit
983b3205f1
3 changed files with 36 additions and 0 deletions
13
news/epadd.rst
Normal file
13
news/epadd.rst
Normal file
|
@ -0,0 +1,13 @@
|
|||
**Added:**
|
||||
|
||||
* Added ``__add__()`` and ``__radd__()`` methods to ``EnvPath``.
|
||||
|
||||
**Changed:** None
|
||||
|
||||
**Deprecated:** None
|
||||
|
||||
**Removed:** None
|
||||
|
||||
**Fixed:** None
|
||||
|
||||
**Security:** None
|
|
@ -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))
|
||||
|
|
|
@ -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."""
|
||||
|
|
Loading…
Add table
Reference in a new issue