Skip to content

Commit

Permalink
Get unittests running with freebsd
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Dec 26, 2014
1 parent d101e75 commit 34dff7d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
4 changes: 2 additions & 2 deletions tmuxp/testsuite/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

logger = logging.getLogger(__name__)

current_dir = os.path.abspath(os.path.dirname(__file__))
fixtures_dir = os.path.abspath(os.path.join(current_dir, 'fixtures'))
current_dir = os.path.realpath(os.path.dirname(__file__))
fixtures_dir = os.path.realpath(os.path.join(current_dir, 'fixtures'))


class TmuxVersionTest(TmuxTestCase):
Expand Down
57 changes: 37 additions & 20 deletions tmuxp/testsuite/workspacebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
with_statement, unicode_literals

import os
import platform
import sys
import logging
import unittest
Expand All @@ -24,9 +25,9 @@

logger = logging.getLogger(__name__)

current_dir = os.path.abspath(os.path.dirname(__file__))
example_dir = os.path.abspath(os.path.join(current_dir, '..', '..', 'examples'))
fixtures_dir = os.path.abspath(os.path.join(current_dir, 'fixtures'))
current_dir = os.path.realpath(os.path.dirname(__file__))
example_dir = os.path.realpath(os.path.join(current_dir, '..', '..', 'examples'))
fixtures_dir = os.path.realpath(os.path.join(current_dir, 'fixtures'))


class TwoPaneTest(TmuxTestCase):
Expand Down Expand Up @@ -300,33 +301,39 @@ def test_automatic_rename_option(self):
self.assertNotEqual(s.get('session_name'), 'tmuxp')
w = s.windows[0]

man_window_name = 'man'

# BSD operating systems will wrap manual pages in less
if 'BSD' in platform.system():
man_window_name = 'less'

for i in range(60):
self.session.server._update_windows()
if w.get('window_name') != 'man':
if w.get('window_name') != man_window_name:
break
time.sleep(.1)

self.assertNotEqual(w.get('window_name'), 'man')
self.assertNotEqual(w.get('window_name'), man_window_name)

pane_base_index = w.show_window_option('pane-base-index', g=True)
w.select_pane(pane_base_index)

for i in range(60):
self.session.server._update_windows()
if w.get('window_name') == 'man':
if w.get('window_name') == man_window_name:
break
time.sleep(.1)

self.assertEqual(w.get('window_name'), text_type('man'))
self.assertEqual(w.get('window_name'), text_type(man_window_name))

w.select_pane('-D')
for i in range(60):
self.session.server._update_windows()
if w['window_name'] != 'man':
if w['window_name'] != man_window_name:
break
time.sleep(.1)

self.assertNotEqual(w.get('window_name'), text_type('man'))
self.assertNotEqual(w.get('window_name'), text_type(man_window_name))


class BlankPaneTest(TmuxTestCase):
Expand Down Expand Up @@ -575,7 +582,7 @@ class PaneOrderingTest(TmuxTestCase):

yaml_config = """
session_name: sampleconfig
start_directory: '~'
start_directory: {HOME}
windows:
- options:
- automatic_rename: on
Expand All @@ -584,8 +591,11 @@ class PaneOrderingTest(TmuxTestCase):
- cd /usr/bin
- cd /usr
- cd /sbin
- cd /home
"""
- cd {HOME}
""".format(
HOME=os.path.realpath(os.path.expanduser('~'))
)


def test_pane_order(self):

Expand All @@ -594,8 +604,9 @@ def test_pane_order(self):
'/usr/bin',
'/usr',
'/sbin',
'/home'
os.path.realpath(os.path.expanduser('~'))
]

s = self.session
sconfig = kaptan.Kaptan(handler='yaml')
sconfig = sconfig.import_config(self.yaml_config).get()
Expand Down Expand Up @@ -676,23 +687,23 @@ class BeforeLoadScript(TmuxTestCase):

config_script_not_exists = """
session_name: sampleconfig
before_script: {fixtures_dir}/script_not_exists.sh
before_script: {script_not_exists}
windows:
- panes:
- pane
"""

config_script_fails = """
session_name: sampleconfig
before_script: {fixtures_dir}/script_failed.sh
before_script: {script_failed}
windows:
- panes:
- pane
"""

config_script_completes = """
session_name: sampleconfig
before_script: {fixtures_dir}/script_complete.sh
before_script: {script_complete}
windows:
- panes:
- pane
Expand All @@ -702,8 +713,10 @@ def test_throw_error_if_retcode_error(self):

sconfig = kaptan.Kaptan(handler='yaml')
yaml = self.config_script_fails.format(
fixtures_dir=fixtures_dir
fixtures_dir=fixtures_dir,
script_failed=os.path.join(fixtures_dir,'script_failed.sh')
)
print(fixtures_dir)
sconfig = sconfig.import_config(yaml).get()
sconfig = config.expand(sconfig)
sconfig = config.trickle(sconfig)
Expand All @@ -726,7 +739,8 @@ def test_throw_error_if_file_not_exists(self):

sconfig = kaptan.Kaptan(handler='yaml')
yaml = self.config_script_not_exists.format(
fixtures_dir=fixtures_dir
fixtures_dir=fixtures_dir,
script_not_exists=os.path.join(fixtures_dir,'script_not_exists.sh')
)
sconfig = sconfig.import_config(yaml).get()
sconfig = config.expand(sconfig)
Expand All @@ -749,12 +763,15 @@ def test_throw_error_if_file_not_exists(self):
msg="Kills session if before_script doesn't exist"
)

def test_true_if_test_passes(self):

def test_true_if_test_passes(self):
assert(os.path.exists(os.path.join(fixtures_dir,'script_complete.sh')))
sconfig = kaptan.Kaptan(handler='yaml')
yaml = self.config_script_completes.format(
fixtures_dir=fixtures_dir
fixtures_dir=fixtures_dir,
script_complete=os.path.join(fixtures_dir,'script_complete.sh')
)

sconfig = sconfig.import_config(yaml).get()
sconfig = config.expand(sconfig)
sconfig = config.trickle(sconfig)
Expand Down

0 comments on commit 34dff7d

Please sign in to comment.