|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""Tests for utility functions in tmux. |
| 3 | +
|
| 4 | +tmuxp.tests.util |
| 5 | +~~~~~~~~~~~~~~~~ |
| 6 | +
|
| 7 | +""" |
| 8 | + |
| 9 | +from __future__ import absolute_import, division, print_function, \ |
| 10 | + with_statement, unicode_literals |
| 11 | + |
| 12 | +import random |
| 13 | +import logging |
| 14 | +import unittest |
| 15 | + |
| 16 | +from .. import exc |
| 17 | +from ..util import has_required_tmux_version |
| 18 | + |
| 19 | +from .helpers import TmuxTestCase |
| 20 | + |
| 21 | +logger = logging.getLogger(__name__) |
| 22 | + |
| 23 | + |
| 24 | +class TmuxVersionTest(TmuxTestCase): |
| 25 | + |
| 26 | + """Test the :meth:`has_required_tmux_version`.""" |
| 27 | + |
| 28 | + def test_no_arg_uses_tmux_version(self): |
| 29 | + result = has_required_tmux_version() |
| 30 | + self.assertRegexpMatches(result, r'[0-9]\.[0-9]') |
| 31 | + |
| 32 | + def test_ignores_letter_versions(self): |
| 33 | + """Ignore letters such as 1.8b. |
| 34 | +
|
| 35 | + See ticket https://github.com/tony/tmuxp/issues/55. |
| 36 | +
|
| 37 | + In version 0.1.7 this is adjusted to use LooseVersion, in order to |
| 38 | + allow letters. |
| 39 | +
|
| 40 | + """ |
| 41 | + result = has_required_tmux_version('1.9a') |
| 42 | + self.assertRegexpMatches(result, r'[0-9]\.[0-9]') |
| 43 | + |
| 44 | + result = has_required_tmux_version('1.8a') |
| 45 | + self.assertEqual(result, r'1.8') |
| 46 | + |
| 47 | + def test_error_version_less_1_7(self): |
| 48 | + with self.assertRaisesRegexp(exc.TmuxpException, 'tmuxp only supports'): |
| 49 | + has_required_tmux_version('1.7') |
| 50 | + |
| 51 | + with self.assertRaisesRegexp(exc.TmuxpException, 'tmuxp only supports'): |
| 52 | + has_required_tmux_version('1.6a') |
| 53 | + |
| 54 | + has_required_tmux_version('1.9a') |
| 55 | + |
| 56 | + |
| 57 | +def suite(): |
| 58 | + suite = unittest.TestSuite() |
| 59 | + suite.addTest(unittest.makeSuite(TmuxVersionTest)) |
| 60 | + return suite |
0 commit comments