mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-29 10:36:53 +00:00
Remove unnecessary and outdated test runner
This commit is contained in:
parent
3da9fd3cb7
commit
48b995fa62
3 changed files with 22 additions and 45 deletions
|
|
@ -46,14 +46,16 @@ class FileProcessor(object):
|
|||
|
||||
NOQA_FILE = re.compile(r'\s*# flake8[:=]\s*noqa', re.I)
|
||||
|
||||
def __init__(self, filename, options):
|
||||
def __init__(self, filename, options, lines=None):
|
||||
"""Initialice our file processor.
|
||||
|
||||
:param str filename:
|
||||
Name of the file to process
|
||||
"""
|
||||
self.filename = filename
|
||||
self.lines = self.read_lines()
|
||||
self.lines = lines
|
||||
if lines is None:
|
||||
self.lines = self.read_lines()
|
||||
self.strip_utf_bom()
|
||||
self.options = options
|
||||
|
||||
|
|
|
|||
32
run_tests.py
32
run_tests.py
|
|
@ -1,32 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import unittest
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
sys.path.insert(0, '.')
|
||||
|
||||
TEST_DIR = 'flake8.tests'
|
||||
|
||||
|
||||
def collect_tests():
|
||||
# list files in directory tests/
|
||||
names = os.listdir(TEST_DIR.replace('.', '/'))
|
||||
regex = re.compile("(?!_+)\w+\.py$")
|
||||
join = '.'.join
|
||||
# Make a list of the names like 'tests.test_name'
|
||||
names = [join([TEST_DIR, f[:-3]]) for f in names if regex.match(f)]
|
||||
modules = [__import__(name, fromlist=[TEST_DIR]) for name in names]
|
||||
load_tests = unittest.defaultTestLoader.loadTestsFromModule
|
||||
suites = [load_tests(m) for m in modules]
|
||||
suite = suites.pop()
|
||||
for s in suites:
|
||||
suite.addTests(s)
|
||||
return suite
|
||||
|
||||
if __name__ == "__main__":
|
||||
suite = collect_tests()
|
||||
res = unittest.TextTestRunner(verbosity=1).run(suite)
|
||||
|
||||
# If it was successful, we don't want to exit with code 1
|
||||
raise SystemExit(not res.wasSuccessful())
|
||||
|
|
@ -1,26 +1,33 @@
|
|||
"""Tests for the FileChecker class."""
|
||||
from flake8 import checker
|
||||
"""Tests for the FileProcessor class."""
|
||||
import optparse
|
||||
|
||||
from flake8 import processor
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def options_from(**kwargs):
|
||||
kwargs.setdefault('hang_closing', True)
|
||||
kwargs.setdefault('max_line_length', 79)
|
||||
kwargs.setdefault('verbose', False)
|
||||
return optparse.Values(kwargs)
|
||||
|
||||
|
||||
def test_read_lines_splits_lines():
|
||||
"""Verify that read_lines splits the lines of the file."""
|
||||
file_checker = checker.FileChecker(__file__, [])
|
||||
lines = file_checker.read_lines()
|
||||
file_processor = processor.FileProcessor(__file__, options_from())
|
||||
lines = file_processor.lines
|
||||
assert len(lines) > 5
|
||||
assert '"""Tests for the FileChecker class."""\n' in lines
|
||||
assert '"""Tests for the FileProcessor class."""\n' in lines
|
||||
|
||||
|
||||
@pytest.mark.parametrize('first_line', [
|
||||
'\xEF\xBB\xBF"""Module docstring."""\n',
|
||||
'\uFEFF"""Module docstring."""\n',
|
||||
u'\uFEFF"""Module docstring."""\n',
|
||||
])
|
||||
def test_strip_utf_bom(first_line):
|
||||
r"""Verify that we strip '\xEF\xBB\xBF' from the first line."""
|
||||
lines = [first_line]
|
||||
file_checker = checker.FileChecker('stdin', [])
|
||||
file_checker.lines = lines[:]
|
||||
file_checker.strip_utf_bom()
|
||||
assert file_checker.lines != lines
|
||||
assert file_checker.lines[0] == '"""Module docstring."""\n'
|
||||
file_processor = processor.FileProcessor('-', options_from(), lines[:])
|
||||
assert file_processor.lines != lines
|
||||
assert file_processor.lines[0] == '"""Module docstring."""\n'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue