Repository: zheller/flake8-quotes

Issue:
Incompatible with flake8 version 3
There is a beta version of flake8 version 3, which doesn't use `config_options` anymore so I get the following error:

```
Traceback (most recent call last):
  File "/home/xzise/.pyenv/versions/3.5.1/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/main/cli.py", line 16, in main
    app.run(argv)
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/main/application.py", line 293, in run
    self._run(argv)
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/main/application.py", line 279, in _run
    self.initialize(argv)
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/main/application.py", line 270, in initialize
    self.register_plugin_options()
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/main/application.py", line 150, in register_plugin_options
    self.check_plugins.register_options(self.option_manager)
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/plugins/manager.py", line 451, in register_options
    list(self.manager.map(register_and_enable))
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/plugins/manager.py", line 261, in map
    yield func(self.plugins[name], *args, **kwargs)
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/plugins/manager.py", line 447, in register_and_enable
    call_register_options(plugin)
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/plugins/manager.py", line 357, in generated_function
    return method(optmanager, *args, **kwargs)
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/plugins/manager.py", line 207, in register_options
    add_options(optmanager)
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8_quotes/__init__.py", line 38, in add_options
    parser.config_options.extend(['quotes', 'inline-quotes'])
```

More information:
* [List of plugins broken by 3.0.0](https://gitlab.com/pycqa/flake8/issues/149)
* [Guide to handle both versions](http://flake8.pycqa.org/en/latest/plugin-development/cross-compatibility.html#option-handling-on-flake8-2-and-3)

Comments:

Patch:
diff --git a/.travis.yml b/.travis.yml
index 11c9ca2..d22e40b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -13,7 +13,7 @@ install:
   - pip install -r requirements-dev.txt
 
   # If we are testing Flake8 3.x, then install it
-  - if test "$FLAKE8_VERSION" = "3"; then pip install flake8==3.0.0b2; fi
+  - if test "$FLAKE8_VERSION" = "3"; then pip install flake8==3; fi
 
   # Install `flake8-quotes`
   - python setup.py develop
diff --git a/flake8_quotes/__init__.py b/flake8_quotes/__init__.py
index a3806c3..3631c21 100644
--- a/flake8_quotes/__init__.py
+++ b/flake8_quotes/__init__.py
@@ -2,7 +2,17 @@ import optparse
 import tokenize
 import warnings
 
-from flake8.engine import pep8
+# Polyfill stdin loading/reading lines
+# https://gitlab.com/pycqa/flake8-polyfill/blob/1.0.1/src/flake8_polyfill/stdin.py#L52-57
+try:
+    from flake8.engine import pep8
+    stdin_get_value = pep8.stdin_get_value
+    readlines = pep8.readlines
+except ImportError:
+    from flake8 import utils
+    import pycodestyle
+    stdin_get_value = utils.stdin_get_value
+    readlines = pycodestyle.readlines
 
 from flake8_quotes.__about__ import __version__
 
@@ -74,9 +84,9 @@ class QuoteChecker(object):
 
     def get_file_contents(self):
         if self.filename in ('stdin', '-', None):
-            return pep8.stdin_get_value().splitlines(True)
+            return stdin_get_value().splitlines(True)
         else:
-            return pep8.readlines(self.filename)
+            return readlines(self.filename)
 
     def run(self):
         file_contents = self.get_file_contents()


Test patch:
diff --git a/test/test_checks.py b/test/test_checks.py
index f242f16..0cb1574 100644
--- a/test/test_checks.py
+++ b/test/test_checks.py
@@ -1,18 +1,7 @@
 from flake8_quotes import QuoteChecker
 import os
 import subprocess
-from unittest import expectedFailure, TestCase
-
-
-FLAKE8_VERSION = os.environ.get('FLAKE8_VERSION', '2')
-
-
-def expectedFailureIf(condition):
-    """Only expect failure if condition applies."""
-    if condition:
-        return expectedFailure
-    else:
-        return lambda func: func
+from unittest import TestCase
 
 
 class TestChecks(TestCase):
@@ -22,7 +11,6 @@ class TestChecks(TestCase):
 
 
 class TestFlake8Stdin(TestCase):
-    @expectedFailureIf(FLAKE8_VERSION == '3')
     def test_stdin(self):
         """Test using stdin."""
         filepath = get_absolute_path('data/doubles.py')
@@ -33,11 +21,10 @@ class TestFlake8Stdin(TestCase):
 
         stdout_lines = stdout.splitlines()
         self.assertEqual(stderr, b'')
-        self.assertEqual(stdout_lines, [
-            b'stdin:1:25: Q000 Remove bad quotes.',
-            b'stdin:2:25: Q000 Remove bad quotes.',
-            b'stdin:3:25: Q000 Remove bad quotes.',
-        ])
+        self.assertEqual(len(stdout_lines), 3)
+        self.assertRegexpMatches(stdout_lines[0], b'stdin:1:(24|25): Q000 Remove bad quotes.')
+        self.assertRegexpMatches(stdout_lines[1], b'stdin:2:(24|25): Q000 Remove bad quotes.')
+        self.assertRegexpMatches(stdout_lines[2], b'stdin:3:(24|25): Q000 Remove bad quotes.')
 
 
 class DoublesTestChecks(TestCase):