Skip to content

Commit ae9f127

Browse files
committed
Run tests on Python 2
The README.rst example fails on Python 2 due to non-ascii, The same example has been added to test.py and runs correctly.
1 parent 598272a commit ae9f127

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

‎.travis.yml‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ install:
1414
- if [ "$TRAVIS_PYTHON_VERSION" == "2.7" ]; then pip --quiet install 3to2; fi
1515
- python setup.py --quiet install
1616

17+
# Prevent Python 2.7 from using the non-3to2 converted code.
18+
- mv language_check .language_check
19+
1720
script:
18-
- if [ "$TRAVIS_PYTHON_VERSION" != "2.7" ]; then python test.py; fi
21+
- ./test.py
1922

20-
- if [ "$TRAVIS_PYTHON_VERSION" != "2.7" ]; then ./run_doctest.py -v README.rst download_lt.py; fi
23+
- ./run_doctest.py -v download_lt.py
24+
- if [ "$TRAVIS_PYTHON_VERSION" != "2.7" ]; then ./run_doctest.py -v README.rst; fi
2125

22-
# Prevent Python 2.7 from using the non-3to2 converted code.
23-
- cd language_check; ../test.bash
26+
- bash test.bash
2427

2528
# Smoke test.
2629
- echo 'This is a sentence.' > foo.txt

‎test.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
"""Test suite for language_check."""
4+
from __future__ import unicode_literals
45

56
import unittest
67
import warnings
@@ -127,6 +128,24 @@ def test_disable_spellcheck(self):
127128
lang_check.enable_spellchecking()
128129
self.assertTrue(lang_check.check(sentence_with_misspelling))
129130

131+
def test_README_with_unicode(self):
132+
tool = language_check.LanguageTool('en-US')
133+
text = ('A sentence with a error in the '
134+
'Hitchhiker’s Guide tot he Galaxy')
135+
matches = tool.check(text)
136+
self.assertEqual(len(matches), 2)
137+
self.assertEqual((matches[0].fromy, matches[0].fromx),
138+
(0, 16))
139+
self.assertEqual((matches[0].ruleId, matches[0].replacements),
140+
('EN_A_VS_AN', ['an']))
141+
self.assertEqual((matches[1].fromy, matches[1].fromx),
142+
(0, 50))
143+
self.assertEqual((matches[1].ruleId, matches[1].replacements),
144+
('TOT_HE', ['to the']))
145+
corrected = language_check.correct(text, matches)
146+
self.assertEqual(corrected, 'A sentence with an error in the '
147+
'Hitchhiker’s Guide to the Galaxy')
148+
130149

131150
if __name__ == '__main__':
132151
unittest.main()

0 commit comments

Comments
 (0)