Skip to content

Commit

Permalink
convert window test to functional, add server/session test fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed May 22, 2016
1 parent 9f8adcb commit 4316aa0
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 191 deletions.
62 changes: 62 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,67 @@
# -*- coding: utf-8 -*-

import pytest

import logging
from tmuxp import exc
from tmuxp.server import Server

from .helpers import get_test_session_name, TEST_SESSION_PREFIX

logger = logging.getLogger(__name__)


@pytest.fixture(scope='session')
def t():
t = Server()
t.socket_name = 'tmuxp_test'

return t


@pytest.fixture(scope='function')
def session(t):
session_name = 'tmuxp'
if not t.has_session(session_name):
t.cmd('new-session', '-d', '-s', session_name)

# find current sessions prefixed with tmuxp
old_test_sessions = [
s.get('session_name') for s in t._sessions
if s.get('session_name').startswith(TEST_SESSION_PREFIX)
]

TEST_SESSION_NAME = get_test_session_name(server=t)

try:
session = t.new_session(
session_name=TEST_SESSION_NAME,
)
except exc.TmuxpException as e:
raise e

"""
Make sure that tmuxp can :ref:`test_builder_visually` and switches to
the newly created session for that testcase.
"""
try:
t.switch_client(session.get('session_id'))
pass
except exc.TmuxpException as e:
# t.attach_session(session.get('session_id'))
pass

for old_test_session in old_test_sessions:
logger.debug(
'Old test test session %s found. Killing it.' %
old_test_session
)
t.kill_session(old_test_session)
assert TEST_SESSION_NAME == session.get('session_name')
assert TEST_SESSION_NAME != 'tmuxp'

return session


@pytest.fixture()
def tmpdir(tmpdir_factory):
Expand Down
3 changes: 0 additions & 3 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import tempfile
from contextlib import contextmanager

import pytest

from tmuxp import exc
from tmuxp.server import Server

Expand Down Expand Up @@ -148,7 +146,6 @@ class TmuxTestCase(TestCase):
def temp_session(self, session_name=None):
return temp_session(self.server, session_name)

@pytest.fixture(autouse=True)
def setUp(self):
"""Run bootstrap if :attr:`~.session` is not set."""

Expand Down
64 changes: 31 additions & 33 deletions tests/test_pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,48 @@

import logging

from .helpers import TmuxTestCase

logger = logging.getLogger(__name__)


class ResizeTest(TmuxTestCase):
def test_resize_pane(session):
""" Test Pane.resize_pane(). """

window = session.attached_window()
window.rename_window('test_resize_pane')

def test_resize_pane(self):
""" Test Pane.resize_pane(). """
pane1 = window.attached_pane()
pane1_height = pane1['pane_height']
window.split_window()

window = self.session.attached_window()
window.rename_window('test_resize_pane')
pane1.resize_pane(height=4)
assert pane1['pane_height'] != pane1_height
assert int(pane1['pane_height']) == 4

pane1 = window.attached_pane()
pane1_height = pane1['pane_height']
window.split_window()
pane1.resize_pane(height=3)
assert int(pane1['pane_height']) == 3

pane1.resize_pane(height=4)
assert pane1['pane_height'] != pane1_height
assert int(pane1['pane_height']) == 4

pane1.resize_pane(height=3)
assert int(pane1['pane_height']) == 3
def test_set_height(session):
window = session.new_window(window_name='test_set_height')
window.split_window()
pane1 = window.attached_pane()
pane1_height = pane1['pane_height']

def test_set_height(self):
window = self.session.new_window(window_name='test_set_height')
window.split_window()
pane1 = window.attached_pane()
pane1_height = pane1['pane_height']
pane1.set_height(2)
assert pane1['pane_height'] != pane1_height
assert int(pane1['pane_height']) == 2

pane1.set_height(2)
assert pane1['pane_height'] != pane1_height
assert int(pane1['pane_height']) == 2

def test_set_width(self):
window = self.session.new_window(window_name='test_set_width')
window.split_window()
def test_set_width(session):
window = session.new_window(window_name='test_set_width')
window.split_window()

window.select_layout('main-vertical')
pane1 = window.attached_pane()
pane1_width = pane1['pane_width']
window.select_layout('main-vertical')
pane1 = window.attached_pane()
pane1_width = pane1['pane_width']

pane1.set_width(10)
assert pane1['pane_width'] != pane1_width
assert int(pane1['pane_width']) == 10
pane1.set_width(10)
assert pane1['pane_width'] != pane1_width
assert int(pane1['pane_width']) == 10

pane1.reset()
pane1.reset()
Loading

0 comments on commit 4316aa0

Please sign in to comment.