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

test window size script #30

Merged
merged 4 commits into from
Jun 11, 2021
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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ omit = [
"src/magic_tiler/utils/filestore.py",
# top-level scripts
"src/magic_tiler/magic_tiler.py",
"src/magic_tiler/get_window_sizes.py",
]

[tool.coverage.report]
Expand Down
5 changes: 5 additions & 0 deletions src/magic_tiler/get_window_sizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

import click

from magic_tiler.utils import interfaces
from magic_tiler.utils import sway


@click.command()
def main() -> None:
window_manager = sway.Sway()
print_window_sizes(window_manager)


def print_window_sizes(window_manager: interfaces.TilingWindowManager) -> None:
pprint.pprint(window_manager.get_window_sizes())
4 changes: 4 additions & 0 deletions src/magic_tiler/utils/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def num_workspace_windows(self) -> int:
def get_tree(self) -> List:
pass

@abc.abstractmethod
def get_window_sizes(self) -> Dict:
pass


class ConfigReader(object):
@abc.abstractmethod
Expand Down
2 changes: 1 addition & 1 deletion src/magic_tiler/utils/sway.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
SLEEP_TIME = 0.30


class Sway(interfaces.TilingWindowManager): # pragma: nocover
class Sway(interfaces.TilingWindowManager):
def __init__(self) -> None:
self._sway = i3ipc.Connection()

Expand Down
9 changes: 8 additions & 1 deletion tests/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ class FakeNode(NamedTuple):


class FakeWindowManager(interfaces.TilingWindowManager):
def __init__(self, tree: Optional[List[FakeNode]] = None):
def __init__(
self, tree: Optional[List[FakeNode]] = None, window_sizes: Optional[Dict] = None
):
if tree:
self._tree = tree
if window_sizes:
self._window_sizes = window_sizes

def make_window(self, window_details: dtos.WindowDetails) -> None:
pass
Expand Down Expand Up @@ -84,3 +88,6 @@ def num_workspace_windows(self) -> int:

def get_tree(self) -> List[FakeNode]:
return self._tree

def get_window_sizes(self):
return self._window_sizes
37 changes: 37 additions & 0 deletions tests/test_get_window_sizes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from unittest import mock

import pytest

from magic_tiler import get_window_sizes


@pytest.fixture
def mock_window_manager(mocker):
return mocker.patch("magic_tiler.utils.sway.Sway")


@pytest.fixture
def mock_print_window_sizes(mocker):
return mocker.patch("magic_tiler.get_window_sizes.print_window_sizes")


@pytest.mark.e2e
def test_get_window_sizes(click_runner):
result = click_runner.invoke(get_window_sizes.main)
assert result.exit_code == 0


def test_click_handles_options(
click_runner, mock_window_manager, mock_print_window_sizes
):
"""Click should handle the user's input and specified flags to pass in the right
details to the print_window_sizes function
"""
click_runner.invoke(get_window_sizes.main)
mock_print_window_sizes.assert_called_once_with(mock_window_manager())


def test_calls_window_manager():
window_manager = mock.MagicMock()
get_window_sizes.print_window_sizes(window_manager)
window_manager.get_window_sizes.assert_called_once_with()
3 changes: 3 additions & 0 deletions tests/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def split(self, split_type: str) -> None:
def get_tree(self):
pass

def get_window_sizes(self) -> Dict:
pass


class LayoutTestCase(NamedTuple):
config: Dict
Expand Down