Skip to content
This repository has been archived by the owner on May 15, 2020. It is now read-only.

Commit

Permalink
Minor Python 3 compatibility fixes.
Browse files Browse the repository at this point in the history
Still more fixes to do.
  • Loading branch information
ulif committed May 6, 2015
1 parent e45adba commit be86e2f
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 19 deletions.
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -54,6 +54,7 @@ def read(*rnames):
install_requires=['setuptools',
'zope.testing',
'martian',
'six',
],
tests_require = tests_require,
extras_require = dict(test=tests_require),
Expand Down
10 changes: 6 additions & 4 deletions src/z3c/testsetup/basicsetup.txt
Expand Up @@ -210,10 +210,12 @@ File paths, that cannot be found, are treated as real errors as they signal an
error in the way we set everything up:

>>> basic_setup4 = BasicTestSetup(cave, extensions=['.foo'])
>>> basic_setup4.fileContains('blah')
Traceback (most recent call last):
...
IOError: [Errno 2] No such file or directory: 'blah'
>>> try:
... basic_setup4.fileContains('blah')
... except Exception as exc:
... # exceptions raised are different in Python2/3.
... print(exc)
[Errno 2] No such file or directory: 'blah'

We pick up an existing file path::

Expand Down
2 changes: 1 addition & 1 deletion src/z3c/testsetup/nozopeapptesting.txt
Expand Up @@ -27,7 +27,7 @@ package of the ``tests``::
>>> pkgpath = os.path.dirname(z3c.testsetup.__file__)
>>> cavepath = os.path.join(pkgpath, 'tests', 'cave')
>>> setupfile = os.path.join(cavepath, 'samplesetup_short0.py')
>>> print open(setupfile).read()
>>> print(open(setupfile).read())
import z3c.testsetup
test_suite = z3c.testsetup.register_all_tests('z3c.testsetup.tests.cave')

Expand Down
2 changes: 1 addition & 1 deletion src/z3c/testsetup/testing.py
Expand Up @@ -75,7 +75,7 @@ def isTestModule(self, module_info):
except ImportError:
# Broken module that is probably a test. We absolutely have to
# warn about this!
print "Import error in", module_info.path
print("Import error in %s" % module_info.path)
docstr = getattr(module, '__doc__', '')
if not self.docstrContains(docstr):
return False
Expand Down
2 changes: 1 addition & 1 deletion src/z3c/testsetup/tests/setupininit.txt
Expand Up @@ -12,7 +12,7 @@ a test setup in the cave package::
The setup looks like this::

>>> setupfile = os.path.join(cavepath, 'tests', '__init__.py')
>>> print open(setupfile).read()
>>> print(open(setupfile).read())
# this is a package that contains a testsetup.
#
# To let it be found by the testrunner, you must call the testrunner
Expand Down
2 changes: 1 addition & 1 deletion src/z3c/testsetup/tests/test_testsetup.py
Expand Up @@ -75,7 +75,7 @@ def print_file(path):
This way we prevent the testrunner to test the output.
"""
contents = open(path, 'r').read()
print '| ' + '\n| '.join(contents.split('\n'))
print('| ' + '\n| '.join(contents.split('\n')))
return


Expand Down
10 changes: 5 additions & 5 deletions src/z3c/testsetup/tests/util.txt
Expand Up @@ -16,13 +16,13 @@ a marker string ``marker``::
... :mymarker: blah
... """
>>> get_marker_from_string('mymarker', text)
u'blah'
'blah'

The marker is also found in the first line::

>>> text = """:mymarker: blah"""
>>> get_marker_from_string('mymarker', text)
u'blah'
'blah'

When several same-named markers occur, the first one is picked::

Expand All @@ -31,15 +31,15 @@ When several same-named markers occur, the first one is picked::
... :mymarker: blubb
... """
>>> get_marker_from_string('mymarker', text)
u'blah'
'blah'

The lookup is case insensitive while the result is not::

>>> text = """
... :MyMarker: Blah
... """
>>> get_marker_from_string('mymarker', text)
u'Blah'
'Blah'

We also accept marker strings preceeded by two dot followed by
whitespaces (a comment in restructured text)::
Expand All @@ -48,7 +48,7 @@ whitespaces (a comment in restructured text)::
... .. :MyMarker: Blah
... """
>>> get_marker_from_string('mymarker', text)
u'Blah'
'Blah'

When the marker string cannot be found, ``None`` is returned::

Expand Down
7 changes: 4 additions & 3 deletions src/z3c/testsetup/util.py
Expand Up @@ -20,6 +20,7 @@

from inspect import getmro, ismethod, getargspec
from martian.scan import resolve
from six import string_types


def get_package(pkg_or_dotted_name):
Expand All @@ -32,7 +33,7 @@ def get_package(pkg_or_dotted_name):
returned as-is.
"""
pkg = pkg_or_dotted_name
if isinstance(pkg, basestring):
if isinstance(pkg, string_types):
pkg = resolve(pkg)
elif isinstance(pkg, bytes):
pkg = resolve(pkg.decode('utf-8'))
Expand Down Expand Up @@ -86,7 +87,7 @@ def get_marker_from_string(marker, text):
if result is None:
continue
result = result.groups()[1].strip()
return unicode(result)
return result
return None


Expand All @@ -98,7 +99,7 @@ def get_marker_from_file(marker, filepath):
:<Tag>: <Value>
"""
return get_marker_from_string(marker, open(filepath, 'rb').read())
return get_marker_from_string(marker, open(filepath, 'r').read())


def warn(text):
Expand Down
6 changes: 3 additions & 3 deletions src/z3c/testsetup/util.txt
Expand Up @@ -125,7 +125,7 @@ Now let's lookup the value of the marker `Test-Layer`::

>>> from z3c.testsetup.util import get_marker_from_string
>>> get_marker_from_string('Test-Layer', markerstring)
u'foo'
'foo'

Another marker cannot be found::

Expand All @@ -144,7 +144,7 @@ upper or lower case letters or both in a wild mix::
... Some other text
... """
>>> get_marker_from_string('test-Layer', markerstring)
u'foo'
'foo'


get_marker_from_file
Expand Down Expand Up @@ -173,7 +173,7 @@ Now we lookup the marker string from this file::

>>> from z3c.testsetup.util import get_marker_from_file
>>> get_marker_from_file('tEsT-LaYeR', 'tempfile')
u'foo'
'foo'

If the string does not exist, we get `None`::

Expand Down

0 comments on commit be86e2f

Please sign in to comment.