14
14
import sys
15
15
import logging
16
16
import unittest
17
+ import tempfile
17
18
import time
18
19
19
20
import kaptan
@@ -187,12 +188,12 @@ def test_focus_pane_index(self):
187
188
self .assertNotEqual (w .get ('window_name' ), 'man' )
188
189
189
190
pane_path = '/usr'
190
- for i in range (60 ):
191
+ for i in range (10 ):
191
192
p = w .attached_pane ()
192
193
p .server ._update_panes ()
193
194
if p .get ('pane_current_path' ) == pane_path :
194
195
break
195
- time .sleep (.2 )
196
+ time .sleep (.4 )
196
197
197
198
self .assertEqual (p .get ('pane_current_path' ), pane_path )
198
199
@@ -205,12 +206,12 @@ def test_focus_pane_index(self):
205
206
206
207
p = None
207
208
pane_path = '/'
208
- for i in range (60 ):
209
+ for i in range (10 ):
209
210
p = window3 .attached_pane ()
210
211
p .server ._update_panes ()
211
212
if p .get ('pane_current_path' ) == pane_path :
212
213
break
213
- time .sleep (.2 )
214
+ time .sleep (.4 )
214
215
215
216
self .assertEqual (p .get ('pane_current_path' ), pane_path )
216
217
@@ -307,31 +308,31 @@ def test_automatic_rename_option(self):
307
308
if 'BSD' in platform .system ():
308
309
man_window_name = 'less'
309
310
310
- for i in range (60 ):
311
+ for i in range (10 ):
311
312
self .session .server ._update_windows ()
312
313
if w .get ('window_name' ) != man_window_name :
313
314
break
314
- time .sleep (.1 )
315
+ time .sleep (.2 )
315
316
316
317
self .assertNotEqual (w .get ('window_name' ), man_window_name )
317
318
318
319
pane_base_index = w .show_window_option ('pane-base-index' , g = True )
319
320
w .select_pane (pane_base_index )
320
321
321
- for i in range (60 ):
322
+ for i in range (10 ):
322
323
self .session .server ._update_windows ()
323
324
if w .get ('window_name' ) == man_window_name :
324
325
break
325
- time .sleep (.1 )
326
+ time .sleep (.2 )
326
327
327
328
self .assertEqual (w .get ('window_name' ), text_type (man_window_name ))
328
329
329
330
w .select_pane ('-D' )
330
- for i in range (60 ):
331
+ for i in range (10 ):
331
332
self .session .server ._update_windows ()
332
333
if w ['window_name' ] != man_window_name :
333
334
break
334
- time .sleep (.1 )
335
+ time .sleep (.2 )
335
336
336
337
self .assertNotEqual (w .get ('window_name' ), text_type (man_window_name ))
337
338
@@ -374,7 +375,8 @@ class StartDirectoryTest(TmuxTestCase):
374
375
start_directory: '/usr'
375
376
windows:
376
377
- window_name: supposed to be /usr/bin
377
- start_directory: '/usr/bin'
378
+ window_index: 1
379
+ start_directory: /usr/bin
378
380
layout: main-horizontal
379
381
options:
380
382
main-pane-height: 50
@@ -384,7 +386,8 @@ class StartDirectoryTest(TmuxTestCase):
384
386
- shell_command:
385
387
- echo "moo"
386
388
- window_name: support to be /dev
387
- start_directory: '/dev'
389
+ window_index: 2
390
+ start_directory: /dev
388
391
layout: main-horizontal
389
392
panes:
390
393
- shell_command:
@@ -394,7 +397,8 @@ class StartDirectoryTest(TmuxTestCase):
394
397
- shell_command:
395
398
- echo "moo"
396
399
- window_name: cwd containing a space
397
- start_directory: /tmp/foo bar
400
+ window_index: 3
401
+ start_directory: {TEST_DIR}
398
402
layout: main-horizontal
399
403
panes:
400
404
- shell_command:
@@ -404,6 +408,7 @@ class StartDirectoryTest(TmuxTestCase):
404
408
- shell_command:
405
409
- echo "moo"
406
410
- window_name: testsa3
411
+ window_index: 4
407
412
layout: main-horizontal
408
413
panes:
409
414
- shell_command:
@@ -412,7 +417,8 @@ class StartDirectoryTest(TmuxTestCase):
412
417
- echo "hey"
413
418
- shell_command:
414
419
- 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
416
422
layout: main-horizontal
417
423
start_directory: ./
418
424
panes:
@@ -426,40 +432,63 @@ class StartDirectoryTest(TmuxTestCase):
426
432
427
433
def setUp (self ):
428
434
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 )
431
441
self ._temp_dir_created = True
432
442
else :
433
443
self ._temp_dir_created = False
434
444
435
445
def tearDown (self ):
436
446
super (StartDirectoryTest , self ).tearDown ()
437
447
if self ._temp_dir_created :
438
- os .rmdir ('/tmp/foo bar' )
448
+ os .rmdir (self . test_dir )
439
449
440
450
def test_start_directory (self ):
441
451
442
- start_directory = os .getcwd ()
452
+ test_config = self .yaml_config .format (
453
+ TMP_DIR = self .tempdir ,
454
+ TEST_DIR = self .test_dir
455
+ )
443
456
444
457
sconfig = kaptan .Kaptan (handler = 'yaml' )
445
- sconfig = sconfig .import_config (self . yaml_config ).get ()
458
+ sconfig = sconfig .import_config (test_config ).get ()
446
459
sconfig = config .expand (sconfig )
447
460
sconfig = config .trickle (sconfig )
448
461
449
462
builder = WorkspaceBuilder (sconf = sconfig )
450
463
builder .build (session = self .session )
451
464
452
465
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
+
454
472
for path , window in zip (dirs , self .session .windows ):
455
473
for p in window .panes :
456
474
for i in range (60 ):
457
475
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
+ )
459
487
break
460
488
time .sleep (.2 )
461
489
462
- self .assertEqual (p .get ('pane_current_path' ), path )
490
+ # handle case with OS X adding /private/ to /tmp/ paths
491
+ self .assertTrue (result )
463
492
464
493
465
494
class StartDirectoryRelativeTest (TmuxTestCase ):
@@ -481,7 +510,6 @@ class StartDirectoryRelativeTest(TmuxTestCase):
481
510
windows:
482
511
- window_name: supposed to be /usr/bin
483
512
start_directory: '/usr/bin'
484
- layout: main-horizontal
485
513
options:
486
514
main-pane-height: 50
487
515
panes:
@@ -500,7 +528,7 @@ class StartDirectoryRelativeTest(TmuxTestCase):
500
528
- shell_command:
501
529
- echo "moo"
502
530
- window_name: cwd containing a space
503
- start_directory: /tmp/foo bar
531
+ start_directory: {TEST_DIR}
504
532
layout: main-horizontal
505
533
panes:
506
534
- shell_command:
@@ -509,7 +537,7 @@ class StartDirectoryRelativeTest(TmuxTestCase):
509
537
- echo "hey"
510
538
- shell_command:
511
539
- echo "moo"
512
- - window_name: testsa3
540
+ - window_name: inherit start_directory which is rel to config file
513
541
layout: main-horizontal
514
542
panes:
515
543
- shell_command:
@@ -532,44 +560,83 @@ class StartDirectoryRelativeTest(TmuxTestCase):
532
560
533
561
def setUp (self ):
534
562
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 )
538
575
self ._temp_dir_created = True
539
576
else :
540
577
self ._temp_dir_created = False
541
578
579
+ assert (os .path .exists (self .config_dir ))
580
+ assert (os .path .exists (self .test_dir ))
581
+
542
582
def tearDown (self ):
543
583
super (StartDirectoryRelativeTest , self ).tearDown ()
544
584
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 )
547
587
548
588
def test_start_directory (self ):
549
589
590
+ test_config = self .yaml_config .format (
591
+ TEST_DIR = self .test_dir ,
592
+ )
593
+
550
594
start_directory = os .getcwd ()
551
595
552
596
sconfig = kaptan .Kaptan (handler = 'yaml' )
553
- sconfig = sconfig .import_config (self . yaml_config ).get ()
597
+ sconfig = sconfig .import_config (test_config ).get ()
554
598
# the second argument of os.getcwd() mimics the behavior
555
599
# 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
+
557
602
sconfig = config .trickle (sconfig )
558
603
604
+ assert (os .path .exists (self .config_dir ))
605
+ assert (os .path .exists (self .test_dir ))
559
606
builder = WorkspaceBuilder (sconf = sconfig )
560
607
builder .build (session = self .session )
561
608
562
609
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
+
564
619
for path , window in zip (dirs , self .session .windows ):
565
620
for p in window .panes :
566
621
for i in range (60 ):
567
622
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
+
569
636
break
570
637
time .sleep (.2 )
571
638
572
- self .assertEqual ( p . get ( 'pane_current_path' ), path )
639
+ self .assertTrue ( result )
573
640
574
641
575
642
class PaneOrderingTest (TmuxTestCase ):
@@ -596,7 +663,6 @@ class PaneOrderingTest(TmuxTestCase):
596
663
HOME = os .path .realpath (os .path .expanduser ('~' ))
597
664
)
598
665
599
-
600
666
def test_pane_order (self ):
601
667
602
668
# test order of `panes` (and pane_index) above aganist pane_dirs
@@ -714,9 +780,9 @@ def test_throw_error_if_retcode_error(self):
714
780
sconfig = kaptan .Kaptan (handler = 'yaml' )
715
781
yaml = self .config_script_fails .format (
716
782
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' )
718
784
)
719
- print ( fixtures_dir )
785
+
720
786
sconfig = sconfig .import_config (yaml ).get ()
721
787
sconfig = config .expand (sconfig )
722
788
sconfig = config .trickle (sconfig )
@@ -740,7 +806,7 @@ def test_throw_error_if_file_not_exists(self):
740
806
sconfig = kaptan .Kaptan (handler = 'yaml' )
741
807
yaml = self .config_script_not_exists .format (
742
808
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' )
744
810
)
745
811
sconfig = sconfig .import_config (yaml ).get ()
746
812
sconfig = config .expand (sconfig )
@@ -763,13 +829,12 @@ def test_throw_error_if_file_not_exists(self):
763
829
msg = "Kills session if before_script doesn't exist"
764
830
)
765
831
766
-
767
832
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' )))
769
834
sconfig = kaptan .Kaptan (handler = 'yaml' )
770
835
yaml = self .config_script_completes .format (
771
836
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' )
773
838
)
774
839
775
840
sconfig = sconfig .import_config (yaml ).get ()
0 commit comments