Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop exit codes from raising errors on Windows #1

Merged
merged 1 commit into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading