Skip to content

Instantly share code, notes, and snippets.

@DasIch
Created April 8, 2013 00:05
Show Gist options
  • Save DasIch/5333211 to your computer and use it in GitHub Desktop.
Save DasIch/5333211 to your computer and use it in GitHub Desktop.
# coding: utf-8
"""
pythonic.tests.test_checkers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:copyright: 2013 by Daniel Neuhäuser
:license: BSD, see LICENSE.rst for more details
"""
import os
import pytest
from pythonic.checkers import ASTChecker
class CheckerTestBaseMeta(type):
def __new__(cls, name, bases, attributes):
@pytest.fixture(params=attributes["warnings"])
def filename(self, request):
return request.param
attributes["filename"] = filename
return type.__new__(cls, name, bases, attributes)
class CheckerTestBase(object):
__metaclass__ = CheckerTestBaseMeta
checker_cls = None
warnings = {}
@pytest.fixture
def messages(self, filename):
return self.warnings[filename]
def get_bad_path(self, filename):
return os.path.join(
os.path.abspath(os.path.dirname(__file__)),
"bad",
filename
)
def test_warnings(self, filename, messages, capsys):
bad_file = self.get_bad_path(filename)
self.checker_cls(bad_file).run()
out, err = capsys.readouterr()
assert not out
for observed, expected in zip(err.splitlines(), messages):
assert observed == bad_file + expected
class TestASTChecker(CheckerTestBase):
checker_cls = ASTChecker
warnings = {
"star_import.py": [
":1:0: Should not use *-import"
],
"multi_import.py": [
":1:0: Should not import multiple modules with one statement"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment