Skip to content

Commit aff1a64

Browse files
committed
Update TestSuite to use base case from helpers. Remove unittest.main() at bottom of files
1 parent 7a56a83 commit aff1a64

13 files changed

+132
-208
lines changed

tmuxp/testsuite/helpers.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import, division, print_function, with_statement
3+
4+
import time
5+
from random import randint
6+
37
try:
48
import unittest2 as unittest
5-
except ImportError: # Python 2.7
9+
except ImportError: # Python 2.7
610
import unittest
7-
import time
811
from . import t
9-
10-
from random import randint
1112
from .. import Server, log, exc
1213
import logging
1314
logger = logging.getLogger(__name__)
1415

1516
TEST_SESSION_PREFIX = 'tmuxp_'
1617

1718

19+
class TestCase(unittest.TestCase):
1820

21+
"""Base TestClass so we don't have to try: unittest2 every module. """
1922

2023

21-
class TmuxTestCase(unittest.TestCase):
24+
class TmuxTestCase(TestCase):
2225

2326
"""TmuxTestCase class, wraps the TestCase in a :class:`Session`."""
2427

@@ -28,8 +31,9 @@ class TmuxTestCase(unittest.TestCase):
2831
TEST_SESSION_NAME = None
2932

3033
def setUp(self):
34+
"""Run bootstrap if :attr:`~.session` is not set."""
3135
if not self.TEST_SESSION_NAME or not self.session:
32-
self.TEST_SESSION_NAME, self.session = self.bootstrap()
36+
self.bootstrap()
3337

3438
def bootstrap(self):
3539
"""Return tuple of the session_name (generated) and :class:`Session`.
@@ -90,4 +94,5 @@ def bootstrap(self):
9094
assert TEST_SESSION_NAME == session.get('session_name')
9195
assert TEST_SESSION_NAME != 'tmuxp'
9296

93-
return (TEST_SESSION_NAME, session)
97+
self.TEST_SESSION_NAME = TEST_SESSION_NAME
98+
self.session = session

tmuxp/testsuite/test_cli.py

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,28 @@
33

44
import os
55
import shutil
6-
try:
7-
import unittest2 as unittest
8-
except ImportError: # Python 2.7
9-
import unittest
106
import kaptan
117
import tempfile
128
from .. import config, cli
139
from ..util import tmux
10+
from .helpers import TestCase
1411

1512
import logging
1613

1714
logger = logging.getLogger(__name__)
1815
TMUXP_DIR = os.path.join(os.path.dirname(__file__), '.tmuxp')
1916

2017

21-
class StartupTest(unittest.TestCase):
18+
class StartupTest(TestCase):
2219

23-
'''test startup_cli()'''
20+
"""test startup_cli()."""
2421

2522
def setUp(self):
2623
if os.path.isdir(TMUXP_DIR):
2724
shutil.rmtree(TMUXP_DIR)
2825

2926
def test_creates_config_dir_not_exists(self):
30-
'''cli.startup() creates config dir if not exists'''
27+
"""cli.startup() creates config dir if not exists."""
3128

3229
self.assertFalse(os.path.exists(TMUXP_DIR))
3330
cli.startup(TMUXP_DIR)
@@ -41,16 +38,16 @@ def tearDownClass(cls):
4138
logger.debug('wiped %s' % TMUXP_DIR)
4239

4340

44-
class FindConfigsTest(unittest.TestCase):
41+
class FindConfigsTest(TestCase):
4542

46-
'''test in_dir() test'''
43+
"""test in_dir() test."""
4744

4845
def setUp(self):
4946
if os.path.isdir(TMUXP_DIR):
5047
shutil.rmtree(TMUXP_DIR)
5148

5249
def test_in_dir_from_config_dir(self):
53-
'''config.in_dir() finds configs config dir'''
50+
"""config.in_dir() finds configs config dir."""
5451

5552
cli.startup(TMUXP_DIR)
5653
config1 = tempfile.NamedTemporaryFile(
@@ -69,7 +66,7 @@ def test_in_dir_from_config_dir(self):
6966
self.assertEqual(len(configs_found), 2)
7067

7168
def test_in_dir_from_current_dir(self):
72-
'''config.in_dir() finds configs config dir'''
69+
"""config.in_dir() find configs config dir."""
7370

7471
cli.startup(TMUXP_DIR)
7572
config1 = tempfile.NamedTemporaryFile(
@@ -88,7 +85,7 @@ def test_in_dir_from_current_dir(self):
8885
self.assertEqual(len(configs_found), 2)
8986

9087
def test_ignore_non_configs_from_current_dir(self):
91-
'''cli.in_dir() ignores non-configs from config dir'''
88+
"""cli.in_dir() ignore non-config from config dir."""
9289

9390
cli.startup(TMUXP_DIR)
9491
badconfig = tempfile.NamedTemporaryFile(
@@ -107,7 +104,7 @@ def test_ignore_non_configs_from_current_dir(self):
107104
self.assertEqual(len(configs_found), 1)
108105

109106
def test_get_configs_cwd(self):
110-
'''config.in_cwd() finds config in shell's current working directory'''
107+
"""config.in_cwd() find config in shell current working directory."""
111108

112109
current_dir = os.getcwd()
113110

@@ -142,26 +139,34 @@ def tearDownClass(cls):
142139
sampleconfigdict = {
143140
'session_name': 'sampleconfig',
144141
'start_directory': '~',
145-
'windows': [{
146-
'window_name': 'editor',
147-
'panes': [
148-
{
149-
'start_directory': '~', 'shell_command': ['vim'],
150-
}, {
151-
'shell_command': ['cowsay "hey"']
152-
},
153-
],
154-
'layout': 'main-verticle'},
155-
{'window_name': 'logging', 'panes': [
156-
{'shell_command': ['tail -F /var/log/syslog'],
157-
'start_directory':'/var/log'}
158-
]}, {
159-
'options': {'automatic_rename': True, },
142+
'windows': [
143+
{
144+
'window_name': 'editor',
160145
'panes': [
161-
{'shell_command': ['htop']}
146+
{
147+
'start_directory': '~',
148+
'shell_command': ['vim'],
149+
},
150+
{
151+
'shell_command': ['cowsay "hey"']
152+
},
153+
],
154+
'layout': 'main-verticle'
155+
},
156+
{
157+
'window_name': 'logging', 'panes': [
158+
{
159+
'shell_command': ['tail -F /var/log/syslog'],
160+
'start_directory':'/var/log'
161+
}
162162
]
163-
}]
163+
}, {
164+
'options': {'automatic_rename': True, },
165+
'panes': [
166+
{
167+
'shell_command': ['htop']
168+
}
169+
]
170+
}
171+
]
164172
}
165-
166-
if __name__ == '__main__':
167-
unittest.main()

tmuxp/testsuite/test_config.py

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33

44
import os
55
import shutil
6-
try:
7-
import unittest2 as unittest
8-
except ImportError: # Python 2.7
9-
import unittest
106
import kaptan
117
from .. import config, exc
128
from ..util import tmux
9+
from .helpers import TestCase
1310

1411
import logging
1512

@@ -52,7 +49,7 @@
5249
}
5350

5451

55-
class ImportExportTest(unittest.TestCase):
52+
class ImportExportTest(TestCase):
5653

5754
@classmethod
5855
def setUpClass(cls):
@@ -132,7 +129,7 @@ def tearDownClass(cls):
132129
logging.debug('wiped %s' % TMUXP_DIR)
133130

134131

135-
class ExpandTest(unittest.TestCase):
132+
class ExpandTest(TestCase):
136133

137134
"""Assume configuration has been imported into a python dict correctly."""
138135

@@ -262,7 +259,7 @@ def test_config(self):
262259
self.assertDictEqual(test_config, self.after_config)
263260

264261

265-
class InlineTest(unittest.TestCase):
262+
class InlineTest(TestCase):
266263

267264
"""Tests for :meth:`config.inline()`."""
268265

@@ -346,7 +343,7 @@ def test_config(self):
346343
self.assertDictEqual(test_config, self.after_config)
347344

348345

349-
class InheritanceTest(unittest.TestCase):
346+
class InheritanceTest(TestCase):
350347
"""Test config inheritance for the nested 'start_command'."""
351348

352349
config_before = {
@@ -456,13 +453,13 @@ def test_start_directory(self):
456453
self.assertDictEqual(config, self.config_after)
457454

458455

459-
class ShellCommandBeforeTest(unittest.TestCase):
456+
class ShellCommandBeforeTest(TestCase):
460457

461-
'''
458+
"""
462459
test config inheritance for the nested 'start_command'
463460
464461
format for tests will be pre
465-
'''
462+
"""
466463

467464
config_unexpanded = { # shell_command_before is string in some areas
468465
'session_name': 'sampleconfig',
@@ -630,7 +627,7 @@ def test_shell_command_before(self):
630627

631628

632629

633-
class TrickleRelativeStartDirectory(unittest.TestCase):
630+
class TrickleRelativeStartDirectory(TestCase):
634631
config_expanded = { # shell_command_before is string in some areas
635632
'session_name': 'sampleconfig',
636633
'start_directory': '/var',
@@ -703,9 +700,9 @@ def test_shell_command_before(self):
703700
self.maxDiff = None
704701
self.assertDictEqual(test_config, self.config_after)
705702

706-
class ConfigConsistency(unittest.TestCase):
703+
class ConfigConsistency(TestCase):
707704

708-
delete_this = '''
705+
delete_this = """
709706
session_name: sampleconfig
710707
start_directory: '~'
711708
windows:
@@ -726,10 +723,10 @@ class ConfigConsistency(unittest.TestCase):
726723
panes:
727724
- shell_command:
728725
- htop
729-
'''
726+
"""
730727

731728
def test_no_session_name(self):
732-
yaml_config = '''
729+
yaml_config = """
733730
- window_name: editor
734731
panes:
735732
shell_command:
@@ -740,7 +737,7 @@ def test_no_session_name(self):
740737
panes:
741738
- shell_command:
742739
- htop
743-
'''
740+
"""
744741

745742
sconfig = kaptan.Kaptan(handler='yaml')
746743
sconfig = sconfig.import_config(yaml_config).get()
@@ -749,9 +746,9 @@ def test_no_session_name(self):
749746
config.validate_schema(sconfig)
750747

751748
def test_no_windows(self):
752-
yaml_config = '''
749+
yaml_config = """
753750
session_name: test session
754-
'''
751+
"""
755752

756753
sconfig = kaptan.Kaptan(handler='yaml')
757754
sconfig = sconfig.import_config(yaml_config).get()
@@ -760,7 +757,7 @@ def test_no_windows(self):
760757
config.validate_schema(sconfig)
761758

762759
def test_no_window_name(self):
763-
yaml_config = '''
760+
yaml_config = """
764761
session_name: test session
765762
windows:
766763
- window_name: editor
@@ -772,14 +769,10 @@ def test_no_window_name(self):
772769
panes:
773770
- shell_command:
774771
- htop
775-
'''
772+
"""
776773

777774
sconfig = kaptan.Kaptan(handler='yaml')
778775
sconfig = sconfig.import_config(yaml_config).get()
779776

780777
with self.assertRaisesRegexp(exc.ConfigError, 'missing "window_name"'):
781778
config.validate_schema(sconfig)
782-
783-
784-
if __name__ == '__main__':
785-
unittest.main()

0 commit comments

Comments
 (0)