Skip to content

Commit 146d57d

Browse files
authored
Make tests resilient against different ways of calling them. (#345)
1 parent 4da5548 commit 146d57d

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
8.1 (unreleased)
66
================
77

8+
- Make tests resilient against different ways of calling them.
9+
810
- Remove run-time dependency on ``setuptools``.
911

1012

src/zope/interface/tests/test_declarations.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
# pylint:disable=inherit-non-class,too-many-lines,protected-access
2727
# pylint:disable=blacklisted-name,attribute-defined-outside-init
2828

29+
IBar = InterfaceClass('IBar')
2930
IFoo = InterfaceClass('IFoo')
3031

3132

@@ -1373,10 +1374,9 @@ def test__repr__directlyProvides_module(self):
13731374
from zope.interface.declarations import alsoProvides
13741375
from zope.interface.declarations import directlyProvides
13751376
from zope.interface.tests import dummy
1377+
from zope.interface.tests.test_declarations import IBar
13761378
from zope.interface.tests.test_declarations import IFoo
13771379

1378-
IBar = InterfaceClass('IBar')
1379-
13801380
orig_provides = dummy.__provides__ # pylint:disable=no-member
13811381
del dummy.__provides__ # pylint:disable=no-member
13821382
self.addCleanup(setattr, dummy, '__provides__', orig_provides)
@@ -1401,7 +1401,7 @@ def test__repr__directlyProvides_module(self):
14011401

14021402
# If we make this module also provide IFoo and IBar, then the repr
14031403
# lists both names.
1404-
my_module = sys.modules[__name__]
1404+
from zope.interface.tests import test_declarations as my_module
14051405
assert not hasattr(my_module, '__provides__')
14061406

14071407
directlyProvides(my_module, IFoo, IBar)
@@ -1410,7 +1410,7 @@ def test__repr__directlyProvides_module(self):
14101410
self.assertEqual(
14111411
repr(provides),
14121412
"directlyProvides(('zope.interface.tests.dummy', "
1413-
"'interface.tests.test_declarations'), "
1413+
"'zope.interface.tests.test_declarations'), "
14141414
"IFoo, IBar)"
14151415
)
14161416

src/zope/interface/tests/test_ro.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
#
1313
##############################################################################
1414
"""Resolution ordering utility tests"""
15+
import doctest
16+
import re
1517
import unittest
1618

19+
import zope.testing.renormalizing
20+
1721

1822
# pylint:disable=blacklisted-name
1923
# pylint:disable=protected-access
@@ -307,14 +311,29 @@ def _check_handler_complex_diamond(self):
307311
interface.tests.test_ro.D interface.tests.test_ro.D
308312
+ interface.tests.test_ro.E
309313
interface.tests.test_ro.F interface.tests.test_ro.F
310-
zope.interface.Interface zope.interface.Interface""".format(
314+
interface.Interface interface.Interface""".format(
311315
name="interface.tests.test_ro.A"
312316
)
313317

314-
self.assertEqual(
315-
'\n'.join(ln.rstrip() for ln in record.getMessage().splitlines()),
316-
expected,
318+
checker = zope.testing.renormalizing.OutputChecker([
319+
(re.compile(r'zope\.'), ''), # zope is not always there
320+
# space in headline is not consistent
321+
(re.compile(
322+
r'Legacy RO \(len=7\) +C3 RO \(len=7; inconsistent=no\)'),
323+
'Legacy RO (len=7) C3 RO (len=7; inconsistent=no)'),
324+
(re.compile(r'=+'), ''), # header underline length varies
325+
(re.compile(r' +\+'), ' +'), # table column spacing varies
326+
(re.compile(r'interface\.Interface +interface\.Interface'),
327+
'interface.Interface interface.Interface'),
328+
# spacing varies in last line
329+
]
317330
)
331+
got = '\n'.join(ln.rstrip() for ln in record.getMessage().splitlines())
332+
self.assertTrue(
333+
checker.check_output(
334+
expected, got, 0), checker.output_difference(
335+
doctest.Example(
336+
got, expected), got, 0))
318337

319338
def test_ExtendedPathIndex_implement_thing_implementedby_super(self):
320339
# See

0 commit comments

Comments
 (0)