Skip to content

Commit

Permalink
Merge pull request #240 from bskinn/fix-no-subparser
Browse files Browse the repository at this point in the history
Fix no subparser
  • Loading branch information
bskinn authored Jun 4, 2022
2 parents 02fa433 + f37af66 commit f991660
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: '22.1.0'
rev: '22.3.0'
hooks:
- id: black
- repo: https://github.com/tox-dev/pyproject-fmt
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ and this project strives to adhere to
[Semantic Versioning](http://semver.org/spec/v2.0.0.html).


### (unreleased)

#### Fixed

* CLI corner case where options are passed but no subparser is specified
now results in a clean error-exit, instead of an exception.
([#239](https://github.com/bskinn/sphobjinv/issues/239))

#### Internal

* Bump pre-commit black hook to v22.3.0

* Remove PyPy and Python 3.6 from Azure Pipelines test matrix


### [2.2.2] - 2022-03-22

#### Fixed
Expand Down
6 changes: 2 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ stages:
spec: '3.10'
pypy3:
spec: 'pypy3'
platforms: [linux, windows]
platforms: [linux]

- template: azure-coretest.yml
parameters:
Expand All @@ -84,7 +84,7 @@ stages:
spec: '3.9'
py310:
spec: '3.10'
platforms: [macOs]
platforms: [windows, macOs]


- stage: aux_tests
Expand Down Expand Up @@ -203,5 +203,3 @@ stages:

- script: tox -e flake8-noqa
displayName: Run never-fail flake8 with noqa check


2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def sphinx_version():
"""
p_version = re.compile(r"(\d+)[.]?(\d+)?[.]?(\d+)?")
mch = p_version.match(sphinx_version_str)
return tuple(map((lambda x: int(x) if x else 0), mch.groups()))
return tuple(int(x) if x else 0 for x in mch.groups())


@pytest.fixture() # Must be function scope since uses monkeypatch
Expand Down
4 changes: 4 additions & 0 deletions src/sphobjinv/cli/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ def main():
print(PrsConst.VER_TXT)
sys.exit(0)

# At this point, need to trap for a null subparser
if not params[PrsConst.SUBPARSER_NAME]:
prs.error("No subparser selected")

# Regardless of mode, insert extra blank line
# for cosmetics
log_print(" ", params)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ def test_cli_noargs_shows_help(self, run_cmdline_test):

assert "usage: sphobjinv" in out_.getvalue()

@pytest.mark.timeout(CLI_TEST_TIMEOUT)
def test_cli_no_subparser_prs_exit(self, run_cmdline_test):
"""Confirm exit code 2 if option passed but no subparser provided."""
with stdio_mgr() as (in_, out_, err_):
run_cmdline_test(["--foo"], expect=2)

assert "error: No subparser selected" in err_.getvalue()

@pytest.mark.timeout(CLI_TEST_TIMEOUT)
def test_cli_bad_subparser_prs_exit(self, run_cmdline_test):
"""Confirm exit code 2 if invalid subparser provided."""
with stdio_mgr() as (in_, out_, err_):
run_cmdline_test(["foo"], expect=2)

assert "invalid choice: 'foo'" in err_.getvalue()


class TestConvertGood:
"""Tests for expected-good convert functionality."""
Expand Down

0 comments on commit f991660

Please sign in to comment.