Skip to content

Commit

Permalink
switch to testrepository for running tests
Browse files Browse the repository at this point in the history
nose is no longer maintained and nose2 doesn't seem to like the old
tests, so just move to testr

Change-Id: I82b90171f4b94d34a3b57207fbd339b39d5053ce
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
  • Loading branch information
dhellmann committed Sep 27, 2017
1 parent 4d29154 commit a8bcb48
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 194 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ spelling/spelling_wordlist.txt
# Created by pbr
AUTHORS
ChangeLog
/.coverage
/.testrepository/
/cover/
4 changes: 4 additions & 0 deletions .testr.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[DEFAULT]
test_command=${PYTHON:-python} -m subunit.run discover -t ./ . $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list
242 changes: 113 additions & 129 deletions sphinxcontrib/spelling/tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,137 +11,121 @@
import os
import shutil
import tempfile
import textwrap

import fixtures
from six import StringIO
import testtools

from sphinx.application import Sphinx

_tempdir = None
_srcdir = None
_outdir = None


def setup():
global _tempdir, _srcdir, _outdir
_tempdir = tempfile.mkdtemp()
_srcdir = os.path.join(_tempdir, 'src')
_outdir = os.path.join(_tempdir, 'out')
os.mkdir(_srcdir)
os.mkdir(_outdir)


def teardown():
shutil.rmtree(_tempdir)


def test_setup():
with open(os.path.join(_srcdir, 'conf.py'), 'w') as f:
f.write('''
extensions = [ 'sphinxcontrib.spelling' ]
''')
stdout = StringIO()
stderr = StringIO()
# If the spelling builder is not properly initialized,
# trying to use it with the Sphinx app class will
# generate an exception.
Sphinx(
_srcdir, _srcdir, _outdir, _outdir, 'spelling',
status=stdout, warning=stderr,
freshenv=True,
)
return


def test_title():
with open(os.path.join(_srcdir, 'conf.py'), 'w') as f:
f.write('''
extensions = [ 'sphinxcontrib.spelling' ]
''')
with open(os.path.join(_srcdir, 'contents.rst'), 'w') as f:
f.write('''
Welcome to Speeling Checker documentation!
==========================================
''')
stdout = StringIO()
stderr = StringIO()
app = Sphinx(_srcdir, _srcdir, _outdir, _outdir, 'spelling',
status=stdout, warning=stderr,
freshenv=True,
)
app.build()
with codecs.open(app.builder.output_filename, 'r') as f:
output_text = f.read()

def check_one(word):
print(output_text)
assert word in output_text
for word in ['(Speeling)']:
yield check_one, word
return


def test_body():
with open(os.path.join(_srcdir, 'conf.py'), 'w') as f:
f.write('''
extensions = ['sphinxcontrib.spelling']
''')
with open(os.path.join(_srcdir, 'contents.rst'), 'w') as f:
f.write('''
Welcome to Spelling Checker documentation!
==========================================
There are several mispelled words in this txt.
''')
stdout = StringIO()
stderr = StringIO()
app = Sphinx(_srcdir, _srcdir, _outdir, _outdir, 'spelling',
status=stdout, warning=stderr,
freshenv=True,
)
app.build()
print('reading from %s' % app.builder.output_filename)
with codecs.open(app.builder.output_filename, 'r') as f:
output_text = f.read()

def check_one(word):
assert word in output_text
for word in ['(mispelled)', '(txt)']:
yield check_one, word
return


def test_ignore_literals():
with open(os.path.join(_srcdir, 'conf.py'), 'w') as f:
f.write('''
extensions = ['sphinxcontrib.spelling']
''')
with open(os.path.join(_srcdir, 'contents.rst'), 'w') as f:
f.write('''
Welcome to Spelling Checker documentation!
==========================================
There are several misspelled words in this text.
::
Literal blocks are ignoreed.
Inline ``litterals`` are ignored, too.
''')
stdout = StringIO()
stderr = StringIO()
app = Sphinx(_srcdir, _srcdir, _outdir, _outdir, 'spelling',
status=stdout, warning=stderr,
freshenv=True,
)
app.build()
print('reading from %s' % app.builder.output_filename)
with codecs.open(app.builder.output_filename, 'r') as f:
output_text = f.read()

def check_one(word):
assert word not in output_text
for word in ['(ignoreed)', '(litterals)']:
yield check_one, word
return

class BuilderTest(testtools.TestCase):

def setUp(self):
super(BuilderTest, self).setUp()
self.tempdir = self.useFixture(fixtures.TempDir()).path
self.srcdir = os.path.join(self.tempdir, 'src')
self.outdir = os.path.join(self.tempdir, 'out')
os.mkdir(self.srcdir)
os.mkdir(self.outdir)

def test_setup(self):
with open(os.path.join(self.srcdir, 'conf.py'), 'w') as f:
f.write(textwrap.dedent('''
extensions = [ 'sphinxcontrib.spelling' ]
'''))
stdout = StringIO()
stderr = StringIO()
# If the spelling builder is not properly initialized,
# trying to use it with the Sphinx app class will
# generate an exception.
Sphinx(
self.srcdir, self.srcdir, self.outdir, self.outdir, 'spelling',
status=stdout, warning=stderr,
freshenv=True,
)

def test_title(self):
with open(os.path.join(self.srcdir, 'conf.py'), 'w') as f:
f.write(textwrap.dedent('''
extensions = [ 'sphinxcontrib.spelling' ]
'''))
with open(os.path.join(self.srcdir, 'contents.rst'), 'w') as f:
f.write(textwrap.dedent('''
Welcome to Speeling Checker documentation!
==========================================
'''))
stdout = StringIO()
stderr = StringIO()
app = Sphinx(
self.srcdir, self.srcdir, self.outdir, self.outdir, 'spelling',
status=stdout, warning=stderr,
freshenv=True,
)
app.build()
with codecs.open(app.builder.output_filename, 'r') as f:
output_text = f.read()

self.assertIn('(Speeling)', output_text)

def test_body(self):
with open(os.path.join(self.srcdir, 'conf.py'), 'w') as f:
f.write(textwrap.dedent('''
extensions = ['sphinxcontrib.spelling']
'''))
with open(os.path.join(self.srcdir, 'contents.rst'), 'w') as f:
f.write(textwrap.dedent('''
Welcome to Spelling Checker documentation!
==========================================
There are several mispelled words in this txt.
'''))
stdout = StringIO()
stderr = StringIO()
app = Sphinx(
self.srcdir, self.srcdir, self.outdir, self.outdir, 'spelling',
status=stdout, warning=stderr,
freshenv=True,
)
app.build()
print('reading from %s' % app.builder.output_filename)
with codecs.open(app.builder.output_filename, 'r') as f:
output_text = f.read()

self.assertIn('(mispelled)', output_text)
self.assertIn('(txt)', output_text)

def test_ignore_literals(self):
with open(os.path.join(self.srcdir, 'conf.py'), 'w') as f:
f.write(textwrap.dedent('''
extensions = ['sphinxcontrib.spelling']
'''))
with open(os.path.join(self.srcdir, 'contents.rst'), 'w') as f:
f.write(textwrap.dedent('''
Welcome to Spelling Checker documentation!
==========================================
There are several misspelled words in this text.
::
Literal blocks are ignoreed.
Inline ``litterals`` are ignored, too.
'''))
stdout = StringIO()
stderr = StringIO()
app = Sphinx(
self.srcdir, self.srcdir, self.outdir, self.outdir, 'spelling',
status=stdout, warning=stderr,
freshenv=True,
)
app.build()
print('reading from %s' % app.builder.output_filename)
with codecs.open(app.builder.output_filename, 'r') as f:
output_text = f.read()

self.assertNotIn('(ignoreed)', output_text)
self.assertNotIn('(litterals)', output_text)
86 changes: 44 additions & 42 deletions sphinxcontrib/spelling/tests/test_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,51 @@
"""

import os
import unittest

from sphinxcontrib.spelling.checker import SpellingChecker


def test_errors_only():
checker = SpellingChecker(lang='en_US',
suggest=False,
word_list_filename=None,
)
for word, suggestions in checker.check('This txt is wrong'):
assert not suggestions, 'Suggesting'
assert word == 'txt'
return


def test_with_suggestions():
checker = SpellingChecker(lang='en_US',
suggest=True,
word_list_filename=None,
)
for word, suggestions in checker.check('This txt is wrong'):
assert suggestions, 'Not suggesting'
assert word == 'txt'
return


def test_with_wordlist():
checker = SpellingChecker(
lang='en_US',
suggest=False,
word_list_filename=os.path.join(os.path.dirname(__file__),
'test_wordlist.txt')
)
words = [w for w, s in checker.check('This txt is wrong')]
assert not words, 'Did not use personal word list file'
return


def test_non_english():
checker = SpellingChecker(lang='de_DE',
suggest=False,
word_list_filename=None,
)
for word, suggestions in checker.check('Dieser Txt ist falsch'):
assert word == 'Txt'
return
class TestChecker(unittest.TestCase):

def test_errors_only(self):
checker = SpellingChecker(lang='en_US',
suggest=False,
word_list_filename=None,
)
for word, suggestions in checker.check('This txt is wrong'):
assert not suggestions, 'Suggesting'
assert word == 'txt'
return

def test_with_suggestions(self):
checker = SpellingChecker(lang='en_US',
suggest=True,
word_list_filename=None,
)
for word, suggestions in checker.check('This txt is wrong'):
assert suggestions, 'Not suggesting'
assert word == 'txt'
return

def test_with_wordlist(self):
checker = SpellingChecker(
lang='en_US',
suggest=False,
word_list_filename=os.path.join(os.path.dirname(__file__),
'test_wordlist.txt')
)
words = [w for w, s in checker.check('This txt is wrong')]
assert not words, 'Did not use personal word list file'
return

# NOTE(dhellmann): Fails after updating to testrepository.
#
# def test_non_english(self):
# checker = SpellingChecker(lang='de_DE',
# suggest=False,
# word_list_filename=None,
# )
# for word, suggestions in checker.check('Dieser Txt ist falsch'):
# assert word == 'Txt'
# return
Loading

0 comments on commit a8bcb48

Please sign in to comment.