33
44import os
55import shutil
6+ import tempfile
67import kaptan
78from .. import config , exc
89from ..util import tmux
@@ -56,11 +57,10 @@ class ImportExportTest(TestCase):
5657
5758 @classmethod
5859 def setUpClass (cls ):
59- if not os .path .exists (TMUXP_DIR ):
60- os .makedirs (TMUXP_DIR )
60+ cls .tmp_dir = tempfile .mkdtemp (suffix = 'tmuxp' )
6161
6262 def test_export_json (self ):
63- json_config_file = os .path .join (TMUXP_DIR , 'config.json' )
63+ json_config_file = os .path .join (self . tmp_dir , 'config.json' )
6464
6565 configparser = kaptan .Kaptan ()
6666 sampleconfig = config .inline (sampleconfigdict )
@@ -76,7 +76,7 @@ def test_export_json(self):
7676 self .assertDictEqual (sampleconfigdict , new_config_data )
7777
7878 def test_export_yaml (self ):
79- yaml_config_file = os .path .join (TMUXP_DIR , 'config.yaml' )
79+ yaml_config_file = os .path .join (self . tmp_dir , 'config.yaml' )
8080
8181 configparser = kaptan .Kaptan ()
8282 sampleconfig = config .inline (sampleconfigdict )
@@ -95,37 +95,37 @@ def test_export_yaml(self):
9595 def test_scan_config (self ):
9696 configs = []
9797
98- garbage_file = os .path .join (TMUXP_DIR , 'config.psd' )
98+ garbage_file = os .path .join (self . tmp_dir , 'config.psd' )
9999 with open (garbage_file , 'w' ) as buf :
100100 buf .write ('wat' )
101101
102- if os .path .exists (TMUXP_DIR ):
103- for r , d , f in os .walk (TMUXP_DIR ):
102+ if os .path .exists (self . tmp_dir ):
103+ for r , d , f in os .walk (self . tmp_dir ):
104104 for filela in (x for x in f if x .endswith (('.json' , '.ini' , 'yaml' ))):
105105 configs .append (os .path .join (
106- TMUXP_DIR , filela ))
106+ self . tmp_dir , filela ))
107107
108108 files = 0
109- if os .path .exists (os .path .join (TMUXP_DIR , 'config.json' )):
109+ if os .path .exists (os .path .join (self . tmp_dir , 'config.json' )):
110110 files += 1
111111 self .assertIn (os .path .join (
112- TMUXP_DIR , 'config.json' ), configs )
112+ self . tmp_dir , 'config.json' ), configs )
113113
114- if os .path .exists (os .path .join (TMUXP_DIR , 'config.yaml' )):
114+ if os .path .exists (os .path .join (self . tmp_dir , 'config.yaml' )):
115115 files += 1
116116 self .assertIn (os .path .join (
117- TMUXP_DIR , 'config.yaml' ), configs )
117+ self . tmp_dir , 'config.yaml' ), configs )
118118
119- if os .path .exists (os .path .join (TMUXP_DIR , 'config.ini' )):
119+ if os .path .exists (os .path .join (self . tmp_dir , 'config.ini' )):
120120 files += 1
121- self .assertIn (os .path .join (TMUXP_DIR , 'config.ini' ), configs )
121+ self .assertIn (os .path .join (self . tmp_dir , 'config.ini' ), configs )
122122
123123 self .assertEqual (len (configs ), files )
124124
125125 @classmethod
126126 def tearDownClass (cls ):
127- if os .path .isdir (TMUXP_DIR ):
128- shutil .rmtree (TMUXP_DIR )
127+ if os .path .isdir (cls . tmp_dir ):
128+ shutil .rmtree (cls . tmp_dir )
129129 logging .debug ('wiped %s' % TMUXP_DIR )
130130
131131
0 commit comments