summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Vandenberg <jayvdb@gmail.com>2016-07-22 01:34:42 +0700
committerIan Cordasco <sigmavirus24@users.noreply.github.com>2016-07-21 13:34:42 -0500
commit2ab47d7628396d3b23d2dda5d163e0c2089666b4 (patch)
treeb49cd06b46b4e1ad3350cb64474ccc90b6d8261c
parentb161e506344d609842e224505fc13374faacfbda (diff)
downloadpyflakes-2ab47d7628396d3b23d2dda5d163e0c2089666b4.tar.gz
Fix TestMain tests on Windows (#75)
Currently the API test module has failures for TestMain class, added in f0084592, on Windows as SysStreamCapturing is in universal newlines mode while its super class IntegrationTests is using a native console stream with newline=os.linesep. Add Appveyor CI script as .appveyor.yml, which can be selected in the Appveyor settings.
-rw-r--r--.appveyor.yml8
-rw-r--r--pyflakes/test/test_api.py32
-rw-r--r--tox.ini1
3 files changed, 37 insertions, 4 deletions
diff --git a/.appveyor.yml b/.appveyor.yml
new file mode 100644
index 0000000..4a1d13c
--- /dev/null
+++ b/.appveyor.yml
@@ -0,0 +1,8 @@
+# To activate, change the Appveyor settings to use `.appveyor.yml`.
+install:
+ - python -m pip install tox
+
+build: off
+
+test_script:
+ - python -m tox
diff --git a/pyflakes/test/test_api.py b/pyflakes/test/test_api.py
index b56ca7a..4ffe242 100644
--- a/pyflakes/test/test_api.py
+++ b/pyflakes/test/test_api.py
@@ -55,10 +55,30 @@ class Node(object):
class SysStreamCapturing(object):
- """Replaces sys.stdin, sys.stdout and sys.stderr with StringIO objects."""
+ """
+ Context manager capturing sys.stdin, sys.stdout and sys.stderr.
+
+ The file handles are replaced with a StringIO object.
+ On environments that support it, the StringIO object uses newlines
+ set to os.linesep. Otherwise newlines are converted from \\n to
+ os.linesep during __exit__.
+ """
+
+ def _create_StringIO(self, buffer=None):
+ # Python 3 has a newline argument
+ try:
+ return StringIO(buffer, newline=os.linesep)
+ except TypeError:
+ self._newline = True
+ # Python 2 creates an input only stream when buffer is not None
+ if buffer is None:
+ return StringIO()
+ else:
+ return StringIO(buffer)
def __init__(self, stdin):
- self._stdin = StringIO(stdin or '')
+ self._newline = False
+ self._stdin = self._create_StringIO(stdin or '')
def __enter__(self):
self._orig_stdin = sys.stdin
@@ -66,8 +86,8 @@ class SysStreamCapturing(object):
self._orig_stderr = sys.stderr
sys.stdin = self._stdin
- sys.stdout = self._stdout_stringio = StringIO()
- sys.stderr = self._stderr_stringio = StringIO()
+ sys.stdout = self._stdout_stringio = self._create_StringIO()
+ sys.stderr = self._stderr_stringio = self._create_StringIO()
return self
@@ -75,6 +95,10 @@ class SysStreamCapturing(object):
self.output = self._stdout_stringio.getvalue()
self.error = self._stderr_stringio.getvalue()
+ if self._newline and os.linesep != '\n':
+ self.output = self.output.replace('\n', os.linesep)
+ self.error = self.error.replace('\n', os.linesep)
+
sys.stdin = self._orig_stdin
sys.stdout = self._orig_stdout
sys.stderr = self._orig_stderr
diff --git a/tox.ini b/tox.ini
index 7766253..870ed43 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,4 +1,5 @@
[tox]
+skip_missing_interpreters = True
envlist =
py26,py27,py32,py33,py34,py35,pypy,pypy3