Skip to content

Commit 7622f08

Browse files
committed
FIX: More
1 parent 8b81405 commit 7622f08

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

codespell_lib/_codespell.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@
5050
)
5151
_builtin_default = 'clear,rare'
5252

53-
# docs say os.EX_USAGE is only available on Unix systems, so to be safe we
54-
# protect and just use the value it is on macOS and Linux (64)
53+
# docs say os.EX_USAGE et al. are only available on Unix systems, so to be safe
54+
# we protect and just use the values they are on macOS and Linux
55+
EX_OK = 0
5556
EX_USAGE = 64
57+
EX_DATAERR = 65
5658

5759
# OPTIONS:
5860
#
@@ -218,11 +220,11 @@ def parse_options(args):
218220

219221
parser.add_argument('-d', '--disable-colors',
220222
action='store_false', dest='colors',
221-
help='disable colors, even when printing to terminal '
223+
help='Disable colors, even when printing to terminal '
222224
'(always set for Windows)')
223225
parser.add_argument('-c', '--enable-colors',
224226
action='store_true', dest='colors',
225-
help='enable colors, even when not printing to '
227+
help='Enable colors, even when not printing to '
226228
'terminal')
227229

228230
parser.add_argument('-w', '--write-changes',
@@ -265,11 +267,11 @@ def parse_options(args):
265267
'specified together with --write-changes.')
266268
parser.add_argument('-s', '--summary',
267269
action='store_true', default=False,
268-
help='print summary of fixes')
270+
help='Print summary of fixes')
269271

270272
parser.add_argument('--count',
271273
action='store_true', default=False,
272-
help='print the number of errors as the last line of '
274+
help='Print the number of errors as the last line of '
273275
'stderr')
274276

275277
parser.add_argument('-S', '--skip',
@@ -315,21 +317,21 @@ def parse_options(args):
315317

316318
parser.add_argument('-f', '--check-filenames',
317319
action='store_true', default=False,
318-
help='check file names as well')
320+
help='Check file names as well')
319321

320322
parser.add_argument('-H', '--check-hidden',
321323
action='store_true', default=False,
322324
help='Check hidden files and directories (those '
323325
'starting with ".") as well.')
324326
parser.add_argument('-A', '--after-context', type=int, metavar='LINES',
325-
help='print LINES of trailing context')
327+
help='Print LINES of trailing context')
326328
parser.add_argument('-B', '--before-context', type=int, metavar='LINES',
327-
help='print LINES of leading context')
329+
help='Print LINES of leading context')
328330
parser.add_argument('-C', '--context', type=int, metavar='LINES',
329-
help='print LINES of surrounding context')
331+
help='Print LINES of surrounding context')
330332

331333
parser.add_argument('files', nargs='*',
332-
help='files or directories to check')
334+
help='Files or directories to check')
333335

334336
options = parser.parse_args(list(args))
335337

@@ -758,4 +760,4 @@ def main(*args):
758760
print(summary)
759761
if options.count:
760762
print(bad_count, file=sys.stderr)
761-
return int(bool(bad_count))
763+
return EX_DATAERR if bad_count else EX_OK

codespell_lib/tests/test_basic.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@
1313
import pytest
1414

1515
import codespell_lib as cs_
16-
from codespell_lib._codespell import EX_USAGE
16+
from codespell_lib._codespell import EX_USAGE, EX_OK, EX_DATAERR
17+
18+
19+
def test_constants():
20+
"""Test our EX constants."""
21+
assert EX_OK == 0
22+
assert EX_USAGE == 64
23+
assert EX_DATAERR == 65
1724

1825

1926
class MainWrapper(object):
@@ -25,9 +32,10 @@ def main(self, *args, count=True, std=False, **kwargs):
2532
code = cs_.main(*args, **kwargs)
2633
capsys = inspect.currentframe().f_back.f_locals['capsys']
2734
stdout, stderr = capsys.readouterr()
28-
if code == 1: # have some misspellings
35+
assert code in (EX_OK, EX_USAGE, EX_DATAERR)
36+
if code == EX_DATAERR: # have some misspellings
2937
code = int(stderr.split('\n')[-2])
30-
elif code == 0 and count:
38+
elif code == EX_OK and count:
3139
code = int(stderr.split('\n')[-2])
3240
assert code == 0
3341
if std:

0 commit comments

Comments
 (0)