mirror of
https://github.com/codespell-project/codespell.git
synced 2025-05-23 18:36:45 +08:00
FIX: Caps and pytest (#482)
* FIX: Caps and pytest * FIX: Check in code * FIX: Check for unique names * FIX: Minor fixes * FIX: More checks
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ ld
|
|||||||
codespell.egg-info
|
codespell.egg-info
|
||||||
*.pyc
|
*.pyc
|
||||||
.cache/
|
.cache/
|
||||||
|
.pytest_cache/
|
||||||
|
@ -39,7 +39,7 @@ before_install:
|
|||||||
- source venv/bin/activate
|
- source venv/bin/activate
|
||||||
- python --version # just to check
|
- python --version # just to check
|
||||||
- pip install -U pip wheel # upgrade to latest pip find 3.5 wheels; wheel to avoid errors
|
- pip install -U pip wheel # upgrade to latest pip find 3.5 wheels; wheel to avoid errors
|
||||||
- retry pip install nose flake8 coverage codecov chardet setuptools
|
- retry pip install pytest pytest-cov pytest-sugar flake8 coverage codecov chardet setuptools
|
||||||
- cd $SRC_DIR
|
- cd $SRC_DIR
|
||||||
|
|
||||||
install:
|
install:
|
||||||
@ -51,7 +51,7 @@ script:
|
|||||||
# this file has an error
|
# this file has an error
|
||||||
- "! codespell codespell_lib/tests/test_basic.py"
|
- "! codespell codespell_lib/tests/test_basic.py"
|
||||||
- flake8
|
- flake8
|
||||||
- nosetests
|
- pytest codespell_lib
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
- codecov
|
- codecov
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
environment:
|
environment:
|
||||||
global:
|
global:
|
||||||
PYTHON: "C:\\conda"
|
PYTHON: "C:\\conda"
|
||||||
CONDA_DEPENDENCIES: "nose setuptools flake8 coverage chardet"
|
CONDA_DEPENDENCIES: "pytest pytest-cov setuptools flake8 coverage chardet"
|
||||||
PIP_DEPENDENCIES: "codecov"
|
PIP_DEPENDENCIES: "codecov pytest-sugar"
|
||||||
matrix:
|
matrix:
|
||||||
- PYTHON_VERSION: "2.7"
|
- PYTHON_VERSION: "2.7"
|
||||||
PYTHON_ARCH: "32"
|
PYTHON_ARCH: "32"
|
||||||
@ -21,7 +21,7 @@ build: false # Not a C# project, build stuff at the test step instead.
|
|||||||
test_script:
|
test_script:
|
||||||
- "codespell --help"
|
- "codespell --help"
|
||||||
- "flake8"
|
- "flake8"
|
||||||
- "nosetests"
|
- "pytest codespell_lib"
|
||||||
|
|
||||||
on_success:
|
on_success:
|
||||||
- "codecov"
|
- "codecov"
|
||||||
|
@ -304,6 +304,10 @@ def build_dict(filename):
|
|||||||
with codecs.open(filename, mode='r', buffering=1, encoding='utf-8') as f:
|
with codecs.open(filename, mode='r', buffering=1, encoding='utf-8') as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
[key, data] = line.split('->')
|
[key, data] = line.split('->')
|
||||||
|
# TODO for now, convert both to lower. Someday we can maybe add
|
||||||
|
# support for fixing caps.
|
||||||
|
key = key.lower()
|
||||||
|
data = data.lower()
|
||||||
if key in ignore_words:
|
if key in ignore_words:
|
||||||
continue
|
continue
|
||||||
data = data.strip()
|
data = data.strip()
|
||||||
@ -588,7 +592,7 @@ def main(*args):
|
|||||||
|
|
||||||
dictionaries = options.dictionary or [default_dictionary]
|
dictionaries = options.dictionary or [default_dictionary]
|
||||||
for dictionary in dictionaries:
|
for dictionary in dictionaries:
|
||||||
if dictionary is "-":
|
if dictionary == "-":
|
||||||
dictionary = default_dictionary
|
dictionary = default_dictionary
|
||||||
if not os.path.exists(dictionary):
|
if not os.path.exists(dictionary):
|
||||||
print('ERROR: cannot find dictionary file: %s' % dictionary,
|
print('ERROR: cannot find dictionary file: %s' % dictionary,
|
||||||
|
@ -192,7 +192,6 @@ achievment->achievement
|
|||||||
achievments->achievements
|
achievments->achievements
|
||||||
achitecture->architecture
|
achitecture->architecture
|
||||||
achitectures->architectures
|
achitectures->architectures
|
||||||
achive->achieve
|
|
||||||
achive->achieve, archive,
|
achive->achieve, archive,
|
||||||
achived->achieved, archived,
|
achived->achieved, archived,
|
||||||
achivement->achievement
|
achivement->achievement
|
||||||
@ -784,7 +783,7 @@ aparment->apartment
|
|||||||
apear->appear
|
apear->appear
|
||||||
apeends->appends
|
apeends->appends
|
||||||
apendix->appendix
|
apendix->appendix
|
||||||
apenines->apennines, Apennines,
|
apenines->Apennines
|
||||||
aplication->application
|
aplication->application
|
||||||
aplied->applied
|
aplied->applied
|
||||||
apllicatin->application
|
apllicatin->application
|
||||||
@ -809,7 +808,7 @@ appedn->append
|
|||||||
appendent->appended
|
appendent->appended
|
||||||
appendign->appending
|
appendign->appending
|
||||||
appeneded->appended
|
appeneded->appended
|
||||||
appenines->apennines, Apennines,
|
appenines->Apennines
|
||||||
appens->appends
|
appens->appends
|
||||||
apperance->appearance
|
apperance->appearance
|
||||||
apperances->appearances
|
apperances->appearances
|
||||||
@ -1533,7 +1532,7 @@ bootstapped->bootstrapped
|
|||||||
bootstapping->bootstrapping
|
bootstapping->bootstrapping
|
||||||
bootstaps->bootstraps
|
bootstaps->bootstraps
|
||||||
boradcast->broadcast
|
boradcast->broadcast
|
||||||
bordrelines->borderline
|
bordreline->borderline
|
||||||
bordrelines->borderlines
|
bordrelines->borderlines
|
||||||
borke->broke
|
borke->broke
|
||||||
bothe->both
|
bothe->both
|
||||||
@ -1903,8 +1902,7 @@ chanel->channel
|
|||||||
changable->changeable
|
changable->changeable
|
||||||
changuing->changing
|
changuing->changing
|
||||||
chanined->chained
|
chanined->chained
|
||||||
chaning->chaining
|
chaning->chaining, changing,
|
||||||
chaning->changing
|
|
||||||
channle->channel
|
channle->channel
|
||||||
channles->channels
|
channles->channels
|
||||||
channnel->channel
|
channnel->channel
|
||||||
@ -2326,7 +2324,6 @@ competance->competence
|
|||||||
competant->competent
|
competant->competent
|
||||||
competative->competitive
|
competative->competitive
|
||||||
competion->competition, completion,
|
competion->competition, completion,
|
||||||
competion->completion
|
|
||||||
competions->completions
|
competions->completions
|
||||||
competitiion->competition
|
competitiion->competition
|
||||||
competive->competitive
|
competive->competitive
|
||||||
@ -2971,7 +2968,6 @@ covnert->convert
|
|||||||
coyp->copy
|
coyp->copy
|
||||||
coypright->copyright
|
coypright->copyright
|
||||||
cpation->caption
|
cpation->caption
|
||||||
cpoy->copy
|
|
||||||
cpoy->coy, copy,
|
cpoy->coy, copy,
|
||||||
craete->create
|
craete->create
|
||||||
crahses->crashes
|
crahses->crashes
|
||||||
@ -3125,8 +3121,7 @@ decalratiosn->declarations
|
|||||||
deccelerate->decelerate
|
deccelerate->decelerate
|
||||||
decendant->descendant
|
decendant->descendant
|
||||||
decendants->descendants
|
decendants->descendants
|
||||||
decendent->descendant
|
decendent->descendent, descendant,
|
||||||
decendent->descendent
|
|
||||||
decendents->descendants
|
decendents->descendants
|
||||||
decideable->decidable
|
decideable->decidable
|
||||||
decidely->decidedly
|
decidely->decidedly
|
||||||
@ -5704,7 +5699,6 @@ imigrated->emigrated, immigrated,
|
|||||||
imigration->emigration, immigration,
|
imigration->emigration, immigration,
|
||||||
imilar->similar
|
imilar->similar
|
||||||
iminent->eminent, imminent, immanent,
|
iminent->eminent, imminent, immanent,
|
||||||
iminent->imminent
|
|
||||||
immeadiately->immediately
|
immeadiately->immediately
|
||||||
immedate->immediate
|
immedate->immediate
|
||||||
immedately->immediately
|
immedately->immediately
|
||||||
@ -6281,7 +6275,6 @@ intiailises->initialises
|
|||||||
intiailize->initialize
|
intiailize->initialize
|
||||||
intiailized->initialized
|
intiailized->initialized
|
||||||
intiailizes->initializes
|
intiailizes->initializes
|
||||||
intiailizing->initialising
|
|
||||||
intiailizing->initializing
|
intiailizing->initializing
|
||||||
intial->initial
|
intial->initial
|
||||||
intialisation->initialisation
|
intialisation->initialisation
|
||||||
@ -6669,7 +6662,6 @@ mamalian->mammalian
|
|||||||
mamory->memory
|
mamory->memory
|
||||||
managable->manageable, manageably,
|
managable->manageable, manageably,
|
||||||
managment->management
|
managment->management
|
||||||
mananged->managed
|
|
||||||
manangement->management
|
manangement->management
|
||||||
mandetory->mandatory
|
mandetory->mandatory
|
||||||
maneouvre->manoeuvre
|
maneouvre->manoeuvre
|
||||||
@ -7030,8 +7022,7 @@ moent->moment
|
|||||||
moeny->money
|
moeny->money
|
||||||
mofdified->modified
|
mofdified->modified
|
||||||
mohammedans->muslims
|
mohammedans->muslims
|
||||||
moil->mohel
|
moil->soil, mohel,
|
||||||
moil->soil
|
|
||||||
moint->mount
|
moint->mount
|
||||||
moleclues->molecules
|
moleclues->molecules
|
||||||
momemtn->moment
|
momemtn->moment
|
||||||
@ -7057,19 +7048,17 @@ mordern->modern
|
|||||||
moreso->more, more so,
|
moreso->more, more so,
|
||||||
morever->moreover
|
morever->moreover
|
||||||
morgage->mortgage
|
morgage->mortgage
|
||||||
Morisette->Morissette
|
morisette->morissette
|
||||||
morover->moreover
|
morrisette->morissette
|
||||||
Morrisette->Morissette
|
|
||||||
morroccan->moroccan
|
morroccan->moroccan
|
||||||
morrocco->morocco
|
morrocco->morocco
|
||||||
morroco->morocco
|
morroco->morocco
|
||||||
mortage->mortgage
|
mortage->mortgage
|
||||||
mose->more
|
mose->more, mouse,
|
||||||
mose->mouse
|
|
||||||
moslty->mostly
|
moslty->mostly
|
||||||
mosture->moisture
|
mosture->moisture
|
||||||
motiviated->motivated
|
motiviated->motivated
|
||||||
mould->mold, mould, module
|
mould->mold, mould, module,
|
||||||
mounth->month
|
mounth->month
|
||||||
mouspointer->mousepointer
|
mouspointer->mousepointer
|
||||||
movebackwrd->movebackward
|
movebackwrd->movebackward
|
||||||
@ -7283,7 +7272,7 @@ noveau->nouveau
|
|||||||
Novermber->November
|
Novermber->November
|
||||||
nowdays->nowadays
|
nowdays->nowadays
|
||||||
nowe->now
|
nowe->now
|
||||||
nto->not, disable due to \n
|
nto->not, disabled due to \n
|
||||||
nubmer->number
|
nubmer->number
|
||||||
nubmers->numbers
|
nubmers->numbers
|
||||||
nucular->nuclear
|
nucular->nuclear
|
||||||
@ -9245,7 +9234,6 @@ sempahore->semaphore
|
|||||||
sempahores->semaphores
|
sempahores->semaphores
|
||||||
senario->scenario
|
senario->scenario
|
||||||
senarios->scenarios
|
senarios->scenarios
|
||||||
sence->sense
|
|
||||||
sence->sense, since,
|
sence->sense, since,
|
||||||
sensistive->sensitive
|
sensistive->sensitive
|
||||||
sensistively->sensitively
|
sensistively->sensitively
|
||||||
@ -9555,7 +9543,7 @@ specificed->specified
|
|||||||
specificiation->specification
|
specificiation->specification
|
||||||
specificiations->specifications
|
specificiations->specifications
|
||||||
specificly->specifically
|
specificly->specifically
|
||||||
specificy->specify, specificity, specifically
|
specificy->specify, specificity, specifically,
|
||||||
specifing->specifying
|
specifing->specifying
|
||||||
specifiy->specify
|
specifiy->specify
|
||||||
specifiying->specifying
|
specifiying->specifying
|
||||||
@ -10244,7 +10232,7 @@ tkaing->taking
|
|||||||
tlaking->talking
|
tlaking->talking
|
||||||
to to->to, to do,
|
to to->to, to do,
|
||||||
tobbaco->tobacco
|
tobbaco->tobacco
|
||||||
todays->today's, disable because of var names
|
todays->today's, disabled because of var names
|
||||||
todya->today
|
todya->today
|
||||||
togehter->together
|
togehter->together
|
||||||
toghether->together
|
toghether->together
|
||||||
@ -10890,9 +10878,9 @@ vulnerablility->vulnerability
|
|||||||
vyer->very
|
vyer->very
|
||||||
vyre->very
|
vyre->very
|
||||||
waht->what
|
waht->what
|
||||||
wan't->want, wasn't
|
wan't->want, wasn't,
|
||||||
wan->want
|
wan->want
|
||||||
wan;t->want, wasn't
|
wan;t->want, wasn't,
|
||||||
wanna->want to, disabled because one might want to allow informal spelling
|
wanna->want to, disabled because one might want to allow informal spelling
|
||||||
want's->wants
|
want's->wants
|
||||||
want;s->wants
|
want;s->wants
|
||||||
|
@ -10,11 +10,12 @@ import sys
|
|||||||
import tempfile
|
import tempfile
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from nose.tools import with_setup, assert_equal, assert_true
|
import pytest
|
||||||
|
|
||||||
import codespell_lib as cs
|
import codespell_lib as cs
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='function')
|
||||||
def reload_codespell_lib():
|
def reload_codespell_lib():
|
||||||
try:
|
try:
|
||||||
reload # Python 2.7
|
reload # Python 2.7
|
||||||
@ -37,63 +38,63 @@ def test_command():
|
|||||||
"""Test running the codespell executable"""
|
"""Test running the codespell executable"""
|
||||||
# With no arguments does "."
|
# With no arguments does "."
|
||||||
with TemporaryDirectory() as d:
|
with TemporaryDirectory() as d:
|
||||||
assert_equal(run_codespell(cwd=d), 0)
|
assert run_codespell(cwd=d) == 0
|
||||||
with open(op.join(d, 'bad.txt'), 'w') as f:
|
with open(op.join(d, 'bad.txt'), 'w') as f:
|
||||||
f.write('abandonned\nAbandonned\nABANDONNED\nAbAnDoNnEd')
|
f.write('abandonned\nAbandonned\nABANDONNED\nAbAnDoNnEd')
|
||||||
assert_equal(run_codespell(cwd=d), 4)
|
assert run_codespell(cwd=d) == 4
|
||||||
|
|
||||||
|
|
||||||
def test_basic():
|
def test_basic():
|
||||||
"""Test some basic functionality"""
|
"""Test some basic functionality"""
|
||||||
assert_equal(cs.main('_does_not_exist_'), 0)
|
assert cs.main('_does_not_exist_') == 0
|
||||||
with tempfile.NamedTemporaryFile('w') as f:
|
with tempfile.NamedTemporaryFile('w') as f:
|
||||||
pass
|
pass
|
||||||
with CaptureStdout() as sio:
|
with CaptureStdout() as sio:
|
||||||
assert_equal(cs.main('-D', 'foo', f.name), 1) # missing dictionary
|
assert cs.main('-D', 'foo', f.name) == 1, 'missing dictionary'
|
||||||
try:
|
try:
|
||||||
assert_true('cannot find dictionary' in sio[1])
|
assert 'cannot find dictionary' in sio[1]
|
||||||
assert_equal(cs.main(f.name), 0) # empty file
|
assert cs.main(f.name) == 0, 'empty file'
|
||||||
with open(f.name, 'a') as f:
|
with open(f.name, 'a') as f:
|
||||||
f.write('this is a test file\n')
|
f.write('this is a test file\n')
|
||||||
assert_equal(cs.main(f.name), 0) # good
|
assert cs.main(f.name) == 0, 'good'
|
||||||
with open(f.name, 'a') as f:
|
with open(f.name, 'a') as f:
|
||||||
f.write('abandonned\n')
|
f.write('abandonned\n')
|
||||||
assert_equal(cs.main(f.name), 1) # bad
|
assert cs.main(f.name) == 1, 'bad'
|
||||||
with open(f.name, 'a') as f:
|
with open(f.name, 'a') as f:
|
||||||
f.write('abandonned\n')
|
f.write('abandonned\n')
|
||||||
assert_equal(cs.main(f.name), 2) # worse
|
assert cs.main(f.name) == 2, 'worse'
|
||||||
finally:
|
finally:
|
||||||
os.remove(f.name)
|
os.remove(f.name)
|
||||||
with TemporaryDirectory() as d:
|
with TemporaryDirectory() as d:
|
||||||
with open(op.join(d, 'bad.txt'), 'w') as f:
|
with open(op.join(d, 'bad.txt'), 'w') as f:
|
||||||
f.write('abandonned\nAbandonned\nABANDONNED\nAbAnDoNnEd')
|
f.write('abandonned\nAbandonned\nABANDONNED\nAbAnDoNnEd')
|
||||||
assert_equal(cs.main(d), 4)
|
assert cs.main(d) == 4
|
||||||
with CaptureStdout() as sio:
|
with CaptureStdout() as sio:
|
||||||
assert_equal(cs.main('-w', d), 0)
|
assert cs.main('-w', d) == 0
|
||||||
assert_true('FIXED:' in sio[1])
|
assert 'FIXED:' in sio[1]
|
||||||
with open(op.join(d, 'bad.txt')) as f:
|
with open(op.join(d, 'bad.txt')) as f:
|
||||||
new_content = f.read()
|
new_content = f.read()
|
||||||
assert_equal(cs.main(d), 0)
|
assert cs.main(d) == 0
|
||||||
assert_equal(new_content, 'abandoned\nAbandoned\nABANDONED\nabandoned')
|
assert new_content == 'abandoned\nAbandoned\nABANDONED\nabandoned'
|
||||||
|
|
||||||
with open(op.join(d, 'bad.txt'), 'w') as f:
|
with open(op.join(d, 'bad.txt'), 'w') as f:
|
||||||
f.write('abandonned abandonned\n')
|
f.write('abandonned abandonned\n')
|
||||||
assert_equal(cs.main(d), 2)
|
assert cs.main(d) == 2
|
||||||
with CaptureStdout() as sio:
|
with CaptureStdout() as sio:
|
||||||
assert_equal(cs.main('-q', '16', '-w', d), 0)
|
assert cs.main('-q', '16', '-w', d) == 0
|
||||||
assert_equal(sio[0], '')
|
assert sio[0] == ''
|
||||||
assert_equal(cs.main(d), 0)
|
assert cs.main(d) == 0
|
||||||
|
|
||||||
# empty directory
|
# empty directory
|
||||||
os.mkdir(op.join(d, 'test'))
|
os.mkdir(op.join(d, 'test'))
|
||||||
assert_equal(cs.main(d), 0)
|
assert cs.main(d) == 0
|
||||||
|
|
||||||
# hidden file
|
# hidden file
|
||||||
with open(op.join(d, 'test.txt'), 'w') as f:
|
with open(op.join(d, 'test.txt'), 'w') as f:
|
||||||
f.write('abandonned\n')
|
f.write('abandonned\n')
|
||||||
assert_equal(cs.main(op.join(d, 'test.txt')), 1)
|
assert cs.main(op.join(d, 'test.txt')) == 1
|
||||||
os.rename(op.join(d, 'test.txt'), op.join(d, '.test.txt'))
|
os.rename(op.join(d, 'test.txt'), op.join(d, '.test.txt'))
|
||||||
assert_equal(cs.main(op.join(d, '.test.txt')), 0)
|
assert cs.main(op.join(d, '.test.txt')) == 0
|
||||||
|
|
||||||
|
|
||||||
def test_interactivity():
|
def test_interactivity():
|
||||||
@ -103,20 +104,20 @@ def test_interactivity():
|
|||||||
with tempfile.NamedTemporaryFile('w') as f:
|
with tempfile.NamedTemporaryFile('w') as f:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
assert_equal(cs.main(f.name), 0) # empty file
|
assert cs.main(f.name) == 0, 'empty file'
|
||||||
with open(f.name, 'w') as f:
|
with open(f.name, 'w') as f:
|
||||||
f.write('abandonned\n')
|
f.write('abandonned\n')
|
||||||
assert_equal(cs.main('-i', '-1', f.name), 1) # bad
|
assert cs.main('-i', '-1', f.name) == 1, 'bad'
|
||||||
with FakeStdin('y\n'):
|
with FakeStdin('y\n'):
|
||||||
assert_equal(cs.main('-i', '3', f.name), 1)
|
assert cs.main('-i', '3', f.name) == 1
|
||||||
with CaptureStdout() as sio:
|
with CaptureStdout() as sio:
|
||||||
with FakeStdin('n\n'):
|
with FakeStdin('n\n'):
|
||||||
assert_equal(cs.main('-w', '-i', '3', f.name), 0)
|
assert cs.main('-w', '-i', '3', f.name) == 0
|
||||||
assert_true('==>' in sio[0])
|
assert '==>' in sio[0]
|
||||||
with CaptureStdout():
|
with CaptureStdout():
|
||||||
with FakeStdin('x\ny\n'):
|
with FakeStdin('x\ny\n'):
|
||||||
assert_equal(cs.main('-w', '-i', '3', f.name), 0)
|
assert cs.main('-w', '-i', '3', f.name) == 0
|
||||||
assert_equal(cs.main(f.name), 0)
|
assert cs.main(f.name) == 0
|
||||||
finally:
|
finally:
|
||||||
os.remove(f.name)
|
os.remove(f.name)
|
||||||
|
|
||||||
@ -126,11 +127,11 @@ def test_interactivity():
|
|||||||
try:
|
try:
|
||||||
with open(f.name, 'w') as f:
|
with open(f.name, 'w') as f:
|
||||||
f.write('abandonned\n')
|
f.write('abandonned\n')
|
||||||
assert_equal(cs.main(f.name), 1)
|
assert cs.main(f.name) == 1
|
||||||
with CaptureStdout():
|
with CaptureStdout():
|
||||||
with FakeStdin(' '): # blank input -> Y
|
with FakeStdin(' '): # blank input -> Y
|
||||||
assert_equal(cs.main('-w', '-i', '3', f.name), 0)
|
assert cs.main('-w', '-i', '3', f.name) == 0
|
||||||
assert_equal(cs.main(f.name), 0)
|
assert cs.main(f.name) == 0
|
||||||
finally:
|
finally:
|
||||||
os.remove(f.name)
|
os.remove(f.name)
|
||||||
|
|
||||||
@ -141,27 +142,27 @@ def test_interactivity():
|
|||||||
with open(f.name, 'w') as f:
|
with open(f.name, 'w') as f:
|
||||||
f.write('ackward\n')
|
f.write('ackward\n')
|
||||||
|
|
||||||
assert_equal(cs.main(f.name), 1)
|
assert cs.main(f.name) == 1
|
||||||
with CaptureStdout():
|
with CaptureStdout():
|
||||||
with FakeStdin(' \n'): # blank input -> nothing
|
with FakeStdin(' \n'): # blank input -> nothing
|
||||||
assert_equal(cs.main('-w', '-i', '3', f.name), 0)
|
assert cs.main('-w', '-i', '3', f.name) == 0
|
||||||
assert_equal(cs.main(f.name), 1)
|
assert cs.main(f.name) == 1
|
||||||
with CaptureStdout():
|
with CaptureStdout():
|
||||||
with FakeStdin('0\n'): # blank input -> nothing
|
with FakeStdin('0\n'): # blank input -> nothing
|
||||||
assert_equal(cs.main('-w', '-i', '3', f.name), 0)
|
assert cs.main('-w', '-i', '3', f.name) == 0
|
||||||
assert_equal(cs.main(f.name), 0)
|
assert cs.main(f.name) == 0
|
||||||
with open(f.name, 'r') as f_read:
|
with open(f.name, 'r') as f_read:
|
||||||
assert_equal(f_read.read(), 'awkward\n')
|
assert f_read.read() == 'awkward\n'
|
||||||
with open(f.name, 'w') as f:
|
with open(f.name, 'w') as f:
|
||||||
f.write('ackward\n')
|
f.write('ackward\n')
|
||||||
assert_equal(cs.main(f.name), 1)
|
assert cs.main(f.name) == 1
|
||||||
with CaptureStdout() as sio:
|
with CaptureStdout() as sio:
|
||||||
with FakeStdin('x\n1\n'): # blank input -> nothing
|
with FakeStdin('x\n1\n'): # blank input -> nothing
|
||||||
assert_equal(cs.main('-w', '-i', '3', f.name), 0)
|
assert cs.main('-w', '-i', '3', f.name) == 0
|
||||||
assert_true('a valid option' in sio[0])
|
assert 'a valid option' in sio[0]
|
||||||
assert_equal(cs.main(f.name), 0)
|
assert cs.main(f.name) == 0
|
||||||
with open(f.name, 'r') as f:
|
with open(f.name, 'r') as f:
|
||||||
assert_equal(f.read(), 'backward\n')
|
assert f.read() == 'backward\n'
|
||||||
finally:
|
finally:
|
||||||
os.remove(f.name)
|
os.remove(f.name)
|
||||||
|
|
||||||
@ -174,26 +175,25 @@ def test_summary():
|
|||||||
with CaptureStdout() as sio:
|
with CaptureStdout() as sio:
|
||||||
cs.main(f.name)
|
cs.main(f.name)
|
||||||
for ii in range(2):
|
for ii in range(2):
|
||||||
assert_equal(sio[ii], '') # no output
|
assert sio[ii] == '', 'no output'
|
||||||
with CaptureStdout() as sio:
|
with CaptureStdout() as sio:
|
||||||
cs.main(f.name, '--summary')
|
cs.main(f.name, '--summary')
|
||||||
assert_equal(sio[1], '') # stderr
|
assert sio[1] == '', 'stderr'
|
||||||
assert_true('SUMMARY' in sio[0])
|
assert 'SUMMARY' in sio[0]
|
||||||
assert_equal(len(sio[0].split('\n')), 5) # no output
|
assert len(sio[0].split('\n')) == 5, 'no output'
|
||||||
with open(f.name, 'w') as f:
|
with open(f.name, 'w') as f:
|
||||||
f.write('abandonned\nabandonned')
|
f.write('abandonned\nabandonned')
|
||||||
with CaptureStdout() as sio:
|
with CaptureStdout() as sio:
|
||||||
cs.main(f.name, '--summary')
|
cs.main(f.name, '--summary')
|
||||||
assert_equal(sio[1], '') # stderr
|
assert sio[1] == '', 'stderr'
|
||||||
assert_true('SUMMARY' in sio[0])
|
assert 'SUMMARY' in sio[0]
|
||||||
assert_equal(len(sio[0].split('\n')), 7)
|
assert len(sio[0].split('\n')) == 7
|
||||||
assert_true('abandonned' in sio[0].split()[-2])
|
assert 'abandonned' in sio[0].split()[-2]
|
||||||
finally:
|
finally:
|
||||||
os.remove(f.name)
|
os.remove(f.name)
|
||||||
|
|
||||||
|
|
||||||
@with_setup(reload_codespell_lib, reload_codespell_lib)
|
def test_ignore_dictionary(reload_codespell_lib):
|
||||||
def test_ignore_dictionary():
|
|
||||||
"""Test ignore dictionary functionality"""
|
"""Test ignore dictionary functionality"""
|
||||||
with TemporaryDirectory() as d:
|
with TemporaryDirectory() as d:
|
||||||
with open(op.join(d, 'bad.txt'), 'w') as f:
|
with open(op.join(d, 'bad.txt'), 'w') as f:
|
||||||
@ -202,17 +202,16 @@ def test_ignore_dictionary():
|
|||||||
pass
|
pass
|
||||||
with open(f.name, 'w') as f:
|
with open(f.name, 'w') as f:
|
||||||
f.write('abandonned\n')
|
f.write('abandonned\n')
|
||||||
assert_equal(cs.main('-I', f.name, d), 1)
|
assert cs.main('-I', f.name, d) == 1
|
||||||
|
|
||||||
|
|
||||||
@with_setup(reload_codespell_lib, reload_codespell_lib)
|
def test_custom_regex(reload_codespell_lib):
|
||||||
def test_custom_regex():
|
|
||||||
"""Test custom word regex"""
|
"""Test custom word regex"""
|
||||||
with TemporaryDirectory() as d:
|
with TemporaryDirectory() as d:
|
||||||
with open(op.join(d, 'bad.txt'), 'w') as f:
|
with open(op.join(d, 'bad.txt'), 'w') as f:
|
||||||
f.write('abandonned_abondon\n')
|
f.write('abandonned_abondon\n')
|
||||||
assert_equal(cs.main(d), 0)
|
assert cs.main(d) == 0
|
||||||
assert_equal(cs.main('-r', "[a-z]+", d), 2)
|
assert cs.main('-r', "[a-z]+", d) == 2
|
||||||
|
|
||||||
|
|
||||||
def test_exclude_file():
|
def test_exclude_file():
|
||||||
@ -220,13 +219,13 @@ def test_exclude_file():
|
|||||||
with TemporaryDirectory() as d:
|
with TemporaryDirectory() as d:
|
||||||
with open(op.join(d, 'bad.txt'), 'wb') as f:
|
with open(op.join(d, 'bad.txt'), 'wb') as f:
|
||||||
f.write('abandonned 1\nabandonned 2\n'.encode('utf-8'))
|
f.write('abandonned 1\nabandonned 2\n'.encode('utf-8'))
|
||||||
assert_equal(cs.main(d), 2)
|
assert cs.main(d) == 2
|
||||||
with tempfile.NamedTemporaryFile('w') as f:
|
with tempfile.NamedTemporaryFile('w') as f:
|
||||||
pass
|
pass
|
||||||
with open(f.name, 'wb') as f:
|
with open(f.name, 'wb') as f:
|
||||||
f.write('abandonned 1\n'.encode('utf-8'))
|
f.write('abandonned 1\n'.encode('utf-8'))
|
||||||
assert_equal(cs.main(d), 2)
|
assert cs.main(d) == 2
|
||||||
assert_equal(cs.main('-x', f.name, d), 1)
|
assert cs.main('-x', f.name, d) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_encoding():
|
def test_encoding():
|
||||||
@ -235,24 +234,24 @@ def test_encoding():
|
|||||||
with tempfile.NamedTemporaryFile('wb') as f:
|
with tempfile.NamedTemporaryFile('wb') as f:
|
||||||
pass
|
pass
|
||||||
# with CaptureStdout() as sio:
|
# with CaptureStdout() as sio:
|
||||||
assert_equal(cs.main(f.name), 0)
|
assert cs.main(f.name) == 0
|
||||||
try:
|
try:
|
||||||
with open(f.name, 'wb') as f:
|
with open(f.name, 'wb') as f:
|
||||||
f.write(u'naïve\n'.encode('utf-8'))
|
f.write(u'naïve\n'.encode('utf-8'))
|
||||||
assert_equal(cs.main(f.name), 0)
|
assert cs.main(f.name) == 0
|
||||||
assert_equal(cs.main('-e', f.name), 0)
|
assert cs.main('-e', f.name) == 0
|
||||||
with open(f.name, 'ab') as f:
|
with open(f.name, 'ab') as f:
|
||||||
f.write(u'naieve\n'.encode('utf-8'))
|
f.write(u'naieve\n'.encode('utf-8'))
|
||||||
assert_equal(cs.main(f.name), 1)
|
assert cs.main(f.name) == 1
|
||||||
# Binary file warning
|
# Binary file warning
|
||||||
with open(f.name, 'wb') as f:
|
with open(f.name, 'wb') as f:
|
||||||
f.write(b'\x00\x00naiive\x00\x00')
|
f.write(b'\x00\x00naiive\x00\x00')
|
||||||
with CaptureStdout() as sio:
|
with CaptureStdout() as sio:
|
||||||
assert_equal(cs.main(f.name), 0)
|
assert cs.main(f.name) == 0
|
||||||
assert_true('WARNING: Binary file' in sio[1])
|
assert 'WARNING: Binary file' in sio[1]
|
||||||
with CaptureStdout() as sio:
|
with CaptureStdout() as sio:
|
||||||
assert_equal(cs.main('-q', '2', f.name), 0)
|
assert cs.main('-q', '2', f.name) == 0
|
||||||
assert_equal(sio[1], '')
|
assert sio[1] == ''
|
||||||
finally:
|
finally:
|
||||||
os.remove(f.name)
|
os.remove(f.name)
|
||||||
|
|
||||||
@ -262,20 +261,20 @@ def test_ignore():
|
|||||||
with TemporaryDirectory() as d:
|
with TemporaryDirectory() as d:
|
||||||
with open(op.join(d, 'good.txt'), 'w') as f:
|
with open(op.join(d, 'good.txt'), 'w') as f:
|
||||||
f.write('this file is okay')
|
f.write('this file is okay')
|
||||||
assert_equal(cs.main(d), 0)
|
assert cs.main(d) == 0
|
||||||
with open(op.join(d, 'bad.txt'), 'w') as f:
|
with open(op.join(d, 'bad.txt'), 'w') as f:
|
||||||
f.write('abandonned')
|
f.write('abandonned')
|
||||||
assert_equal(cs.main(d), 1)
|
assert cs.main(d) == 1
|
||||||
assert_equal(cs.main('--skip=bad*', d), 0)
|
assert cs.main('--skip=bad*', d) == 0
|
||||||
assert_equal(cs.main('--skip=bad.txt', d), 0)
|
assert cs.main('--skip=bad.txt', d) == 0
|
||||||
subdir = op.join(d, 'ignoredir')
|
subdir = op.join(d, 'ignoredir')
|
||||||
os.mkdir(subdir)
|
os.mkdir(subdir)
|
||||||
with open(op.join(subdir, 'bad.txt'), 'w') as f:
|
with open(op.join(subdir, 'bad.txt'), 'w') as f:
|
||||||
f.write('abandonned')
|
f.write('abandonned')
|
||||||
assert_equal(cs.main(d), 2)
|
assert cs.main(d) == 2
|
||||||
assert_equal(cs.main('--skip=bad*', d), 0)
|
assert cs.main('--skip=bad*', d) == 0
|
||||||
assert_equal(cs.main('--skip=*ignoredir*', d), 1)
|
assert cs.main('--skip=*ignoredir*', d) == 1
|
||||||
assert_equal(cs.main('--skip=ignoredir', d), 1)
|
assert cs.main('--skip=ignoredir', d) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_check_filename():
|
def test_check_filename():
|
||||||
@ -283,7 +282,7 @@ def test_check_filename():
|
|||||||
with TemporaryDirectory() as d:
|
with TemporaryDirectory() as d:
|
||||||
with open(op.join(d, 'abandonned.txt'), 'w') as f:
|
with open(op.join(d, 'abandonned.txt'), 'w') as f:
|
||||||
f.write('.')
|
f.write('.')
|
||||||
assert_equal(cs.main('-f', d), 1)
|
assert cs.main('-f', d) == 1
|
||||||
|
|
||||||
|
|
||||||
class TemporaryDirectory(object):
|
class TemporaryDirectory(object):
|
||||||
@ -385,3 +384,52 @@ def FakeStdin(text):
|
|||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
sys.stdin = oldin
|
sys.stdin = oldin
|
||||||
|
|
||||||
|
|
||||||
|
def test_dictionary_formatting():
|
||||||
|
"""Test that all dictionary entries are in lower case and non-empty."""
|
||||||
|
err_dict = dict()
|
||||||
|
with open(op.join(op.dirname(__file__), '..', 'data',
|
||||||
|
'dictionary.txt'), 'rb') as fid:
|
||||||
|
for line in fid:
|
||||||
|
err, rep = line.decode('utf-8').split('->')
|
||||||
|
err = err.lower()
|
||||||
|
assert err not in err_dict, 'entry already exists'
|
||||||
|
rep = rep.rstrip('\n')
|
||||||
|
assert len(rep) > 0, 'corrections must be non-empty'
|
||||||
|
if rep.count(','):
|
||||||
|
if not rep.endswith(','):
|
||||||
|
assert 'disabled' in rep.split(',')[-1], \
|
||||||
|
('currently corrections must end with trailing "," (if'
|
||||||
|
' multiple corrections are available) or '
|
||||||
|
'have "disabled" in the comment')
|
||||||
|
err_dict[err] = rep
|
||||||
|
reps = [r.strip() for r in rep.lower().split(',')]
|
||||||
|
reps = [r for r in reps if len(r)]
|
||||||
|
unique = list()
|
||||||
|
for r in reps:
|
||||||
|
if r not in unique:
|
||||||
|
unique.append(r)
|
||||||
|
assert reps == unique, 'entries are not (lower-case) unique'
|
||||||
|
|
||||||
|
|
||||||
|
def test_case_handling(reload_codespell_lib):
|
||||||
|
"""Test that capitalized entries get detected properly."""
|
||||||
|
# Some simple Unicode things
|
||||||
|
with tempfile.NamedTemporaryFile('wb') as f:
|
||||||
|
pass
|
||||||
|
# with CaptureStdout() as sio:
|
||||||
|
assert cs.main(f.name) == 0
|
||||||
|
try:
|
||||||
|
with open(f.name, 'wb') as f:
|
||||||
|
f.write('this has an ACII error'.encode('utf-8'))
|
||||||
|
with CaptureStdout() as sio:
|
||||||
|
assert cs.main(f.name) == 1
|
||||||
|
assert 'ASCII' in sio[0]
|
||||||
|
with CaptureStdout() as sio:
|
||||||
|
assert cs.main('-w', f.name) == 0
|
||||||
|
assert 'FIXED' in sio[1]
|
||||||
|
with open(f.name, 'rb') as f:
|
||||||
|
assert f.read().decode('utf-8') == 'this has an ASCII error'
|
||||||
|
finally:
|
||||||
|
os.remove(f.name)
|
||||||
|
Reference in New Issue
Block a user