diff options
author | Robert Lehmann <mail@robertlehmann.de> | 2015-03-20 22:26:32 +0100 |
---|---|---|
committer | Robert Lehmann <mail@robertlehmann.de> | 2015-03-20 22:26:32 +0100 |
commit | 657c53b0f571fedcfa4cb347de7573a6dcfd1963 (patch) | |
tree | b8fc308dac95a7f5c04217852160e4201353d18b /tests/path.py | |
parent | e2da583be85a74f5ce25200836227aa5b8c85b67 (diff) | |
download | sphinx-git-657c53b0f571fedcfa4cb347de7573a6dcfd1963.tar.gz |
Fixes #1785: Reduce output for test generators.
Diffstat (limited to 'tests/path.py')
-rwxr-xr-x | tests/path.py | 21 |
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 |