Skip to content

Commit 2ff7cbd

Browse files
committed
More tests for Server
1 parent 5dab47a commit 2ff7cbd

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

tmuxp/server.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,17 @@ class Server(TmuxRelationalObject):
3939
socket_name = None
4040
socket_path = None
4141
config_file = None
42+
colors = None
4243
childIdAttribute = 'session_id'
4344

44-
def __init__(self, socket_name=None, socket_path=None, config_file=None,
45-
**kwargs):
45+
def __init__(
46+
self,
47+
socket_name=None,
48+
socket_path=None,
49+
config_file=None,
50+
colors=None,
51+
**kwargs
52+
):
4653
self._windows = []
4754
self._panes = []
4855

@@ -55,6 +62,9 @@ def __init__(self, socket_name=None, socket_path=None, config_file=None,
5562
if config_file:
5663
self.config_file = config_file
5764

65+
if colors:
66+
self.colors = colors
67+
5868
def tmux(self, *args, **kwargs):
5969
args = list(args)
6070
if self.socket_name:
@@ -63,6 +73,13 @@ def tmux(self, *args, **kwargs):
6373
args.insert(0, '-S{}'.format(self.socket_path))
6474
if self.config_file:
6575
args.insert(0, '-f{}'.format(self.config_file))
76+
if self.colors:
77+
if self.colors == 256:
78+
args.insert(0, '-2')
79+
elif self.colors == 88:
80+
args.insert(0, '-8')
81+
else:
82+
raise ValueError('Server.colors must equal 88 or 256')
6683

6784
return tmux(*args, **kwargs)
6885

@@ -437,14 +454,14 @@ def new_session(self,
437454
:type kill_session: bool
438455
'''
439456

440-
# ToDo: Update below to work with attach_if_exists
441457
if self.has_session(session_name):
442458
if kill_session:
443459
self.tmux('kill-session', '-t%s' % session_name)
444460
logger.info('session %s exists. killed it.' % session_name)
445461
else:
446462
raise TmuxSessionExists(
447-
'Session named %s exists' % session_name)
463+
'Session named %s exists' % session_name
464+
)
448465

449466
logger.debug('creating session %s' % session_name)
450467

@@ -485,6 +502,4 @@ def new_session(self,
485502

486503
session = Session(server=self, **session)
487504

488-
# self._sessions.append(session)
489-
490505
return session

tmuxp/testsuite/test_server.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,12 @@ def test_config(self):
4444
myserver = Server(config_file='test')
4545
self.assertEqual(myserver.config_file, 'test')
4646

47+
def test_256_colors(self):
48+
myserver = Server(colors=256)
49+
self.assertEqual(myserver.colors, 256)
50+
51+
# try to read the command in util.tmux()
52+
# get util.tmux to have a self.cmd and create tests for it
53+
4754
if __name__ == '__main__':
4855
unittest.main()

0 commit comments

Comments
 (0)