Skip to content

Commit 7a56a83

Browse files
committed
Move testsuite bootstrap into TmuxTestCase, try travis now
1 parent 03e6406 commit 7a56a83

File tree

1 file changed

+59
-59
lines changed

1 file changed

+59
-59
lines changed

tmuxp/testsuite/helpers.py

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,24 @@
1515
TEST_SESSION_PREFIX = 'tmuxp_'
1616

1717

18-
def bootstrap():
19-
'''
20-
Returns a tuple of the session_name (generated) and a :class:`Session`
18+
19+
20+
21+
class TmuxTestCase(unittest.TestCase):
22+
23+
"""TmuxTestCase class, wraps the TestCase in a :class:`Session`."""
24+
25+
#: :class:`Session` object.
26+
session = None
27+
#: Session name for the TestCase.
28+
TEST_SESSION_NAME = None
29+
30+
def setUp(self):
31+
if not self.TEST_SESSION_NAME or not self.session:
32+
self.TEST_SESSION_NAME, self.session = self.bootstrap()
33+
34+
def bootstrap(self):
35+
"""Return tuple of the session_name (generated) and :class:`Session`.
2136
2237
Checks to verify if the user has a tmux client open.
2338
@@ -28,66 +43,51 @@ def bootstrap():
2843
if there is no other client open aside from a tmuxp_ prefixed session
2944
a dumby session will be made to prevent tmux from closing.
3045
31-
'''
32-
33-
session_name = 'tmuxp'
34-
if not t.has_session(session_name):
35-
t.tmux('new-session', '-d', '-s', session_name)
36-
37-
# find current sessions prefixed with tmuxp
38-
old_test_sessions = [s.get('session_name') for s in t._sessions
39-
if
40-
s.get('session_name').startswith(TEST_SESSION_PREFIX)]
41-
42-
other_sessions = [s.get('session_name') for s in t._sessions
43-
if not s.get('session_name').startswith(
44-
TEST_SESSION_PREFIX
45-
)]
46-
47-
# assert session_list == t.sessions
48-
49-
TEST_SESSION_NAME = TEST_SESSION_PREFIX + str(randint(0, 13370))
50-
try:
51-
session = t.new_session(
52-
session_name=TEST_SESSION_NAME,
53-
)
54-
except exc.TmuxpException as e:
55-
raise e
56-
57-
'''
58-
Make sure that tmuxp can :ref:`test_builder_visually` and switches to the
59-
newly created session for that testcase.
60-
'''
61-
try:
62-
t.switch_client(session.get('session_id'))
63-
pass
64-
except exc.TmuxpException as e:
65-
#t.attach_session(session.get('session_id'))
66-
pass
67-
68-
for old_test_session in old_test_sessions:
69-
logger.debug('Old test test session %s found. Killing it.' %
70-
old_test_session)
71-
t.kill_session(old_test_session)
72-
assert TEST_SESSION_NAME == session.get('session_name')
73-
assert TEST_SESSION_NAME != 'tmuxp'
74-
75-
return (TEST_SESSION_NAME, session)
46+
"""
7647

48+
session_name = 'tmuxp'
49+
if not t.has_session(session_name):
50+
t.tmux('new-session', '-d', '-s', session_name)
7751

78-
class TmuxTestCase(unittest.TestCase):
52+
# find current sessions prefixed with tmuxp
53+
old_test_sessions = [
54+
s.get('session_name') for s in t._sessions
55+
if s.get('session_name').startswith(TEST_SESSION_PREFIX)
56+
]
7957

80-
"""TmuxTestCase class, wraps the TestCase in a :class:`Session`."""
58+
other_sessions = [
59+
s.get('session_name') for s in t._sessions
60+
if not s.get('session_name').startswith(
61+
TEST_SESSION_PREFIX
62+
)
63+
]
8164

82-
#: :class:`Session` object.
83-
# session = None
84-
#: Session name for the TestCase.
85-
# TEST_SESSION_NAME = None
65+
# assert session_list == t.sessions
8666

87-
@classmethod
88-
def setUpClass(cls):
89-
"""Add :attr:`~.TEST_SESSION_NAME` and :attr:`~.session`."""
67+
TEST_SESSION_NAME = TEST_SESSION_PREFIX + str(randint(0, 13370))
9068
try:
91-
cls.TEST_SESSION_NAME, cls.session = bootstrap()
92-
except Exception as e:
69+
session = t.new_session(
70+
session_name=TEST_SESSION_NAME,
71+
)
72+
except exc.TmuxpException as e:
9373
raise e
74+
75+
'''
76+
Make sure that tmuxp can :ref:`test_builder_visually` and switches to the
77+
newly created session for that testcase.
78+
'''
79+
try:
80+
t.switch_client(session.get('session_id'))
81+
pass
82+
except exc.TmuxpException as e:
83+
#t.attach_session(session.get('session_id'))
84+
pass
85+
86+
for old_test_session in old_test_sessions:
87+
logger.debug('Old test test session %s found. Killing it.' %
88+
old_test_session)
89+
t.kill_session(old_test_session)
90+
assert TEST_SESSION_NAME == session.get('session_name')
91+
assert TEST_SESSION_NAME != 'tmuxp'
92+
93+
return (TEST_SESSION_NAME, session)

0 commit comments

Comments
 (0)