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

Switch to py.test #151

Merged
merged 47 commits into from
May 22, 2016
Merged
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4a587df
Ignore all types of virtualenv dir
tony May 21, 2016
ace8043
Refactor tests structure for py.test, optimize helper imports
tony May 21, 2016
553ac81
Ignore .cache/ and .eggs/
tony May 21, 2016
dfa1cb1
switch window rename to use sh shell as test
tony May 21, 2016
8c18356
Add flaky for rerunning those tricky testcases
tony May 21, 2016
bd6616a
reorder test deps
tony May 21, 2016
82ed172
Update pip, wheel, virtualenv before install on travis
tony May 21, 2016
79b981b
Try upgrading setuptools
tony May 21, 2016
06779a1
Upgrade pytest
tony May 21, 2016
20b3fd1
try upgrading setuptools/pip once more
tony May 21, 2016
9bfd122
Omit tests/ dir from coveragerc
tony May 21, 2016
8f380b6
remove run-tests.py
tony May 21, 2016
a06bc09
Update make test command to py.test
tony May 21, 2016
2c467b3
Clean up old TestLoader infrastructure
tony May 21, 2016
03df8df
flake8 for tests also
tony May 21, 2016
bd7e8f9
Refactor tests for py.test fixture, polish
tony May 21, 2016
d416a53
Update docs for new test directions
tony May 21, 2016
bebbd88
Update README/dox/MANIFEST.in to rm run-tests.py and use make test
tony May 21, 2016
120106c
switch to py.test style asserts, cleanup param order
tony May 21, 2016
713a5e8
port cli tests to py.test functions
tony May 21, 2016
43b4973
midway commit of py.test function rewrite test_config
tony May 22, 2016
e5abc75
Move second expansion test to yaml files+fixtures
tony May 22, 2016
2823379
add util to load fixtures, more tests to fixtures, py.test functions
tony May 22, 2016
41e89ed
move sample config to fixture
tony May 22, 2016
9314c5c
helper function to make loading configs brief
tony May 22, 2016
d9b1de0
Finish test_config py.test fixturization/function conversion
tony May 22, 2016
fcd54c3
Briefen fixture name
tony May 22, 2016
8cbeac7
Move load fixtures to tests/fixtures root
tony May 22, 2016
3141d81
teamocil config tests to fixtures
tony May 22, 2016
e788ab5
Move rest of tmuxinator configs to fixtures
tony May 22, 2016
9f8adcb
move tests for test helpers to tests/tests/
tony May 22, 2016
4316aa0
convert window test to functional, add server/session test fixtures
tony May 22, 2016
10b8eb8
parametrize multisession teamocil import test
tony May 22, 2016
795df2e
Move rest of teamocil config tests to py.test
tony May 22, 2016
781129b
tmuxinator tests to py.test parametrized funcs
tony May 22, 2016
faa771a
Rename t decorator to server, test_server to py.test funcs
tony May 22, 2016
66a9493
move test_session to py.test funcs
tony May 22, 2016
b9eb738
port test_tmuxobject to py.test
tony May 22, 2016
f877bae
workspace{builder,freeze} split fixtures, tweak flaky
tony May 22, 2016
7df1b3c
move more tests (util, workspacebuilder) to py.test func
tony May 22, 2016
8225be1
convert rest tests to py.test
tony May 22, 2016
e7b0591
Clean out unused test helpers, fixture usage fixes
tony May 22, 2016
310ebcc
remove unittest2 dep
tony May 22, 2016
586456b
Fix indentation in setup.py
tony May 22, 2016
447f917
fixes to test decorators, run in function scope for now
tony May 22, 2016
91ccb36
rm unittest2 dep from tox
tony May 22, 2016
2fab3a0
Update doc for pytest
tony May 22, 2016
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
Prev Previous commit
Next Next commit
move test_session to py.test funcs
  • Loading branch information
tony committed May 22, 2016
commit 66a94938d5097eb8b5664eaeb3fb3997f93632ab
235 changes: 121 additions & 114 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,164 +8,171 @@
import pytest

from tmuxp import Pane, Session, Window
from .helpers import TEST_SESSION_PREFIX, TmuxTestCase, namer

from .helpers import TEST_SESSION_PREFIX, namer

logger = logging.getLogger(__name__)


class SessionTest(TmuxTestCase):
def test_has_session(server, session):
"""Server.has_session returns True if has session_name exists."""
TEST_SESSION_NAME = session.get('session_name')
assert server.has_session(TEST_SESSION_NAME)
assert not server.has_session('asdf2314324321')


def test_select_window(session):
"""Session.select_window moves window."""
# get the current window_base_index, since different user tmux config
# may start at 0 or 1, or whatever they want.
window_base_index = int(
session.attached_window().get('window_index')
)

session.new_window(window_name='test_window')
window_count = len(session._windows)

assert window_count >= 2 # 2 or more windows

assert len(session._windows) == window_count

# tmux selects a window, moves to it, shows it as attached_window
selected_window1 = session.select_window(window_base_index)
assert isinstance(selected_window1, Window)
attached_window1 = session.attached_window()

assert selected_window1 == attached_window1
assert selected_window1.__dict__ == attached_window1.__dict__

# again: tmux selects a window, moves to it, shows it as
# attached_window
selected_window2 = session.select_window(window_base_index + 1)
assert isinstance(selected_window2, Window)
attached_window2 = session.attached_window()

def test_has_session(self):
"""Server.has_session returns True if has session_name exists."""
assert self.t.has_session(self.TEST_SESSION_NAME)
assert not self.t.has_session('asdf2314324321')
assert selected_window2 == attached_window2
assert selected_window2.__dict__ == attached_window2.__dict__

def test_select_window(self):
"""Session.select_window moves window."""
# get the current window_base_index, since different user tmux config
# may start at 0 or 1, or whatever they want.
window_base_index = int(
self.session.attached_window().get('window_index')
)
# assure these windows were really different
assert selected_window1 != selected_window2
assert selected_window1.__dict__ != selected_window2.__dict__

self.session.new_window(window_name='test_window')
window_count = len(self.session._windows)

assert window_count >= 2 # 2 or more windows
def test_select_window_returns_Window(session):
"""Session.select_window returns Window object."""

assert len(self.session._windows) == window_count
window_count = len(session._windows)
assert len(session._windows) == window_count
window_base_index = int(
session.attached_window().get('window_index'))

# tmux selects a window, moves to it, shows it as attached_window
selected_window1 = self.session.select_window(window_base_index)
assert isinstance(selected_window1, Window)
attached_window1 = self.session.attached_window()
assert isinstance(
session.select_window(window_base_index), Window
)

assert selected_window1 == attached_window1
assert selected_window1.__dict__ == attached_window1.__dict__

# again: tmux selects a window, moves to it, shows it as
# attached_window
selected_window2 = self.session.select_window(window_base_index + 1)
assert isinstance(selected_window2, Window)
attached_window2 = self.session.attached_window()
def test_attached_window(session):
"""Session.attached_window() returns Window."""
assert isinstance(session.attached_window(), Window)

assert selected_window2 == attached_window2
assert selected_window2.__dict__ == attached_window2.__dict__

# assure these windows were really different
assert selected_window1 != selected_window2
assert selected_window1.__dict__ != selected_window2.__dict__
def test_attached_pane(session):
"""Session.attached_pane() returns Pane."""
assert isinstance(session.attached_pane(), Pane)

def test_select_window_returns_Window(self):
"""Session.select_window returns Window object."""

window_count = len(self.session._windows)
assert len(self.session._windows) == window_count
window_base_index = int(
self.session.attached_window().get('window_index'))
def test_session_rename(session):
"""Session.rename_session renames session."""
TEST_SESSION_NAME = session.get('session_name')
test_name = 'testingdis_sessname'
session.rename_session(test_name)
assert session.get('session_name') == test_name
session.rename_session(TEST_SESSION_NAME)
assert session.get('session_name') == TEST_SESSION_NAME

assert isinstance(
self.session.select_window(window_base_index), Window
)

def test_attached_window(self):
"""Session.attached_window() returns Window."""
assert isinstance(self.session.attached_window(), Window)
def test_new_session(server):
"""Server.new_session creates new session."""
new_session_name = TEST_SESSION_PREFIX + next(namer)
new_session = server.new_session(
session_name=new_session_name, detach=True)

def test_attached_pane(self):
"""Session.attached_pane() returns Pane."""
assert isinstance(self.session.attached_pane(), Pane)
assert isinstance(new_session, Session)
assert new_session.get('session_name') == new_session_name

def test_session_rename(self):
"""Session.rename_session renames session."""
test_name = 'testingdis_sessname'
self.session.rename_session(test_name)
assert self.session.get('session_name') == test_name
self.session.rename_session(self.TEST_SESSION_NAME)
assert self.session.get('session_name') == self.TEST_SESSION_NAME

def test_show_options(session):
"""Session.show_options() returns dict."""

class SessionNewTest(TmuxTestCase):
options = session.show_options()
assert isinstance(options, dict)

def test_new_session(self):
"""Server.new_session creates new session."""
new_session_name = TEST_SESSION_PREFIX + next(namer)
new_session = self.t.new_session(
session_name=new_session_name, detach=True)

assert isinstance(new_session, Session)
assert new_session.get('session_name') == new_session_name
def test_set_show_options_single(session):
"""Set option then Session.show_options(key)."""

session.set_option('history-limit', 20)
assert session.show_options('history-limit') == 20

class Options(TmuxTestCase):
session.set_option('history-limit', 40)
assert session.show_options('history-limit') == 40

def test_show_options(self):
"""Session.show_options() returns dict."""
assert session.show_options()['history-limit'] == 40

options = self.session.show_options()
assert isinstance(options, dict)

def test_set_show_options_single(self):
"""Set option then Session.show_options(key)."""
def test_set_show_option(session):
"""Set option then Session.show_option(key)."""
session.set_option('history-limit', 20)
assert session.show_option('history-limit') == 20

self.session.set_option('history-limit', 20)
assert self.session.show_options('history-limit') == 20
session.set_option('history-limit', 40)

self.session.set_option('history-limit', 40)
assert self.session.show_options('history-limit') == 40
assert session.show_option('history-limit') == 40

assert self.session.show_options()['history-limit'] == 40

def test_set_show_option(self):
"""Set option then Session.show_option(key)."""
self.session.set_option('history-limit', 20)
assert self.session.show_option('history-limit') == 20
def test_set_option_bad(session):
"""Session.set_option raises ValueError for bad option key."""
with pytest.raises(ValueError):
session.set_option('afewewfew', 43)

self.session.set_option('history-limit', 40)

assert self.session.show_option('history-limit') == 40
def test_show_environment(session):
"""Session.show_environment() returns dict."""

def test_set_option_bad(self):
"""Session.set_option raises ValueError for bad option key."""
with pytest.raises(ValueError):
self.session.set_option('afewewfew', 43)
_vars = session.show_environment()
assert isinstance(_vars, dict)


class Environment(TmuxTestCase):
def test_set_show_environment_single(session):
"""Set environment then Session.show_environment(key)."""

def test_show_environment(self):
"""Session.show_environment() returns dict."""
session.set_environment('FOO', 'BAR')
assert session.show_environment('FOO') == 'BAR'

_vars = self.session.show_environment()
assert isinstance(_vars, dict)
session.set_environment('FOO', 'DAR')
assert session.show_environment('FOO') == 'DAR'

def test_set_show_environment_single(self):
"""Set environment then Session.show_environment(key)."""
assert session.show_environment()['FOO'] == 'DAR'

self.session.set_environment('FOO', 'BAR')
assert self.session.show_environment('FOO') == 'BAR'

self.session.set_environment('FOO', 'DAR')
assert self.session.show_environment('FOO') == 'DAR'
def test_show_environment_not_set(session):
"""Not set environment variable returns None."""
assert session.show_environment('BAR') is None

assert self.session.show_environment()['FOO'] == 'DAR'

def test_show_environment_not_set(self):
"""Not set environment variable returns None."""
assert self.session.show_environment('BAR') is None
def test_remove_environment(session):
"""Remove environment variable."""
assert session.show_environment('BAM') is None
session.set_environment('BAM', 'OK')
assert session.show_environment('BAM') == 'OK'
session.remove_environment('BAM')
assert session.show_environment('BAM') is None

def test_remove_environment(self):
"""Remove environment variable."""
assert self.session.show_environment('BAM') is None
self.session.set_environment('BAM', 'OK')
assert self.session.show_environment('BAM') == 'OK'
self.session.remove_environment('BAM')
assert self.session.show_environment('BAM') is None

def test_unset_environment(self):
"""Unset environment variable."""
assert self.session.show_environment('BAM') is None
self.session.set_environment('BAM', 'OK')
assert self.session.show_environment('BAM') == 'OK'
self.session.unset_environment('BAM')
assert self.session.show_environment('BAM') is None
def test_unset_environment(session):
"""Unset environment variable."""
assert session.show_environment('BAM') is None
session.set_environment('BAM', 'OK')
assert session.show_environment('BAM') == 'OK'
session.unset_environment('BAM')
assert session.show_environment('BAM') is None