Skip to content

Commit 82d8158

Browse files
committed
Stop exit codes from raising errors on Windows
1 parent 4f14459 commit 82d8158

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

noid/pynoid.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
from noid import utils, cli
66

7+
# make exit codes cross-platform
8+
SUCCESS_EXIT_CODE = getattr(os, 'EX_OK', 0)
9+
USAGE_EXIT_CODE = getattr(os, 'EX_USAGE', 64)
710

811
def mint(template: str = 'zek', n: int = -1, scheme: str = '', naa: str = '') -> str:
912
""" Mint identifiers according to template with a prefix of scheme + naa.
@@ -148,7 +151,7 @@ def main():
148151
"""Main entry point"""
149152
args = cli.parse_args()
150153
if args is None:
151-
return os.EX_USAGE
154+
return USAGE_EXIT_CODE
152155
if args.validate:
153156
if args.verbose:
154157
print(f"info: validating '{args.noid}'...", file=sys.stderr)
@@ -164,7 +167,7 @@ def main():
164167
f"scheme={args.scheme}, naa={args.naa}...", file=sys.stderr)
165168
noid = mint(args.template, args.index, scheme=args.scheme, naa=args.naa)
166169
print(noid)
167-
return os.EX_OK
170+
return SUCCESS_EXIT_CODE
168171

169172

170173
if __name__ == '__main__':

test/test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,11 @@ def test_default(self):
179179
self.assertRegex(sys.stdout.getvalue(), r"(?ms:^info: generating noid.*template=.*scheme=.*ark[:][/][\w\d]+)")
180180

181181
def test_error(self):
182-
"""Exit status on *nix is os.EX_USAGE"""
182+
"""Exit status on *nix is os.EX_USAGE, but its not available on Windows"""
183+
USAGE_EXIT_CODE = getattr(os, 'EX_USAGE', 64)
183184
cli.cli(f"noid -V")
184185
ex = pynoid.main()
185-
self.assertEqual(os.EX_USAGE, ex)
186+
self.assertEqual(USAGE_EXIT_CODE, ex)
186187

187188
def test_config(self):
188189
"""Using config"""

0 commit comments

Comments
 (0)