Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
adefe38a0d | ||
|
|
7e11082353 | ||
|
|
29c1c60143 | ||
|
|
b879e9a98f | ||
|
|
5956b20545 | ||
|
|
10ad302e2f | ||
|
|
73d9322813 |
@@ -1,2 +1,3 @@
|
|||||||
|
include LICENSE
|
||||||
|
include README.rst
|
||||||
include docs/*
|
include docs/*
|
||||||
include tests/yaml-1.2-spec-examples/*
|
|
||||||
|
|||||||
3
setup.py
3
setup.py
@@ -44,7 +44,8 @@ setup(
|
|||||||
|
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
entry_points={'console_scripts': ['yamllint=yamllint.cli:run']},
|
entry_points={'console_scripts': ['yamllint=yamllint.cli:run']},
|
||||||
package_data={'yamllint': ['conf/*.yml']},
|
package_data={'yamllint': ['conf/*.yml'],
|
||||||
|
'tests': ['yaml-1.2-spec-examples/*']},
|
||||||
install_requires=['pyyaml'],
|
install_requires=['pyyaml'],
|
||||||
tests_require=['nose'],
|
tests_require=['nose'],
|
||||||
test_suite='nose.collector',
|
test_suite='nose.collector',
|
||||||
|
|||||||
46
tests/test_linter.py
Normal file
46
tests/test_linter.py
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (C) 2016 Adrien Vergé
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import io
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from yamllint.config import YamlLintConfig
|
||||||
|
from yamllint import linter
|
||||||
|
|
||||||
|
|
||||||
|
class LinterTestCase(unittest.TestCase):
|
||||||
|
def fake_config(self):
|
||||||
|
return YamlLintConfig('extends: default')
|
||||||
|
|
||||||
|
def test_run_on_string(self):
|
||||||
|
linter.run('test: document', self.fake_config())
|
||||||
|
|
||||||
|
def test_run_on_bytes(self):
|
||||||
|
linter.run(b'test: document', self.fake_config())
|
||||||
|
|
||||||
|
def test_run_on_unicode(self):
|
||||||
|
linter.run(u'test: document', self.fake_config())
|
||||||
|
|
||||||
|
def test_run_on_stream(self):
|
||||||
|
linter.run(io.StringIO(u'hello'), self.fake_config())
|
||||||
|
|
||||||
|
def test_run_on_int(self):
|
||||||
|
self.assertRaises(TypeError, linter.run, 42, self.fake_config())
|
||||||
|
|
||||||
|
def test_run_on_list(self):
|
||||||
|
self.assertRaises(TypeError, linter.run,
|
||||||
|
['h', 'e', 'l', 'l', 'o'], self.fake_config())
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from io import open
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from tests.common import RuleTestCase
|
from tests.common import RuleTestCase
|
||||||
@@ -120,7 +121,8 @@ conf_overrides = {
|
|||||||
'example-10.2': ('indentation: {indent-sequences: no}\n'),
|
'example-10.2': ('indentation: {indent-sequences: no}\n'),
|
||||||
}
|
}
|
||||||
|
|
||||||
files = os.listdir('tests/yaml-1.2-spec-examples')
|
files = os.listdir(os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
||||||
|
'yaml-1.2-spec-examples'))
|
||||||
assert len(files) == 132
|
assert len(files) == 132
|
||||||
|
|
||||||
|
|
||||||
@@ -178,7 +180,7 @@ for file in files:
|
|||||||
if file in pyyaml_blacklist:
|
if file in pyyaml_blacklist:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
with open('tests/yaml-1.2-spec-examples/' + file) as f:
|
with open('tests/yaml-1.2-spec-examples/' + file, encoding='utf-8') as f:
|
||||||
conf = conf_general + conf_overrides.get(file, '')
|
conf = conf_general + conf_overrides.get(file, '')
|
||||||
setattr(SpecificationTestCase, 'test_' + file,
|
setattr(SpecificationTestCase, 'test_' + file,
|
||||||
_gen_test(f.read(), conf))
|
_gen_test(f.read(), conf))
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ indentation, etc."""
|
|||||||
|
|
||||||
|
|
||||||
APP_NAME = 'yamllint'
|
APP_NAME = 'yamllint'
|
||||||
APP_VERSION = '1.0.2'
|
APP_VERSION = '1.0.4'
|
||||||
APP_DESCRIPTION = __doc__
|
APP_DESCRIPTION = __doc__
|
||||||
|
|
||||||
__author__ = u'Adrien Vergé'
|
__author__ = u'Adrien Vergé'
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ def run(input, conf):
|
|||||||
:param input: buffer, string or stream to read from
|
:param input: buffer, string or stream to read from
|
||||||
:param conf: yamllint configuration object
|
:param conf: yamllint configuration object
|
||||||
"""
|
"""
|
||||||
if type(input) == str:
|
if type(input) in (type(b''), type(u'')): # compat with Python 2 & 3
|
||||||
return _run(input, conf)
|
return _run(input, conf)
|
||||||
elif hasattr(input, 'read'): # Python 2's file or Python 3's io.IOBase
|
elif hasattr(input, 'read'): # Python 2's file or Python 3's io.IOBase
|
||||||
# We need to have everything in memory to parse correctly
|
# We need to have everything in memory to parse correctly
|
||||||
|
|||||||
Reference in New Issue
Block a user