Skip to content

Commit

Permalink
Refactor tests for py.test fixture, polish
Browse files Browse the repository at this point in the history
- sort imports, clean out unused
- clean up pydoc for modules, no need to keep headers there
- keep t (tmuxp.server.Server) out of the global namespace
  • Loading branch information
tony committed May 21, 2016
1 parent 03df8df commit bd7e8f9
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 228 deletions.
17 changes: 3 additions & 14 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,12 @@
~~~~~~~~~~~
"""
from __future__ import absolute_import, division, print_function, \
with_statement, unicode_literals
from __future__ import (absolute_import, division, print_function,
unicode_literals, with_statement)

import logging
import pkgutil
import sys

from tmuxp import log
from tmuxp._compat import string_types, PY2, reraise
from tmuxp.server import Server

if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest

t = Server()
t.socket_name = 'tmuxp_test'

from . import helpers # NOQA
import unittest # NOQA
10 changes: 7 additions & 3 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import tempfile
from contextlib import contextmanager

import pytest

from tmuxp import exc
from . import t
from tmuxp.server import Server

if sys.version_info < (2, 7):
import unittest2 as unittest
Expand All @@ -39,7 +41,7 @@
def get_test_session_name(server, prefix=TEST_SESSION_PREFIX):
while True:
session_name = prefix + next(namer)
if not t.has_session(session_name):
if not server.has_session(session_name):
break
return session_name

Expand Down Expand Up @@ -146,6 +148,7 @@ 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 All @@ -165,6 +168,8 @@ def bootstrap(self):
a dumby session will be made to prevent tmux from closing.
"""
self.t = t = Server()
t.socket_name = 'tmuxp_test'

session_name = 'tmuxp'
if not t.has_session(session_name):
Expand Down Expand Up @@ -370,7 +375,6 @@ def test_foo(self):
sys.__stderr__ = prev_rerr



class EnvironmentVarGuard(object):

"""Class to help protect the environment variable properly. Can be used as
Expand Down
16 changes: 2 additions & 14 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# -*- coding: utf-8 -*-
"""Test for tmuxp command line interface.
tmuxp.tests.cli
~~~~~~~~~~~~~~~
"""
"""Test for tmuxp command line interface."""

from __future__ import (absolute_import, division, print_function,
unicode_literals, with_statement)
Expand All @@ -13,9 +8,9 @@
import os
import shutil
import tempfile
import unittest

from tmuxp import cli, config

from .helpers import TestCase

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -123,10 +118,3 @@ def tearDown(self):
if os.path.isdir(self.tmp_dir):
shutil.rmtree(self.tmp_dir)
logger.debug('wiped %s' % self.tmp_dir)


def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(FindConfigsTest))
suite.addTest(unittest.makeSuite(StartupTest))
return suite
24 changes: 3 additions & 21 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# -*- coding: utf-8 -*-
"""Test for tmuxp configuration import, inlining, expanding and export.
tmuxp.tests.config
~~~~~~~~~~~~~~~~~~
"""
"""Test for tmuxp configuration import, inlining, expanding and export."""

from __future__ import (absolute_import, division, print_function,
unicode_literals, with_statement)
Expand All @@ -18,7 +13,8 @@
import kaptan

from tmuxp import config, exc
from .helpers import TestCase, EnvironmentVarGuard, example_dir

from .helpers import EnvironmentVarGuard, TestCase, example_dir

logger = logging.getLogger(__name__)
TMUXP_DIR = os.path.join(os.path.dirname(__file__), '.tmuxp')
Expand Down Expand Up @@ -1103,17 +1099,3 @@ def test_replaces_start_directory(self):
"logging @ %s" % env_value,
sconfig['windows'][1]['window_name']
)


def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(ConfigBlankPanes))
suite.addTest(unittest.makeSuite(ConfigConsistency))
suite.addTest(unittest.makeSuite(ExpandTest))
suite.addTest(unittest.makeSuite(ImportExportTest))
suite.addTest(unittest.makeSuite(InlineTest))
suite.addTest(unittest.makeSuite(ShellCommandBeforeTest))
suite.addTest(unittest.makeSuite(ShellCommandBeforeSession))
suite.addTest(unittest.makeSuite(TrickleRelativeStartDirectory))
suite.addTest(unittest.makeSuite(ConfigExpandEnvironmentVariables))
return suite
19 changes: 2 additions & 17 deletions tests/test_config_teamocil.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
# -*- coding: utf-8 -*-
"""Test for tmuxp teamocil configuration..
tmuxp.tests.config_teamocil
~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
"""Test for tmuxp teamocil configuration."""

from __future__ import (absolute_import, division, print_function,
unicode_literals, with_statement)

import logging
import os
import unittest

import kaptan

from tmuxp import config

from .helpers import TestCase

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -730,13 +725,3 @@ def test_config_to_dict(self):
""" this configuration contains multiple sessions in a single file.
tmuxp can split them into files, proceed?
"""


def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TeamocilTest))
suite.addTest(unittest.makeSuite(Teamocil2Test))
suite.addTest(unittest.makeSuite(Teamocil3Test))
suite.addTest(unittest.makeSuite(Teamocil4Test))
suite.addTest(unittest.makeSuite(TeamocilLayoutsTest))
return suite
17 changes: 2 additions & 15 deletions tests/test_config_tmuxinator.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
# -*- coding: utf-8 -*-
"""Test for tmuxp tmuxinator configuration.
tmuxp.tests.config_tmuxinator
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
"""Test for tmuxp tmuxinator configuration."""

from __future__ import (absolute_import, division, print_function,
unicode_literals, with_statement)

import logging
import os
import unittest

import kaptan

from tmuxp import config

from .helpers import TestCase

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -472,11 +467,3 @@ def test_config_to_dict(self):
config.import_tmuxinator(self.tmuxinator_dict),
self.tmuxp_dict
)


def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TmuxinatorTest))
suite.addTest(unittest.makeSuite(TmuxinatorDeprecationsTest))
suite.addTest(unittest.makeSuite(TmuxinatoriSampleTest))
return suite
14 changes: 1 addition & 13 deletions tests/test_pane.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
# -*- coding: utf-8 -*-
"""Test for tmuxp Pane object.
tmuxp.tests.pane
~~~~~~~~~~~~~~~~
"""
"""Test for tmuxp Pane object."""

from __future__ import (absolute_import, division, print_function,
unicode_literals, with_statement)

import logging
import unittest

from .helpers import TmuxTestCase

Expand Down Expand Up @@ -59,9 +53,3 @@ def test_set_width(self):
self.assertEqual(int(pane1['pane_width']), 10)

pane1.reset()


def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(ResizeTest))
return suite
20 changes: 3 additions & 17 deletions tests/test_server.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
# -*- coding: utf-8 -*-
"""Test for tmuxp Server object.
tmuxp.tests.server
~~~~~~~~~~~~~~~~~~
"""
"""Test for tmuxp Server object."""

from __future__ import (absolute_import, division, print_function,
unicode_literals, with_statement)

import logging
import unittest

from tmuxp import Server
from . import t
from .helpers import TmuxTestCase

logger = logging.getLogger(__name__)
Expand All @@ -22,8 +15,8 @@
class ServerTest(TmuxTestCase):

def test_has_session(self):
self.assertTrue(t.has_session(self.TEST_SESSION_NAME))
self.assertFalse(t.has_session('asdf2314324321'))
self.assertTrue(self.t.has_session(self.TEST_SESSION_NAME))
self.assertFalse(self.t.has_session('asdf2314324321'))

def test_socket_name(self):
""" ``-L`` socket_name.
Expand Down Expand Up @@ -86,10 +79,3 @@ def test_set_show_environment_single(self):
def test_show_environment_not_set(self):
"""Unset environment variable returns None."""
self.assertEqual(None, self.server.show_environment('BAR'))


def suite():
_suite = unittest.TestSuite()
_suite.addTest(unittest.makeSuite(ServerTest))
_suite.addTest(unittest.makeSuite(EnvironmentTest))
return _suite
25 changes: 5 additions & 20 deletions tests/test_session.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
# -*- coding: utf-8 -*-
"""Test for tmuxp Session object.
tmuxp.tests.session
~~~~~~~~~~~~~~~~~~~
"""
"""Test for tmuxp Session object."""

from __future__ import (absolute_import, division, print_function,
unicode_literals, with_statement)

import logging
import unittest

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

logger = logging.getLogger(__name__)
Expand All @@ -23,8 +16,8 @@ class SessionTest(TmuxTestCase):

def test_has_session(self):
"""Server.has_session returns True if has session_name exists."""
self.assertTrue(t.has_session(self.TEST_SESSION_NAME))
self.assertFalse(t.has_session('asdf2314324321'))
self.assertTrue(self.t.has_session(self.TEST_SESSION_NAME))
self.assertFalse(self.t.has_session('asdf2314324321'))

def test_select_window(self):
"""Session.select_window moves window."""
Expand Down Expand Up @@ -99,7 +92,8 @@ class SessionNewTest(TmuxTestCase):
def test_new_session(self):
"""Server.new_session creates new session."""
new_session_name = TEST_SESSION_PREFIX + next(namer)
new_session = t.new_session(session_name=new_session_name, detach=True)
new_session = self.t.new_session(
session_name=new_session_name, detach=True)

self.assertIsInstance(new_session, Session)
self.assertEqual(new_session.get('session_name'), new_session_name)
Expand Down Expand Up @@ -177,12 +171,3 @@ def test_unset_environment(self):
self.assertEqual('OK', self.session.show_environment('BAM'))
self.session.unset_environment('BAM')
self.assertEqual(None, self.session.show_environment('BAM'))


def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(Options))
suite.addTest(unittest.makeSuite(Environment))
suite.addTest(unittest.makeSuite(SessionNewTest))
suite.addTest(unittest.makeSuite(SessionTest))
return suite
Loading

0 comments on commit bd7e8f9

Please sign in to comment.