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 fbbc2a4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 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
21 changes: 21 additions & 0 deletions src/z3c/jbot/manager.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
import os
import sys
import tempfile
import six

from zope.interface import implementer

from . import interfaces
from . import utility


# Check if we have case insensitive filesystem
# By default mkstemp() creates a file with
# a name that begins with 'tmp' (lowercase)
try:
tmphandle, tmppath = tempfile.mkstemp()
CASEINSENSITIVE = os.path.exists(tmppath.upper())
os.path.remove(tmppath)
except OSError:
# no tempfiles allowed, so:
# in doubt expect worst case
CASEINSENSITIVE = True

IGNORE = object()
DELETE = object()


def casefix(filepath):
if not isinstance(filepath, str):
return filepath
return filepath.lower() if CASEINSENSITIVE else filepath


def root_length(a, b):
if b.startswith(a):
return len(a)
Expand Down
15 changes: 13 additions & 2 deletions src/z3c/jbot/tests/test_doctests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@

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)
return super(Py23DocChecker, self).check_output(self, want, got, optionflags)

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


def test_suite():
Expand Down

0 comments on commit fbbc2a4

Please sign in to comment.