/usr/lib/python2.7/dist-packages/zope/testing/renormalizing/__init__.py is in python-zope.testing 4.1.2-0ubuntu7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | ##############################################################################
#
# Copyright (c) 2004 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
#
# This file is a package rather than a module because we want
#
# import doctest
#
# to import the stdlib version of doctest rather than the deprecated
# zope.testing.doctest, and
#
# from __future__ import absolute_import
#
# is not available on Python 2.4 which we still support.
#
##############################################################################
import doctest
class OutputChecker(doctest.OutputChecker):
"""Pattern-normalizing outout checker
"""
def __init__(self, patterns):
self.transformers = list(map(self._cook, patterns))
def __add__(self, other):
if not isinstance(other, RENormalizing):
return NotImplemented
return RENormalizing(self.transformers + other.transformers)
def _cook(self, pattern):
if hasattr(pattern, '__call__'):
return pattern
regexp, replacement = pattern
return lambda text: regexp.sub(replacement, text)
def check_output(self, want, got, optionflags):
if got == want:
return True
for transformer in self.transformers:
want = transformer(want)
got = transformer(got)
return doctest.OutputChecker.check_output(self, want, got, optionflags)
def output_difference(self, example, got, optionflags):
want = example.want
# If want is empty, use original outputter. This is useful
# when setting up tests for the first time. In that case, we
# generally use the differencer to display output, which we evaluate
# by hand.
if not want.strip():
return doctest.OutputChecker.output_difference(
self, example, got, optionflags)
# Dang, this isn't as easy to override as we might wish
original = want
for transformer in self.transformers:
want = transformer(want)
got = transformer(got)
# temporarily hack example with normalized want:
example.want = want
result = doctest.OutputChecker.output_difference(
self, example, got, optionflags)
example.want = original
return result
RENormalizing = OutputChecker
|