forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tighten up checkstyle plugin subsystem option passing. (pantsbuild#6648)
Ensure we only try to pass options declared by checkstyle plugins. Fixes pantsbuild#6645
- Loading branch information
Showing
5 changed files
with
101 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
65 changes: 65 additions & 0 deletions
65
...ts/python/pants_test/contrib/python/checks/tasks/checkstyle/test_plugin_subsystem_base.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# coding=utf-8 | ||
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
import json | ||
import unittest | ||
|
||
from pants_test.subsystem import subsystem_util | ||
|
||
from pants.contrib.python.checks.checker.common import CheckstylePlugin | ||
from pants.contrib.python.checks.tasks.checkstyle.plugin_subsystem_base import (PluginSubsystemBase, | ||
default_subsystem_for_plugin) | ||
|
||
|
||
class Plugin(CheckstylePlugin): | ||
@classmethod | ||
def name(cls): | ||
return 'test-plugin' | ||
|
||
|
||
class PluginSubsystem(PluginSubsystemBase): | ||
options_scope = 'pycheck-test-plugin' | ||
|
||
@classmethod | ||
def plugin_type(cls): | ||
return Plugin | ||
|
||
@classmethod | ||
def register_plugin_options(cls, register): | ||
register('--bob') | ||
register('-j', '--jake', dest='jane') | ||
|
||
|
||
class PluginSubsystemBaseTest(unittest.TestCase): | ||
def assert_options(self, subsystem_type, **input_opts): | ||
expected = {'skip': True} | ||
expected.update(**input_opts) | ||
|
||
unexpected = {('random', 'global', 'option', 'non', 'string', 'key'): 42, | ||
'another_unneeded': 137} | ||
|
||
opts = expected.copy() | ||
opts.update(unexpected) | ||
|
||
subsystem_util.init_subsystem(subsystem_type, | ||
options={subsystem_type.options_scope: opts}) | ||
|
||
subsystem_instance = subsystem_type.global_instance() | ||
self.assertTrue(subsystem_instance.get_options().skip) | ||
self.assertEqual(expected, json.loads(subsystem_instance.options_blob())) | ||
|
||
def test_default_subsystem_for_plugin(self): | ||
subsystem_type = default_subsystem_for_plugin(Plugin) | ||
self.assertEqual('pycheck-test-plugin', subsystem_type.options_scope) | ||
|
||
self.assert_options(subsystem_type) | ||
|
||
def test_default_subsystem_for_plugin_bad_plugin(self): | ||
with self.assertRaises(ValueError): | ||
default_subsystem_for_plugin(object) | ||
|
||
def test_options_blob(self): | ||
self.assert_options(PluginSubsystem, bob=42, jane=True) |