summaryrefslogtreecommitdiff
path: root/tests/path.py
diff options
context:
space:
mode:
authorRobert Lehmann <mail@robertlehmann.de>2015-03-20 22:26:32 +0100
committerRobert Lehmann <mail@robertlehmann.de>2015-03-20 22:26:32 +0100
commit657c53b0f571fedcfa4cb347de7573a6dcfd1963 (patch)
treeb8fc308dac95a7f5c04217852160e4201353d18b /tests/path.py
parente2da583be85a74f5ce25200836227aa5b8c85b67 (diff)
downloadsphinx-git-657c53b0f571fedcfa4cb347de7573a6dcfd1963.tar.gz
Fixes #1785: Reduce output for test generators.
Diffstat (limited to 'tests/path.py')
-rwxr-xr-xtests/path.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/tests/path.py b/tests/path.py
index 2f0cdc062..0c4823005 100755
--- a/tests/path.py
+++ b/tests/path.py
@@ -12,7 +12,7 @@ import sys
import shutil
from codecs import open
-from six import PY2, text_type
+from six import PY2, text_type, binary_type
FILESYSTEMENCODING = sys.getfilesystemencoding() or sys.getdefaultencoding()
@@ -142,9 +142,11 @@ class path(text_type):
"""
f = open(self, mode='U', **kwargs)
try:
- return f.read()
+ text = f.read()
finally:
f.close()
+ contents = repr_as(text, '<%s contents>' % self.basename())
+ return contents
def bytes(self):
"""
@@ -205,3 +207,18 @@ class path(text_type):
def __repr__(self):
return '%s(%s)' % (self.__class__.__name__, text_type.__repr__(self))
+
+
+# Lives here only to avoid circular references; use it from util.py!
+class _repr_text(text_type):
+ def __repr__(self):
+ return self._repr
+class _repr_bin(binary_type):
+ def __repr__(self):
+ return self._repr
+
+def repr_as(string, repr_):
+ wrapper = _repr_text if isinstance(string, text_type) else _repr_bin
+ proxy = wrapper(string)
+ proxy._repr = repr_
+ return proxy