1414import sys
1515import logging
1616import unittest
17+ import tempfile
1718import time
1819
1920import kaptan
@@ -376,6 +377,7 @@ class StartDirectoryTest(TmuxTestCase):
376377 - window_name: supposed to be /usr/bin
377378 start_directory: '/usr/bin'
378379 layout: main-horizontal
380+ window_index: 1
379381 options:
380382 main-pane-height: 50
381383 panes:
@@ -386,6 +388,7 @@ class StartDirectoryTest(TmuxTestCase):
386388 - window_name: support to be /dev
387389 start_directory: '/dev'
388390 layout: main-horizontal
391+ window_index: 2
389392 panes:
390393 - shell_command:
391394 - pwd
@@ -394,8 +397,9 @@ class StartDirectoryTest(TmuxTestCase):
394397 - shell_command:
395398 - echo "moo"
396399 - window_name: cwd containing a space
397- start_directory: /tmp/foo bar
400+ start_directory: {TEST_DIR}
398401 layout: main-horizontal
402+ window_index: 3
399403 panes:
400404 - shell_command:
401405 - pwd
@@ -405,6 +409,7 @@ class StartDirectoryTest(TmuxTestCase):
405409 - echo "moo"
406410 - window_name: testsa3
407411 layout: main-horizontal
412+ window_index: 4
408413 panes:
409414 - shell_command:
410415 - pwd
@@ -415,6 +420,7 @@ class StartDirectoryTest(TmuxTestCase):
415420 - window_name: cwd relative to config file
416421 layout: main-horizontal
417422 start_directory: ./
423+ window_index: 5
418424 panes:
419425 - shell_command:
420426 - pwd
@@ -426,40 +432,62 @@ 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+ os .getcwd (),
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+ if p .get ('pane_current_path' ) is None :
477+ pass
478+ elif (
479+ path in p .get ('pane_current_path' ) or
480+ p .get ('pane_current_path' ) == path
481+ ):
482+ result = (
483+ path in p .get ('pane_current_path' ) or
484+ p .get ('pane_current_path' ) == path
485+ )
459486 break
460487 time .sleep (.2 )
461488
462- self .assertEqual (p .get ('pane_current_path' ), path )
489+ # handle case with OS X adding /private/ to /tmp/ paths
490+ self .assertTrue (result )
463491
464492
465493class StartDirectoryRelativeTest (TmuxTestCase ):
@@ -481,14 +509,14 @@ class StartDirectoryRelativeTest(TmuxTestCase):
481509 windows:
482510 - window_name: supposed to be /usr/bin
483511 start_directory: '/usr/bin'
484- layout: main-horizontal
485512 options:
486513 main-pane-height: 50
487514 panes:
488515 - shell_command:
489516 - echo "hey"
490517 - shell_command:
491518 - echo "moo"
519+ window_index: 1
492520 - window_name: support to be /dev
493521 start_directory: '/dev'
494522 layout: main-horizontal
@@ -499,8 +527,9 @@ class StartDirectoryRelativeTest(TmuxTestCase):
499527 - echo "hey"
500528 - shell_command:
501529 - echo "moo"
530+ window_index: 2
502531 - window_name: cwd containing a space
503- start_directory: /tmp/foo bar
532+ start_directory: {TEST_DIR}
504533 layout: main-horizontal
505534 panes:
506535 - shell_command:
@@ -509,6 +538,7 @@ class StartDirectoryRelativeTest(TmuxTestCase):
509538 - echo "hey"
510539 - shell_command:
511540 - echo "moo"
541+ window_index: 3
512542 - window_name: testsa3
513543 layout: main-horizontal
514544 panes:
@@ -518,6 +548,7 @@ class StartDirectoryRelativeTest(TmuxTestCase):
518548 - echo "hey"
519549 - shell_command:
520550 - echo "moo3"
551+ window_index: 4
521552 - window_name: cwd relative to config file
522553 layout: main-horizontal
523554 start_directory: ./
@@ -528,48 +559,87 @@ class StartDirectoryRelativeTest(TmuxTestCase):
528559 - echo "hey"
529560 - shell_command:
530561 - echo "moo3"
562+ window_index: 5
531563 """
532564
533565 def setUp (self ):
534566 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' )
567+
568+ self .tempdir = tempfile .gettempdir ()
569+
570+ self .test_dir = os .path .join (self .tempdir , 'foo bar' )
571+ self .config_dir = os .path .join (self .tempdir , 'testRelConfigDir' )
572+
573+ if (
574+ not os .path .exists (self .test_dir ) or
575+ not os .path .exists (self .config_dir )
576+ ):
577+ os .mkdir (self .test_dir )
578+ os .mkdir (self .config_dir )
538579 self ._temp_dir_created = True
539580 else :
540581 self ._temp_dir_created = False
541582
583+ assert (os .path .exists (self .config_dir ))
584+ assert (os .path .exists (self .test_dir ))
585+
542586 def tearDown (self ):
543587 super (StartDirectoryRelativeTest , self ).tearDown ()
544588 if self ._temp_dir_created :
545- os .rmdir ('/tmp/foo bar' )
546- os .rmdir ('/tmp/testRelConfigDir' )
589+ os .rmdir (self . test_dir )
590+ os .rmdir (self . config_dir )
547591
548592 def test_start_directory (self ):
549593
594+ test_config = self .yaml_config .format (
595+ TEST_DIR = self .test_dir ,
596+ )
597+
550598 start_directory = os .getcwd ()
551599
552600 sconfig = kaptan .Kaptan (handler = 'yaml' )
553- sconfig = sconfig .import_config (self . yaml_config ).get ()
601+ sconfig = sconfig .import_config (test_config ).get ()
554602 # the second argument of os.getcwd() mimics the behavior
555603 # the CLI loader will do, but it passes in the config file's location.
556- sconfig = config .expand (sconfig , '/tmp/testRelConfigDir' )
604+ sconfig = config .expand (sconfig , self .config_dir )
605+
557606 sconfig = config .trickle (sconfig )
558607
608+ assert (os .path .exists (self .config_dir ))
609+ assert (os .path .exists (self .test_dir ))
559610 builder = WorkspaceBuilder (sconf = sconfig )
560611 builder .build (session = self .session )
561612
562613 assert (self .session == builder .session )
563- dirs = ['/usr/bin' , '/dev' , '/tmp/foo bar' , '/tmp/testRelConfigDir' ]
614+
615+ dirs = [
616+ '/usr/bin' , '/dev' ,
617+ self .test_dir ,
618+ os .getcwd (),
619+ self .config_dir ,
620+ ]
621+
564622 for path , window in zip (dirs , self .session .windows ):
565623 for p in window .panes :
566- for i in range (60 ):
624+ for i in range (10 ):
567625 p .server ._update_panes ()
568- if p .get ('pane_current_path' ) == path :
626+ # Handle case where directories resolve to /private/ in OSX
627+ pane_path = p .get ('pane_current_path' )
628+ if pane_path is None :
629+ pass
630+ elif (
631+ path in pane_path or
632+ pane_path == path
633+ ):
634+ result = (
635+ path == pane_path or
636+ path in pane_path
637+ )
638+
569639 break
570640 time .sleep (.2 )
571641
572- self .assertEqual ( p . get ( 'pane_current_path' ), path )
642+ self .assertTrue ( result )
573643
574644
575645class PaneOrderingTest (TmuxTestCase ):
0 commit comments