Skip to content

Commit

Permalink
Stop exit codes from raising errors on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
gwiedeman authored and paulkorir committed Aug 31, 2024
1 parent 14d234c commit 99e4033
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions noid/pynoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

from noid import utils, cli

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

def mint(template: str = 'zek', n: int = -1, scheme: str = '', naa: str = '') -> str:
""" Mint identifiers according to template with a prefix of scheme + naa.
Expand Down Expand Up @@ -148,7 +151,7 @@ def main():
"""Main entry point"""
args = cli.parse_args()
if args is None:
return os.EX_USAGE
return USAGE_EXIT_CODE
if args.validate:
if args.verbose:
print(f"info: validating '{args.noid}'...", file=sys.stderr)
Expand All @@ -164,7 +167,7 @@ def main():
f"scheme={args.scheme}, naa={args.naa}...", file=sys.stderr)
noid = mint(args.template, args.index, scheme=args.scheme, naa=args.naa)
print(noid)
return os.EX_OK
return SUCCESS_EXIT_CODE


if __name__ == '__main__':
Expand Down
5 changes: 3 additions & 2 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,11 @@ def test_default(self):
self.assertRegex(sys.stdout.getvalue(), r"(?ms:^info: generating noid.*template=.*scheme=.*ark[:][/][\w\d]+)")

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

def test_config(self):
"""Using config"""
Expand Down

0 comments on commit 99e4033

Please sign in to comment.