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
Show file tree
Hide file tree
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
Refactor tests structure for py.test, optimize helper imports
  • Loading branch information
tony committed May 21, 2016
commit ace8043758d94ae97f6ba7b45848de4935ea316d
1 change: 1 addition & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest==2.9.1
23 changes: 20 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
import sys

from setuptools import setup
from setuptools.command.test import test as TestCommand

about = {}
with open("tmuxp/__about__.py") as fp:
exec(fp.read(), about)

with open('requirements/base.txt') as f:
install_reqs = [line for line in f.read().split('\n') if line]
tests_reqs = []

with open('requirements/test.txt') as f:
tests_reqs = [line for line in f.read().split('\n') if line]

if sys.version_info < (2, 7):
install_reqs += ['argparse']
Expand All @@ -29,6 +32,20 @@

history = open('CHANGES').read().replace('.. :changelog:', '')


class PyTest(TestCommand):
user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]

def initialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = []

def run_tests(self):
import pytest
errno = pytest.main(self.pytest_args)
sys.exit(errno)


setup(
name=about['__title__'],
version=about['__version__'],
Expand All @@ -39,11 +56,11 @@
author_email=about['__email__'],
description=about['__description__'],
long_description=readme,
packages=['tmuxp', 'tmuxp.testsuite'],
packages=['tmuxp'],
include_package_data=True,
install_requires=install_reqs,
tests_require=tests_reqs,
test_suite='tmuxp.testsuite',
cmdclass = {'test': PyTest},
zip_safe=False,
keywords=about['__title__'],
scripts=['pkg/tmuxp.bash', 'pkg/tmuxp.zsh', 'pkg/tmuxp.tcsh'],
Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
t = Server()
t.socket_name = 'tmuxp_test'

from tmuxp.testsuite import helpers # NOQA
from . import helpers # NOQA

logger = logging.getLogger() # Logger functionality

Expand Down
41 changes: 40 additions & 1 deletion tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from contextlib import contextmanager

from tmuxp import exc
from tmuxp.testsuite import t
from . import t

if sys.version_info < (2, 7):
import unittest2 as unittest
Expand All @@ -31,6 +31,9 @@
TEST_SESSION_PREFIX = 'test tmuxp_'

namer = tempfile._RandomNameSequence()
current_dir = os.path.abspath(os.path.dirname(__file__))
example_dir = os.path.abspath(os.path.join(current_dir, '..', 'examples'))
fixtures_dir = os.path.realpath(os.path.join(current_dir, 'fixtures'))


def get_test_session_name(server, prefix=TEST_SESSION_PREFIX):
Expand Down Expand Up @@ -365,3 +368,39 @@ def test_foo(self):
sys.stderr = prev_err
sys.__stdout__ = prev_rout
sys.__stderr__ = prev_rerr



class EnvironmentVarGuard(object):

"""Class to help protect the environment variable properly. Can be used as
a context manager.
Vendorize to fix issue with Anaconda Python 2 not
including test module, see #121.
"""

def __init__(self):
self._environ = os.environ
self._unset = set()
self._reset = dict()

def set(self, envvar, value):
if envvar not in self._environ:
self._unset.add(envvar)
else:
self._reset[envvar] = self._environ[envvar]
self._environ[envvar] = value

def unset(self, envvar):
if envvar in self._environ:
self._reset[envvar] = self._environ[envvar]
del self._environ[envvar]

def __enter__(self):
return self

def __exit__(self, *ignore_exc):
for envvar, value in self._reset.items():
self._environ[envvar] = value
for unset in self._unset:
del self._environ[unset]
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import unittest

from tmuxp import cli, config
from tmuxp.testsuite.helpers import TestCase
from .helpers import TestCase

logger = logging.getLogger(__name__)

Expand Down
7 changes: 1 addition & 6 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,10 @@
import kaptan

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

logger = logging.getLogger(__name__)
TMUXP_DIR = os.path.join(os.path.dirname(__file__), '.tmuxp')
current_dir = os.path.abspath(os.path.dirname(__file__))
example_dir = os.path.abspath(os.path.join(
current_dir, '..', '..', 'examples'))


sampleconfigdict = {
'session_name': 'sampleconfig',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_config_teamocil.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import kaptan

from tmuxp import config
from tmuxp.testsuite.helpers import TestCase
from .helpers import TestCase

logger = logging.getLogger(__name__)
TMUXP_DIR = os.path.join(os.path.dirname(__file__), '.tmuxp')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_config_tmuxinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import kaptan

from tmuxp import config
from tmuxp.testsuite.helpers import TestCase
from .helpers import TestCase

logger = logging.getLogger(__name__)
TMUXP_DIR = os.path.join(os.path.dirname(__file__), '.tmuxp')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import logging
import unittest

from tmuxp.testsuite.helpers import TmuxTestCase
from .helpers import TmuxTestCase

logger = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import unittest

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

logger = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import unittest

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

logger = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_tmuxobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import unittest

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

logger = logging.getLogger(__name__)

Expand Down
40 changes: 1 addition & 39 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,11 @@

from tmuxp import exc
from tmuxp.exc import BeforeLoadScriptError, BeforeLoadScriptNotExists
from tmuxp.testsuite.helpers import TestCase, TmuxTestCase, stdouts
from .helpers import TestCase, TmuxTestCase, stdouts, fixtures_dir
from tmuxp.util import has_required_tmux_version, run_before_script

logger = logging.getLogger(__name__)

current_dir = os.path.realpath(os.path.dirname(__file__))
fixtures_dir = os.path.realpath(os.path.join(current_dir, 'fixtures'))


class EnvironmentVarGuard(object):

"""Class to help protect the environment variable properly. Can be used as
a context manager.
Vendorize to fix issue with Anaconda Python 2 not
including test module, see #121.
"""

def __init__(self):
self._environ = os.environ
self._unset = set()
self._reset = dict()

def set(self, envvar, value):
if envvar not in self._environ:
self._unset.add(envvar)
else:
self._reset[envvar] = self._environ[envvar]
self._environ[envvar] = value

def unset(self, envvar):
if envvar in self._environ:
self._reset[envvar] = self._environ[envvar]
del self._environ[envvar]

def __enter__(self):
return self

def __exit__(self, *ignore_exc):
for envvar, value in self._reset.items():
self._environ[envvar] = value
for unset in self._unset:
del self._environ[unset]


class TmuxVersionTest(TmuxTestCase):

Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
"""Tests for tmuxp testsuite's helper and utility functions."""
"""Tests for .'s helper and utility functions."""

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

from tmuxp.testsuite.helpers import (TmuxTestCase, get_test_session_name,
from .helpers import (TmuxTestCase, get_test_session_name,
temp_session, unittest)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import unittest

from tmuxp import Pane, Server, Window
from tmuxp.testsuite.helpers import TmuxTestCase
from .helpers import TmuxTestCase

logger = logging.getLogger(__name__)

Expand Down
8 changes: 1 addition & 7 deletions tests/test_workspacebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,11 @@

from tmuxp import Window, config, exc
from tmuxp._compat import text_type
from tmuxp.testsuite.helpers import TmuxTestCase, mute
from .helpers import TmuxTestCase, mute, current_dir, example_dir, fixtures_dir
from tmuxp.workspacebuilder import WorkspaceBuilder

logger = logging.getLogger(__name__)

current_dir = os.path.realpath(os.path.dirname(__file__))
example_dir = os.path.realpath(
os.path.join(current_dir, '..', '..', 'examples')
)
fixtures_dir = os.path.realpath(os.path.join(current_dir, 'fixtures'))


class TwoPaneTest(TmuxTestCase):

Expand Down
5 changes: 1 addition & 4 deletions tests/test_workspacefreezer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@
import kaptan

from tmuxp import config
from tmuxp.testsuite.helpers import TmuxTestCase
from .helpers import TmuxTestCase, current_dir
from tmuxp.workspacebuilder import WorkspaceBuilder, freeze

logger = logging.getLogger(__name__)

current_dir = os.path.abspath(os.path.dirname(__file__))
example_dir = os.path.abspath(os.path.join(current_dir, '..', '..'))


class FreezeTest(TmuxTestCase):

Expand Down