mirror of
https://github.com/codespell-project/codespell.git
synced 2025-08-06 09:40:56 +08:00
* Add some tests for #1531 * Ignore hidden files in directories, fixes #1531
This commit is contained in:
@ -714,6 +714,9 @@ def main(*args):
|
|||||||
del dirs[:]
|
del dirs[:]
|
||||||
continue
|
continue
|
||||||
for file_ in files:
|
for file_ in files:
|
||||||
|
# ignore hidden files in directories
|
||||||
|
if is_hidden(file_, options.check_hidden):
|
||||||
|
continue
|
||||||
if glob_match.match(file_): # skip files
|
if glob_match.match(file_): # skip files
|
||||||
continue
|
continue
|
||||||
fname = os.path.join(root, file_)
|
fname = os.path.join(root, file_)
|
||||||
|
@ -279,18 +279,26 @@ def test_check_filename(tmpdir):
|
|||||||
def test_check_hidden(tmpdir):
|
def test_check_hidden(tmpdir):
|
||||||
"""Test ignoring of hidden files."""
|
"""Test ignoring of hidden files."""
|
||||||
d = str(tmpdir)
|
d = str(tmpdir)
|
||||||
# hidden file
|
# visible 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 cs.main(op.join(d, 'test.txt')) == 1
|
assert cs.main(op.join(d, 'test.txt')) == 1
|
||||||
|
assert cs.main(d) == 1
|
||||||
|
# hidden file
|
||||||
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 cs.main(op.join(d, '.test.txt')) == 0
|
assert cs.main(op.join(d, '.test.txt')) == 0
|
||||||
|
assert cs.main(d) == 0
|
||||||
assert cs.main('--check-hidden', op.join(d, '.test.txt')) == 1
|
assert cs.main('--check-hidden', op.join(d, '.test.txt')) == 1
|
||||||
|
assert cs.main('--check-hidden', d) == 1
|
||||||
|
# hidden file with typo in name
|
||||||
os.rename(op.join(d, '.test.txt'), op.join(d, '.abandonned.txt'))
|
os.rename(op.join(d, '.test.txt'), op.join(d, '.abandonned.txt'))
|
||||||
assert cs.main(op.join(d, '.abandonned.txt')) == 0
|
assert cs.main(op.join(d, '.abandonned.txt')) == 0
|
||||||
|
assert cs.main(d) == 0
|
||||||
assert cs.main('--check-hidden', op.join(d, '.abandonned.txt')) == 1
|
assert cs.main('--check-hidden', op.join(d, '.abandonned.txt')) == 1
|
||||||
|
assert cs.main('--check-hidden', d) == 1
|
||||||
assert cs.main('--check-hidden', '--check-filenames',
|
assert cs.main('--check-hidden', '--check-filenames',
|
||||||
op.join(d, '.abandonned.txt')) == 2
|
op.join(d, '.abandonned.txt')) == 2
|
||||||
|
assert cs.main('--check-hidden', '--check-filenames', d) == 2
|
||||||
|
|
||||||
|
|
||||||
def test_case_handling(tmpdir, capsys):
|
def test_case_handling(tmpdir, capsys):
|
||||||
|
Reference in New Issue
Block a user