Skip to content

Commit b8adcf9

Browse files
committed
Merge pull request #90 from tony/OSX-Testfix
OSX testfixes + test speedup
2 parents 34dff7d + 243d57b commit b8adcf9

File tree

1 file changed

+107
-42
lines changed

1 file changed

+107
-42
lines changed

tmuxp/testsuite/workspacebuilder.py

Lines changed: 107 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import sys
1515
import logging
1616
import unittest
17+
import tempfile
1718
import time
1819

1920
import kaptan
@@ -187,12 +188,12 @@ def test_focus_pane_index(self):
187188
self.assertNotEqual(w.get('window_name'), 'man')
188189

189190
pane_path = '/usr'
190-
for i in range(60):
191+
for i in range(10):
191192
p = w.attached_pane()
192193
p.server._update_panes()
193194
if p.get('pane_current_path') == pane_path:
194195
break
195-
time.sleep(.2)
196+
time.sleep(.4)
196197

197198
self.assertEqual(p.get('pane_current_path'), pane_path)
198199

@@ -205,12 +206,12 @@ def test_focus_pane_index(self):
205206

206207
p = None
207208
pane_path = '/'
208-
for i in range(60):
209+
for i in range(10):
209210
p = window3.attached_pane()
210211
p.server._update_panes()
211212
if p.get('pane_current_path') == pane_path:
212213
break
213-
time.sleep(.2)
214+
time.sleep(.4)
214215

215216
self.assertEqual(p.get('pane_current_path'), pane_path)
216217

@@ -307,31 +308,31 @@ def test_automatic_rename_option(self):
307308
if 'BSD' in platform.system():
308309
man_window_name = 'less'
309310

310-
for i in range(60):
311+
for i in range(10):
311312
self.session.server._update_windows()
312313
if w.get('window_name') != man_window_name:
313314
break
314-
time.sleep(.1)
315+
time.sleep(.2)
315316

316317
self.assertNotEqual(w.get('window_name'), man_window_name)
317318

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

321-
for i in range(60):
322+
for i in range(10):
322323
self.session.server._update_windows()
323324
if w.get('window_name') == man_window_name:
324325
break
325-
time.sleep(.1)
326+
time.sleep(.2)
326327

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

329330
w.select_pane('-D')
330-
for i in range(60):
331+
for i in range(10):
331332
self.session.server._update_windows()
332333
if w['window_name'] != man_window_name:
333334
break
334-
time.sleep(.1)
335+
time.sleep(.2)
335336

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

@@ -374,7 +375,8 @@ class StartDirectoryTest(TmuxTestCase):
374375
start_directory: '/usr'
375376
windows:
376377
- window_name: supposed to be /usr/bin
377-
start_directory: '/usr/bin'
378+
window_index: 1
379+
start_directory: /usr/bin
378380
layout: main-horizontal
379381
options:
380382
main-pane-height: 50
@@ -384,7 +386,8 @@ class StartDirectoryTest(TmuxTestCase):
384386
- shell_command:
385387
- echo "moo"
386388
- window_name: support to be /dev
387-
start_directory: '/dev'
389+
window_index: 2
390+
start_directory: /dev
388391
layout: main-horizontal
389392
panes:
390393
- shell_command:
@@ -394,7 +397,8 @@ class StartDirectoryTest(TmuxTestCase):
394397
- shell_command:
395398
- echo "moo"
396399
- window_name: cwd containing a space
397-
start_directory: /tmp/foo bar
400+
window_index: 3
401+
start_directory: {TEST_DIR}
398402
layout: main-horizontal
399403
panes:
400404
- shell_command:
@@ -404,6 +408,7 @@ class StartDirectoryTest(TmuxTestCase):
404408
- shell_command:
405409
- echo "moo"
406410
- window_name: testsa3
411+
window_index: 4
407412
layout: main-horizontal
408413
panes:
409414
- shell_command:
@@ -412,7 +417,8 @@ class StartDirectoryTest(TmuxTestCase):
412417
- echo "hey"
413418
- shell_command:
414419
- echo "moo3"
415-
- window_name: cwd relative to config file
420+
- window_name: cwd relative to start_directory since no rel dir entered
421+
window_index: 5
416422
layout: main-horizontal
417423
start_directory: ./
418424
panes:
@@ -426,40 +432,63 @@ class StartDirectoryTest(TmuxTestCase):
426432

427433
def setUp(self):
428434
super(StartDirectoryTest, self).setUp()
429-
if not os.path.exists('/tmp/foo bar'):
430-
os.mkdir('/tmp/foo bar')
435+
436+
self.tempdir = tempfile.gettempdir()
437+
self.test_dir = os.path.join(self.tempdir, 'foo bar')
438+
439+
if not os.path.exists(self.test_dir):
440+
os.mkdir(self.test_dir)
431441
self._temp_dir_created = True
432442
else:
433443
self._temp_dir_created = False
434444

435445
def tearDown(self):
436446
super(StartDirectoryTest, self).tearDown()
437447
if self._temp_dir_created:
438-
os.rmdir('/tmp/foo bar')
448+
os.rmdir(self.test_dir)
439449

440450
def test_start_directory(self):
441451

442-
start_directory = os.getcwd()
452+
test_config = self.yaml_config.format(
453+
TMP_DIR=self.tempdir,
454+
TEST_DIR=self.test_dir
455+
)
443456

444457
sconfig = kaptan.Kaptan(handler='yaml')
445-
sconfig = sconfig.import_config(self.yaml_config).get()
458+
sconfig = sconfig.import_config(test_config).get()
446459
sconfig = config.expand(sconfig)
447460
sconfig = config.trickle(sconfig)
448461

449462
builder = WorkspaceBuilder(sconf=sconfig)
450463
builder.build(session=self.session)
451464

452465
assert(self.session == builder.session)
453-
dirs = ['/usr/bin', '/dev', '/tmp/foo bar', '/usr', '/usr']
466+
dirs = [
467+
'/usr/bin', '/dev', self.test_dir,
468+
'/usr',
469+
'/usr'
470+
]
471+
454472
for path, window in zip(dirs, self.session.windows):
455473
for p in window.panes:
456474
for i in range(60):
457475
p.server._update_panes()
458-
if p.get('pane_current_path') == path:
476+
pane_path = p.get('pane_current_path')
477+
if pane_path is None:
478+
pass
479+
elif (
480+
path in pane_path or
481+
pane_path == path
482+
):
483+
result = (
484+
path == pane_path or
485+
path in pane_path
486+
)
459487
break
460488
time.sleep(.2)
461489

462-
self.assertEqual(p.get('pane_current_path'), path)
490+
# handle case with OS X adding /private/ to /tmp/ paths
491+
self.assertTrue(result)
463492

464493

465494
class StartDirectoryRelativeTest(TmuxTestCase):
@@ -481,7 +510,6 @@ class StartDirectoryRelativeTest(TmuxTestCase):
481510
windows:
482511
- window_name: supposed to be /usr/bin
483512
start_directory: '/usr/bin'
484-
layout: main-horizontal
485513
options:
486514
main-pane-height: 50
487515
panes:
@@ -500,7 +528,7 @@ class StartDirectoryRelativeTest(TmuxTestCase):
500528
- shell_command:
501529
- echo "moo"
502530
- window_name: cwd containing a space
503-
start_directory: /tmp/foo bar
531+
start_directory: {TEST_DIR}
504532
layout: main-horizontal
505533
panes:
506534
- shell_command:
@@ -509,7 +537,7 @@ class StartDirectoryRelativeTest(TmuxTestCase):
509537
- echo "hey"
510538
- shell_command:
511539
- echo "moo"
512-
- window_name: testsa3
540+
- window_name: inherit start_directory which is rel to config file
513541
layout: main-horizontal
514542
panes:
515543
- shell_command:
@@ -532,44 +560,83 @@ class StartDirectoryRelativeTest(TmuxTestCase):
532560

533561
def setUp(self):
534562
super(StartDirectoryRelativeTest, self).setUp()
535-
if not os.path.exists('/tmp/foo bar') and not os.path.exists('/tmp/testRelConfigDir'):
536-
os.mkdir('/tmp/foo bar')
537-
os.mkdir('/tmp/testRelConfigDir')
563+
564+
self.tempdir = tempfile.gettempdir()
565+
566+
self.test_dir = os.path.join(self.tempdir, 'foo bar')
567+
self.config_dir = os.path.join(self.tempdir, 'testRelConfigDir')
568+
569+
if (
570+
not os.path.exists(self.test_dir) or
571+
not os.path.exists(self.config_dir)
572+
):
573+
os.mkdir(self.test_dir)
574+
os.mkdir(self.config_dir)
538575
self._temp_dir_created = True
539576
else:
540577
self._temp_dir_created = False
541578

579+
assert(os.path.exists(self.config_dir))
580+
assert(os.path.exists(self.test_dir))
581+
542582
def tearDown(self):
543583
super(StartDirectoryRelativeTest, self).tearDown()
544584
if self._temp_dir_created:
545-
os.rmdir('/tmp/foo bar')
546-
os.rmdir('/tmp/testRelConfigDir')
585+
os.rmdir(self.test_dir)
586+
os.rmdir(self.config_dir)
547587

548588
def test_start_directory(self):
549589

590+
test_config = self.yaml_config.format(
591+
TEST_DIR=self.test_dir,
592+
)
593+
550594
start_directory = os.getcwd()
551595

552596
sconfig = kaptan.Kaptan(handler='yaml')
553-
sconfig = sconfig.import_config(self.yaml_config).get()
597+
sconfig = sconfig.import_config(test_config).get()
554598
# the second argument of os.getcwd() mimics the behavior
555599
# the CLI loader will do, but it passes in the config file's location.
556-
sconfig = config.expand(sconfig, '/tmp/testRelConfigDir')
600+
sconfig = config.expand(sconfig, self.config_dir)
601+
557602
sconfig = config.trickle(sconfig)
558603

604+
assert(os.path.exists(self.config_dir))
605+
assert(os.path.exists(self.test_dir))
559606
builder = WorkspaceBuilder(sconf=sconfig)
560607
builder.build(session=self.session)
561608

562609
assert(self.session == builder.session)
563-
dirs = ['/usr/bin', '/dev', '/tmp/foo bar', '/tmp/testRelConfigDir']
610+
611+
dirs = [
612+
'/usr/bin',
613+
'/dev',
614+
self.test_dir,
615+
self.config_dir,
616+
self.config_dir,
617+
]
618+
564619
for path, window in zip(dirs, self.session.windows):
565620
for p in window.panes:
566621
for i in range(60):
567622
p.server._update_panes()
568-
if p.get('pane_current_path') == path:
623+
# Handle case where directories resolve to /private/ in OSX
624+
pane_path = p.get('pane_current_path')
625+
if pane_path is None:
626+
pass
627+
elif (
628+
path in pane_path or
629+
pane_path == path
630+
):
631+
result = (
632+
path == pane_path or
633+
path in pane_path
634+
)
635+
569636
break
570637
time.sleep(.2)
571638

572-
self.assertEqual(p.get('pane_current_path'), path)
639+
self.assertTrue(result)
573640

574641

575642
class PaneOrderingTest(TmuxTestCase):
@@ -596,7 +663,6 @@ class PaneOrderingTest(TmuxTestCase):
596663
HOME=os.path.realpath(os.path.expanduser('~'))
597664
)
598665

599-
600666
def test_pane_order(self):
601667

602668
# test order of `panes` (and pane_index) above aganist pane_dirs
@@ -714,9 +780,9 @@ def test_throw_error_if_retcode_error(self):
714780
sconfig = kaptan.Kaptan(handler='yaml')
715781
yaml = self.config_script_fails.format(
716782
fixtures_dir=fixtures_dir,
717-
script_failed=os.path.join(fixtures_dir,'script_failed.sh')
783+
script_failed=os.path.join(fixtures_dir, 'script_failed.sh')
718784
)
719-
print(fixtures_dir)
785+
720786
sconfig = sconfig.import_config(yaml).get()
721787
sconfig = config.expand(sconfig)
722788
sconfig = config.trickle(sconfig)
@@ -740,7 +806,7 @@ def test_throw_error_if_file_not_exists(self):
740806
sconfig = kaptan.Kaptan(handler='yaml')
741807
yaml = self.config_script_not_exists.format(
742808
fixtures_dir=fixtures_dir,
743-
script_not_exists=os.path.join(fixtures_dir,'script_not_exists.sh')
809+
script_not_exists=os.path.join(fixtures_dir, 'script_not_exists.sh')
744810
)
745811
sconfig = sconfig.import_config(yaml).get()
746812
sconfig = config.expand(sconfig)
@@ -763,13 +829,12 @@ def test_throw_error_if_file_not_exists(self):
763829
msg="Kills session if before_script doesn't exist"
764830
)
765831

766-
767832
def test_true_if_test_passes(self):
768-
assert(os.path.exists(os.path.join(fixtures_dir,'script_complete.sh')))
833+
assert(os.path.exists(os.path.join(fixtures_dir, 'script_complete.sh')))
769834
sconfig = kaptan.Kaptan(handler='yaml')
770835
yaml = self.config_script_completes.format(
771836
fixtures_dir=fixtures_dir,
772-
script_complete=os.path.join(fixtures_dir,'script_complete.sh')
837+
script_complete=os.path.join(fixtures_dir, 'script_complete.sh')
773838
)
774839

775840
sconfig = sconfig.import_config(yaml).get()

0 commit comments

Comments
 (0)