Skip to content

Commit

Permalink
Merge pull request #392 from joke2k/fix/path-eq
Browse files Browse the repository at this point in the history
Fix `environ.Path.__eq__()` to compare paths correctly
  • Loading branch information
sergeyklay authored Jun 15, 2022
2 parents ea30823 + 16de011 commit a2e61c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Fixed
`#357 <https://github.com/joke2k/django-environ/issues/357>`_.
- Fix documentation regarding unsafe characters in URLs
`#220 <https://github.com/joke2k/django-environ/issues/220>`_.
- Fix ``environ.Path.__eq__()`` to compare paths correctly
`#86 <https://github.com/joke2k/django-environ/issues/86>`_
`#197 <https://github.com/joke2k/django-environ/issues/197>`_.


`v0.8.1`_ - 20-October-2021
Expand Down
20 changes: 13 additions & 7 deletions environ/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,16 @@ def path(self, var, default=NOTSET, **kwargs):
def get_value(self, var, cast=None, default=NOTSET, parse_default=False):
"""Return value for given environment variable.
:param var: Name of variable.
:param cast: Type to cast return value as.
:param default: If var not present in environ, return this instead.
:param parse_default: force to parse default..
:returns: Value from environment or default (if set)
:param str var:
Name of variable.
:param collections.abc.Callable or None cast:
Type to cast return value as.
:param default:
If var not present in environ, return this instead.
:param bool parse_default:
Force to parse default.
:returns: Value from environment or default (if set).
:rtype: typing.IO[typing.Any]
"""

logger.debug("get '{}' casted as '{}' with default '{}'".format(
Expand Down Expand Up @@ -997,7 +1001,9 @@ def __call__(self, *paths, **kwargs):
return self._absolute_join(self.__root__, *paths, **kwargs)

def __eq__(self, other):
return self.__root__ == other.__root__
if isinstance(other, Path):
return self.__root__ == other.__root__
return self.__root__ == other

def __ne__(self, other):
return not self.__eq__(other)
Expand Down
10 changes: 9 additions & 1 deletion tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_repr(volume):
assert root.__repr__() == '<Path:/home>'


def test_comparison():
def test_comparison(volume):
root = Path('/home')
assert root.__eq__(Path('/home'))
assert root in Path('/')
Expand All @@ -62,6 +62,14 @@ def test_comparison():
assert Path('/home/foo/').__fspath__() == str(Path('/home/foo/'))
assert ~Path('/home') == Path('/')

if sys.platform == 'win32':
assert Path('/home') == '{}home'.format(volume)
assert '{}home'.format(volume) == Path('/home')
else:
assert Path('/home') == '/home'
assert '/home' == Path('/home')

assert Path('/home') != '/usr'

def test_sum():
"""Make sure Path correct handle __add__."""
Expand Down

0 comments on commit a2e61c8

Please sign in to comment.