Using relative path for shorter repr.

This commit is contained in:
Roland 2022-01-05 13:40:11 -07:00
parent bedcc3a5e9
commit 3284a210bf
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
2 changed files with 6 additions and 1 deletions

View file

@ -18,7 +18,7 @@ class MediaPath:
self._path = path.absolute()
def __repr__(self):
return f'<MediaPath path={self.path}>'
return f'<MediaPath path={self.path.relative_to(get_media_directory())}>'
@classmethod
def _validate_path(cls, path: PATH_TYPE):

View file

@ -43,3 +43,8 @@ class TestMediaPath(unittest.TestCase):
# Error is raised when the path is not in the media path.
self.assertRaises(ValueError, MediaPath, '/tmp/foo')
def test_repr(self):
d = MediaPath('foo')
assert self.test_dir.name not in repr(d)
assert self.test_dir.name not in str(d)