Skip to content

Commit

Permalink
Removed ability to load a different driver
Browse files Browse the repository at this point in the history
  • Loading branch information
expobrain committed Oct 12, 2024
1 parent b9cdfc1 commit 6283e93
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
10 changes: 3 additions & 7 deletions sqlalchemy_to_json_schema/command/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

import click

from sqlalchemy_to_json_schema.command.driver import Driver
from sqlalchemy_to_json_schema.types import Decision, Format, Layout, Walker
from sqlalchemy_to_json_schema.utils.imports import load_module_or_symbol

DEFAULT_WALKER: Final = Walker.STRUCTURAL
DEFAULT_DECISION: Final = Decision.DEFAULT
DEFAULT_LAYOUT: Final = Layout.SWAGGER_2
DEFAULT_DRIVER = "sqlalchemy_to_json_schema.command.driver:Driver"


@click.command()
Expand All @@ -30,7 +29,6 @@
type=click.Choice([layout.value for layout in Layout]),
default=DEFAULT_LAYOUT.value,
)
@click.option("--driver", type=str, default=DEFAULT_DRIVER)
@click.option(
"--out",
type=click.Path(
Expand All @@ -43,13 +41,11 @@ def main(
walker: str,
decision: str,
layout: str,
driver: str,
out: Optional[Path] = None,
format: Optional[str] = None,
) -> None:
driver_cls = load_module_or_symbol(driver)
driver = driver_cls(Walker(walker), Decision(decision), Layout(layout)) # type: ignore[operator] # noqa: E501
driver.run(targets, filename=out, format=None if format is None else Format(format)) # type: ignore[attr-defined] # noqa: E501
driver = Driver(Walker(walker), Decision(decision), Layout(layout))
driver.run(targets, filename=out, format=None if format is None else Format(format))


if __name__ == "__main__":
Expand Down
21 changes: 2 additions & 19 deletions tests/command/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from sqlalchemy_to_json_schema.command.main import (
DEFAULT_DECISION,
DEFAULT_DRIVER,
DEFAULT_LAYOUT,
DEFAULT_WALKER,
main,
Expand All @@ -18,22 +17,11 @@

@pytest.fixture
def mock_driver(mocker: MockerFixture) -> Mock:
return mocker.patch("sqlalchemy_to_json_schema.command.driver.Driver", autospec=True)


@pytest.fixture
def mock_load_module_or_symbol(mock_driver: Mock, mocker: MockerFixture) -> Mock:
return mocker.patch(
"sqlalchemy_to_json_schema.command.main.load_module_or_symbol",
return_value=mock_driver,
autospec=True,
)
return mocker.patch("sqlalchemy_to_json_schema.command.main.Driver", autospec=True)


@pytest.mark.parametrize("targets", [["my_module"]])
def test_main_defaults(
mock_driver: Mock, mock_load_module_or_symbol: Mock, targets: Sequence[str]
) -> None:
def test_main_defaults(mock_driver: Mock, targets: Sequence[str]) -> None:
"""
ARRANGE CLI args
ACT calling the driver's method
Expand All @@ -49,8 +37,6 @@ def test_main_defaults(
# ASSERT
assert actual.exit_code == 0

mock_load_module_or_symbol.assert_called_once_with(DEFAULT_DRIVER)

mock_driver.assert_called_once_with(DEFAULT_WALKER, DEFAULT_DECISION, DEFAULT_LAYOUT)
mock_driver.return_value.run.assert_called_once_with(
tuple(targets), filename=None, format=None
Expand All @@ -65,7 +51,6 @@ def test_main_defaults(
@pytest.mark.parametrize("out", [Path("output.txt").absolute()])
def test_main(
mock_driver: Mock,
mock_load_module_or_symbol: Mock,
targets: Sequence[str],
walker: Walker,
decision: Decision,
Expand Down Expand Up @@ -102,8 +87,6 @@ def test_main(
# ASSERT
assert actual.exit_code == 0

mock_load_module_or_symbol.assert_called_once_with(DEFAULT_DRIVER)

mock_driver.assert_called_once_with(walker, decision, layout)
mock_driver.return_value.run.assert_called_once_with(
tuple(targets), filename=out, format=format
Expand Down

0 comments on commit 6283e93

Please sign in to comment.