Skip to content

Commit

Permalink
fix #55. where tmuxp would crash with letter version Version 0.1.7.
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Feb 25, 2014
1 parent c8fd2b6 commit 87293f6
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGES
Expand Up @@ -4,6 +4,14 @@ Changelog

Here you can find the recent changes to tmuxp.

0.1.7
-----

- [cli] [test]: Fix `Issue #55`_ where tmuxp would crash with letter
numbers in version. Write tests.

.. _Issue #55: https://github.com/tony/tmuxp/issues/55

0.1.6
-----

Expand Down
2 changes: 1 addition & 1 deletion tmuxp/__init__.py
Expand Up @@ -13,7 +13,7 @@

__title__ = 'tmuxp'
__package_name__ = 'tmuxp'
__version__ = '0.1.6'
__version__ = '0.1.7'
__description__ = 'Manage tmux sessions thru JSON, YAML configs. Features Python API'
__email__ = 'tony@git-pull.com'
__author__ = 'Tony Narlock'
Expand Down
5 changes: 5 additions & 0 deletions tmuxp/testsuite/cli.py
Expand Up @@ -25,6 +25,11 @@
TMUXP_DIR = os.path.join(os.path.dirname(__file__), '.tmuxp')


class CLIVersion(TestCase):

pass


class StartupTest(TestCase):

"""test startup_cli()."""
Expand Down
60 changes: 60 additions & 0 deletions tmuxp/testsuite/util.py
@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
"""Tests for utility functions in tmux.
tmuxp.tests.util
~~~~~~~~~~~~~~~~
"""

from __future__ import absolute_import, division, print_function, \
with_statement, unicode_literals

import random
import logging
import unittest

from .. import exc
from ..util import has_required_tmux_version

from .helpers import TmuxTestCase

logger = logging.getLogger(__name__)


class TmuxVersionTest(TmuxTestCase):

"""Test the :meth:`has_required_tmux_version`."""

def test_no_arg_uses_tmux_version(self):
result = has_required_tmux_version()
self.assertRegexpMatches(result, r'[0-9]\.[0-9]')

def test_ignores_letter_versions(self):
"""Ignore letters such as 1.8b.
See ticket https://github.com/tony/tmuxp/issues/55.
In version 0.1.7 this is adjusted to use LooseVersion, in order to
allow letters.
"""
result = has_required_tmux_version('1.9a')
self.assertRegexpMatches(result, r'[0-9]\.[0-9]')

result = has_required_tmux_version('1.8a')
self.assertEqual(result, r'1.8')

def test_error_version_less_1_7(self):
with self.assertRaisesRegexp(exc.TmuxpException, 'tmuxp only supports'):
has_required_tmux_version('1.7')

with self.assertRaisesRegexp(exc.TmuxpException, 'tmuxp only supports'):
has_required_tmux_version('1.6a')

has_required_tmux_version('1.9a')


def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TmuxVersionTest))
return suite
24 changes: 18 additions & 6 deletions tmuxp/util.py
Expand Up @@ -11,6 +11,7 @@
import unittest
import collections
import subprocess
import re
import os
import sys
import logging
Expand Down Expand Up @@ -263,14 +264,25 @@ def is_version(version):
return StrictVersion(installed_version) == StrictVersion(version)


def has_required_tmux_version():
"""Return if tmux meets version requirement. Version >1.8 or above."""
proc = tmux('-V')
def has_required_tmux_version(version=None):
"""Return if tmux meets version requirement. Version >1.8 or above.
if proc.stderr:
raise exc.TmuxpException(proc.stderr)
:versionchanged: 0.1.7
Versions will now remove trailing letters per `Issue 55`_.
.. _Issue 55: https://github.com/tony/tmuxp/issues/55.
"""

if not version:
proc = tmux('-V')

if proc.stderr:
raise exc.TmuxpException(proc.stderr)

version = proc.stdout[0].split('tmux ')[1]

version = proc.stdout[0].split('tmux ')[1]
version = re.sub(r'[a-z]', '', version)

if StrictVersion(version) <= StrictVersion("1.7"):
raise exc.TmuxpException(
Expand Down

0 comments on commit 87293f6

Please sign in to comment.