Add basic check test cases

Change-Id: Icb4ef09b68618e562062d1d79b1b09b1cef72d79
This commit is contained in:
Joshua Harlow 2014-08-28 17:35:35 -07:00
parent 74f4a31087
commit 5bbb86c198
3 changed files with 117 additions and 0 deletions

0
doc8/tests/__init__.py Normal file
View File

116
doc8/tests/test_checks.py Normal file
View File

@ -0,0 +1,116 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2014 Yahoo! Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import tempfile
import testtools
from doc8 import checks
from doc8 import parser
class TestTrailingWhitespace(testtools.TestCase):
def test_trailing(self):
lines = ["a b ", "ab"]
check = checks.CheckTrailingWhitespace({})
errors = []
for line in lines:
errors.extend(check.report_iter(line))
self.assertEqual(1, len(errors))
(code, msg) = errors[0]
self.assertIn(code, check.REPORTS)
class TestTabIndentation(testtools.TestCase):
def test_tabs(self):
lines = [" b", "\tabc", "efg", "\t\tc"]
check = checks.CheckIndentationNoTab({})
errors = []
for line in lines:
errors.extend(check.report_iter(line))
self.assertEqual(2, len(errors))
(code, msg) = errors[0]
self.assertIn(code, check.REPORTS)
class TestCarriageReturn(testtools.TestCase):
def test_cr(self):
lines = ["\tabc", "efg", "\r\n"]
check = checks.CheckCarriageReturn({})
errors = []
for line in lines:
errors.extend(check.report_iter(line))
self.assertEqual(1, len(errors))
(code, msg) = errors[0]
self.assertIn(code, check.REPORTS)
class TestLineLength(testtools.TestCase):
def test_over_length(self):
content = """
===
aaa
===
----
test
----
"""
content += "\n\n"
content += ("a" * 60) + " " + ("b" * 60)
content += "\n"
with tempfile.NamedTemporaryFile() as fh:
fh.write(content)
fh.flush()
parsed_file = parser.ParsedFile(fh.name)
conf = {
'max_line_length': 79,
'allow_long_titles': True,
}
check = checks.CheckMaxLineLength(conf)
errors = list(check.report_iter(parsed_file))
self.assertEqual(1, len(errors))
(line, code, msg) = errors[0]
self.assertIn(code, check.REPORTS)
def test_unsplittable_length(self):
content = """
===
aaa
===
----
test
----
"""
content += "\n\n"
content += "a" * 100
content += "\n"
with tempfile.NamedTemporaryFile() as fh:
fh.write(content)
fh.flush()
parsed_file = parser.ParsedFile(fh.name)
conf = {
'max_line_length': 79,
'allow_long_titles': True,
}
check = checks.CheckMaxLineLength(conf)
errors = list(check.report_iter(parsed_file))
self.assertEqual(0, len(errors))

View File

@ -4,3 +4,4 @@ nose
oslosphinx
pylint==0.25.2
sphinx>=1.1.2,!=1.2.0,<1.3
testtools