Skip to content

Commit

Permalink
fix test to run on windows with windows line endings (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Aug 9, 2020
1 parent 93f7ac7 commit 4ba330b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ jobs:
uses: actions/cache@v1
id: cache
with:
path: .cache/pip
path: |
.cache/pip
eggs
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt', 'constraints.txt', 'buildout.cfg', 'setup.*') }}
restore-keys: |
${{ runner.os }}-test
Expand Down
17 changes: 12 additions & 5 deletions src/z3c/jbot/manager.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import os
import sys
import tempfile

from zope.interface import implementer

from . import interfaces
from . import utility


IGNORE = object()
DELETE = object()



def root_length(a, b):
if b.startswith(a):
return len(a)
Expand Down Expand Up @@ -40,12 +43,13 @@ def find_zope2_product(path):

def find_package(syspaths, path):
"""Determine the Python-package where path is located. If the path is
not located within the Python sys-path, return ``None``."""
not located within the Python sys-path, return ``None``.
The returned path is already 'normcase'. """

_syspaths = sort_by_path(path, syspaths)
syspath = _syspaths[0]
syspath = os.path.normcase(os.path.normpath(_syspaths[0]))

path = os.path.normpath(path)
path = os.path.normcase(os.path.normpath(path))
if not path.startswith(syspath):
if utility.ZOPE_2:
return find_zope2_product(path)
Expand Down Expand Up @@ -78,16 +82,19 @@ def __init__(self, name):
self.name = name

def registerDirectory(self, directory):
directory = os.path.normcase(directory)
self.directories.add(directory)

for filename in os.listdir(directory):
filename = os.path.normcase(filename)
self.paths[filename] = "%s/%s" % (directory, filename)

for template, filename in list(self.templates.items()):
if filename is IGNORE:
del self.templates[template]

def unregisterDirectory(self, directory):
directory = os.path.normcase(directory)
self.directories.remove(directory)

templates = []
Expand Down Expand Up @@ -122,7 +129,7 @@ def registerTemplate(self, template, token):

# verify that override has not been unregistered
if filename is not None and filename not in paths:
template.filename = template._filename
template.filename = os.path.normcase(template._filename)
del self.templates[token]

# check if an override exists
Expand All @@ -132,7 +139,7 @@ def registerTemplate(self, template, token):
self.templates[token] = IGNORE
return

filename = path.replace(os.path.sep, '.')
filename = path.replace('/', '.')
if filename not in paths:
self.templates[token] = IGNORE
template._v_last_read = False
Expand Down
16 changes: 15 additions & 1 deletion src/z3c/jbot/tests/test_doctests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,27 @@

class Py23DocChecker(doctest.OutputChecker):
def check_output(self, want, got, optionflags):
# fix windows line-endings to match ones in tests
got = got.replace("\r\n", "\n")
# fix binary/unicode differences between python versions
if six.PY2:
want = re.sub("b'(.*?)'", "'\\1'", want)
else:
want = re.sub("u'(.*?)'", "'\\1'", want)
want = want.replace(r"\r\n", r"\n")
return doctest.OutputChecker.check_output(self, want, got, optionflags)

def output_difference(self, example, got, optionflags):
# fix windows line-endings to match ones in tests
if isinstance(got, six.string_types):
got = got.replace("\r\n", "\n")
if isinstance(example, six.string_types):
if six.PY2:
example = re.sub("b'(.*?)'", "'\\1'", example)
else:
example = re.sub("u'(.*?)'", "'\\1'", example)
return doctest.OutputChecker.output_difference(
self, example, got, optionflags)


def test_suite():
globs = dict(
Expand Down

0 comments on commit 4ba330b

Please sign in to comment.