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

Commit

Permalink
Python 2.6 tested on Windows. No subprocess32.
Browse files Browse the repository at this point in the history
Using Popen and defining my own check_output() instead of installing
subprocess32 which doesn't work on Windows.
  • Loading branch information
Robpol86 committed Jul 30, 2016
1 parent f2b6c01 commit a2f005f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This is just a simple flake8 plugin for the `pep257 <https://github.com/GreenSte
validating docstrings.

* Python 2.6, 2.7, PyPy, 3.3, 3.4, and 3.5 supported on Linux and OS X.
* Python 2.7, 3.3, 3.4, and 3.5 supported on Windows (both 32 and 64 bit versions of Python).
* Python 2.6, 2.7, 3.3, 3.4, and 3.5 supported on Windows (both 32 and 64 bit versions of Python).

.. image:: https://img.shields.io/appveyor/ci/Robpol86/flake8-pep257/master.svg?style=flat-square&label=AppVeyor%20CI
:target: https://ci.appveyor.com/project/Robpol86/flake8-pep257
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ artifacts:
# Run.
init: set PATH=C:\Python35-x64;C:\Python35-x64\Scripts;%PATH%
build_script: pip install tox
test_script: tox -e lint,py35,py34,py33,py27,py35x64,py34x64,py33x64,py27x64
test_script: tox -e lint,py35,py34,py33,py27,py26,py35x64,py34x64,py33x64,py27x64,py26x64
38 changes: 32 additions & 6 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
"""Non-fixture code shared among test modules."""

import os
import subprocess

try:
from subprocess import check_output, STDOUT
except ImportError:
from subprocess32 import check_output, STDOUT

def check_output(command, cwd=None, env=None, stdin=None):
"""Basically subprocess.check_output since it doesn't exist in Python 2.6.
assert check_output
assert STDOUT
:raise CalledProcessError: Command exits non-zero.
:param iter command: Command to run.
:param str cwd: Current working directory.
:param dict env: Set environment variables.
:param file stdin: Pipe handle to subprocess' stdin.
:return: Command output.
:rtype: str
"""
stdout = subprocess.STDOUT
pipe = subprocess.PIPE

# Setup env.
environ = os.environ.copy()
if env:
environ.update(env)

# Run command.
with open(os.devnull) as null:
proc = subprocess.Popen(command, cwd=cwd, env=environ, stdout=pipe, stderr=stdout, stdin=stdin or null)
output = proc.communicate()[0].decode('utf-8') # Blocks until command exits.

# Raise if non-zero exit.
if proc.poll() != 0:
raise subprocess.CalledProcessError(proc.poll(), command, output=output)

return output
4 changes: 2 additions & 2 deletions tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import flake8.main
import pytest

from tests import check_output, STDOUT
from tests import check_output

EXPECTED = """\
./sample.py:1:1: D100 Missing docstring in public module
Expand Down Expand Up @@ -72,7 +72,7 @@ def test_subprocess(tmpdir, stdin):
command = [find_executable('flake8'), '--exit-zero', '-' if stdin else '.']
environ = os.environ.copy()
environ['COV_CORE_DATAFILE'] = '' # Disable pytest-cov's subprocess coverage feature. Doesn't work right now.
out = check_output(command, stderr=STDOUT, cwd=cwd, stdin=stdin_handle, env=environ).decode('utf-8')
out = check_output(command, cwd=cwd, stdin=stdin_handle, env=environ)

# Clean.
if stdin:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_explain.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import flake8.main
import pytest

from tests import check_output, STDOUT
from tests import check_output

EXPECTED = list()
EXPECTED.append("""\
Expand Down Expand Up @@ -187,7 +187,7 @@ def test_subprocess(tmpdir, stdin, which_cfg):
command = [find_executable('flake8'), '--exit-zero', '-' if stdin else '.']
environ = os.environ.copy()
environ['COV_CORE_DATAFILE'] = '' # Disable pytest-cov's subprocess coverage feature. Doesn't work right now.
out = check_output(command, stderr=STDOUT, cwd=cwd, stdin=stdin_handle, env=environ).decode('utf-8')
out = check_output(command, cwd=cwd, stdin=stdin_handle, env=environ)

# Clean.
if stdin:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import flake8.main
import pytest

from tests import check_output, STDOUT
from tests import check_output

EXPECTED = """\
./sample.py:1:1: D100 Missing docstring in public module
Expand Down Expand Up @@ -86,7 +86,7 @@ def test_subprocess(tmpdir, ignore, stdin, which_cfg):
command = [find_executable('flake8'), '--exit-zero', '-' if stdin else '.']
environ = os.environ.copy()
environ['COV_CORE_DATAFILE'] = '' # Disable pytest-cov's subprocess coverage feature. Doesn't work right now.
out = check_output(command, stderr=STDOUT, cwd=cwd, stdin=stdin_handle, env=environ).decode('utf-8')
out = check_output(command, cwd=cwd, stdin=stdin_handle, env=environ)

# Clean.
if stdin:
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ commands =
deps =
flake8==2.5.4
pytest-cov==2.2.1
py26: subprocess32==3.2.7
usedevelop = True

[testenv:py35x64]
Expand Down

0 comments on commit a2f005f

Please sign in to comment.