summaryrefslogtreecommitdiff
path: root/tests/integration
diff options
context:
space:
mode:
authorCarl Meyer <carl@oddbird.net>2017-08-03 00:25:37 -0700
committerCarl Meyer <carl@oddbird.net>2017-08-03 00:25:37 -0700
commit4e58068657ece52e3f1636cb028e42c15b86fec3 (patch)
treec739fe9428a1a3f46d836773e243cdcdb22ddb27 /tests/integration
parent6df26ffd57178e50194aea31b3bf9c572f91fa54 (diff)
downloadflake8-4e58068657ece52e3f1636cb028e42c15b86fec3.tar.gz
Add support for local (in-repo, non-setuptools) plugins.
Closes #357
Diffstat (limited to 'tests/integration')
-rw-r--r--tests/integration/test_aggregator.py9
-rw-r--r--tests/integration/test_plugins.py58
2 files changed, 65 insertions, 2 deletions
diff --git a/tests/integration/test_aggregator.py b/tests/integration/test_aggregator.py
index 929bdbf..c789624 100644
--- a/tests/integration/test_aggregator.py
+++ b/tests/integration/test_aggregator.py
@@ -5,6 +5,7 @@ import pytest
from flake8.main import options
from flake8.options import aggregator
+from flake8.options import config
from flake8.options import manager
CLI_SPECIFIED_CONFIG = 'tests/fixtures/config_files/cli-specified.ini'
@@ -25,7 +26,9 @@ def test_aggregate_options_with_config(optmanager):
"""Verify we aggregate options and config values appropriately."""
arguments = ['flake8', '--config', CLI_SPECIFIED_CONFIG, '--select',
'E11,E34,E402,W,F', '--exclude', 'tests/*']
- options, args = aggregator.aggregate_options(optmanager, arguments)
+ config_finder = config.ConfigFileFinder('flake8', arguments, [])
+ options, args = aggregator.aggregate_options(
+ optmanager, config_finder, arguments)
assert options.config == CLI_SPECIFIED_CONFIG
assert options.select == ['E11', 'E34', 'E402', 'W', 'F']
@@ -37,8 +40,10 @@ def test_aggregate_options_when_isolated(optmanager):
"""Verify we aggregate options and config values appropriately."""
arguments = ['flake8', '--isolated', '--select', 'E11,E34,E402,W,F',
'--exclude', 'tests/*']
+ config_finder = config.ConfigFileFinder('flake8', arguments, [])
optmanager.extend_default_ignore(['E8'])
- options, args = aggregator.aggregate_options(optmanager, arguments)
+ options, args = aggregator.aggregate_options(
+ optmanager, config_finder, arguments)
assert options.isolated is True
assert options.select == ['E11', 'E34', 'E402', 'W', 'F']
diff --git a/tests/integration/test_plugins.py b/tests/integration/test_plugins.py
new file mode 100644
index 0000000..6d51a4a
--- /dev/null
+++ b/tests/integration/test_plugins.py
@@ -0,0 +1,58 @@
+"""Integration tests for plugin loading."""
+from flake8.main import application
+
+
+LOCAL_PLUGIN_CONFIG = 'tests/fixtures/config_files/local-plugin.ini'
+
+
+class ExtensionTestPlugin(object):
+ """Extension test plugin."""
+
+ name = 'ExtensionTestPlugin'
+ version = '1.0.0'
+
+ def __init__(self, tree):
+ """Construct an instance of test plugin."""
+ pass
+
+ def run(self):
+ """Do nothing."""
+ pass
+
+ @classmethod
+ def add_options(cls, parser):
+ """Register options."""
+ parser.add_option('--anopt')
+
+
+class ReportTestPlugin(object):
+ """Report test plugin."""
+
+ name = 'ReportTestPlugin'
+ version = '1.0.0'
+
+ def __init__(self, tree):
+ """Construct an instance of test plugin."""
+ pass
+
+ def run(self):
+ """Do nothing."""
+ pass
+
+
+def test_enable_local_plugin_from_config():
+ """App can load a local plugin from config file."""
+ app = application.Application()
+ app.initialize(['flake8', '--config', LOCAL_PLUGIN_CONFIG])
+
+ assert app.check_plugins['XE'].plugin is ExtensionTestPlugin
+ assert app.formatting_plugins['XR'].plugin is ReportTestPlugin
+
+
+def test_local_plugin_can_add_option():
+ """A local plugin can add a CLI option."""
+ app = application.Application()
+ app.initialize(
+ ['flake8', '--config', LOCAL_PLUGIN_CONFIG, '--anopt', 'foo'])
+
+ assert app.options.anopt == 'foo'