Skip to content

Commit

Permalink
Fixup: Adjust existing tests for structure change
Browse files Browse the repository at this point in the history
  • Loading branch information
asmacdo committed Oct 8, 2024
1 parent ac54820 commit ee91f97
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ all =
[options.entry_points]
console_scripts =
duct = con_duct.__main__:main
con-duct = con_duct.suite.main:main
con-duct = con_duct.suite.__main__:main

[mypy]
allow_incomplete_defs = False
Expand Down
20 changes: 10 additions & 10 deletions test/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import unittest
from unittest.mock import MagicMock, mock_open, patch
import pytest
from con_duct import suite
from con_duct.suite import main, pprint_json


class TestSuiteHelpers(unittest.TestCase):
Expand All @@ -16,40 +16,40 @@ def return_non_int(*_args: Any) -> str:
command="invalid", file_path="dummy.json", func=return_non_int
)
with pytest.raises(TypeError):
suite.execute(args)
main.execute(args)


class TestPPrint(unittest.TestCase):

@patch(
"builtins.open", new_callable=mock_open, read_data='{"mock_key": "mock_value"}'
)
@patch("con_duct.suite.pprint")
@patch("con_duct.suite.pprint_json.pprint")
def test_pprint_json(self, mock_pprint: MagicMock, mock_open: MagicMock) -> None:
args = argparse.Namespace(
command="pp", file_path="dummy.json", func=suite.pprint_json
command="pp", file_path="dummy.json", func=pprint_json.pprint_json
)
assert suite.execute(args) == 0
assert main.execute(args) == 0

mock_open.assert_called_with("dummy.json", "r")
mock_pprint.assert_called_once_with({"mock_key": "mock_value"})

@patch("builtins.open", side_effect=FileNotFoundError)
def test_file_not_found(self, _mock_open: MagicMock) -> None:
args = argparse.Namespace(
command="pp", file_path="dummy.json", func=suite.pprint_json
command="pp", file_path="dummy.json", func=pprint_json.pprint_json
)
assert suite.execute(args) == 1
assert main.execute(args) == 1

@patch("builtins.open", new_callable=mock_open, read_data='{"invalid": "json"')
@patch("con_duct.suite.pprint")
@patch("con_duct.suite.pprint_json.pprint")
def test_pprint_invalid_json(
self, mock_pprint: MagicMock, mock_open: MagicMock
) -> None:
args = argparse.Namespace(
command="pp", file_path="dummy.json", func=suite.pprint_json
command="pp", file_path="dummy.json", func=pprint_json.pprint_json
)
assert suite.execute(args) == 1
assert main.execute(args) == 1

mock_open.assert_called_with("dummy.json", "r")
mock_pprint.assert_not_called()

0 comments on commit ee91f97

Please sign in to comment.