diff --git a/mutapath/immutapath.py b/mutapath/immutapath.py index 0e6ae18..425e8e5 100644 --- a/mutapath/immutapath.py +++ b/mutapath/immutapath.py @@ -56,6 +56,9 @@ def __repr__(self): def __str__(self): return self._contained + def __hash__(self): + return hash(self._contained) + def __eq__(self, other): if isinstance(other, Path): return self._contained == other._contained diff --git a/mutapath/mutapath.py b/mutapath/mutapath.py index 92b5761..2243026 100644 --- a/mutapath/mutapath.py +++ b/mutapath/mutapath.py @@ -30,6 +30,9 @@ def __repr__(self): def __str__(self): return self._contained + def __hash__(self): + return hash(self._contained) + def merge_tree(self, other, *args, **kwargs): """Move, merge and mutate this path to the given other path.""" self._contained.merge_tree(other, *args, **kwargs) diff --git a/tests/test_immutapath.py b/tests/test_immutapath.py index 0a24726..0d2d933 100644 --- a/tests/test_immutapath.py +++ b/tests/test_immutapath.py @@ -133,3 +133,8 @@ def test_home_root(self): actual = Path("/").home self.assertEqual(excpected, actual) self.assertEqual(excpected.abspath(), actual.abspath()) + + def test_hash(self): + expected = hash(Path("/A") / "B") + actual = hash(Path("/A/B/")) + self.assertEqual(expected, actual) diff --git a/tests/test_mutapath.py b/tests/test_mutapath.py index e0e5822..480983e 100644 --- a/tests/test_mutapath.py +++ b/tests/test_mutapath.py @@ -177,10 +177,15 @@ def test_joinpath(self): self.assertEqual(expected.normpath(), actual.normpath()) def test_capsulation(self): - excpected = MutaPath("/A/B") - actual = MutaPath(MutaPath(excpected)) - self.assertEqual(excpected, actual) + expected = MutaPath("/A/B") + actual = MutaPath(MutaPath(expected)) + self.assertEqual(expected, actual) def test_repr(self): excpected = MutaPath("/A/B") self.assertTrue(repr(excpected).startswith("Path")) + + def test_hash(self): + expected = hash(Path("/A/B")) + actual = hash(MutaPath("/A/B/")) + self.assertEqual(expected, actual)