3
3
4
4
import os
5
5
import shutil
6
+ import tempfile
6
7
import kaptan
7
8
from .. import config , exc
8
9
from ..util import tmux
@@ -56,11 +57,10 @@ class ImportExportTest(TestCase):
56
57
57
58
@classmethod
58
59
def setUpClass (cls ):
59
- if not os .path .exists (TMUXP_DIR ):
60
- os .makedirs (TMUXP_DIR )
60
+ cls .tmp_dir = tempfile .mkdtemp (suffix = 'tmuxp' )
61
61
62
62
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' )
64
64
65
65
configparser = kaptan .Kaptan ()
66
66
sampleconfig = config .inline (sampleconfigdict )
@@ -76,7 +76,7 @@ def test_export_json(self):
76
76
self .assertDictEqual (sampleconfigdict , new_config_data )
77
77
78
78
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' )
80
80
81
81
configparser = kaptan .Kaptan ()
82
82
sampleconfig = config .inline (sampleconfigdict )
@@ -95,37 +95,37 @@ def test_export_yaml(self):
95
95
def test_scan_config (self ):
96
96
configs = []
97
97
98
- garbage_file = os .path .join (TMUXP_DIR , 'config.psd' )
98
+ garbage_file = os .path .join (self . tmp_dir , 'config.psd' )
99
99
with open (garbage_file , 'w' ) as buf :
100
100
buf .write ('wat' )
101
101
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 ):
104
104
for filela in (x for x in f if x .endswith (('.json' , '.ini' , 'yaml' ))):
105
105
configs .append (os .path .join (
106
- TMUXP_DIR , filela ))
106
+ self . tmp_dir , filela ))
107
107
108
108
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' )):
110
110
files += 1
111
111
self .assertIn (os .path .join (
112
- TMUXP_DIR , 'config.json' ), configs )
112
+ self . tmp_dir , 'config.json' ), configs )
113
113
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' )):
115
115
files += 1
116
116
self .assertIn (os .path .join (
117
- TMUXP_DIR , 'config.yaml' ), configs )
117
+ self . tmp_dir , 'config.yaml' ), configs )
118
118
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' )):
120
120
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 )
122
122
123
123
self .assertEqual (len (configs ), files )
124
124
125
125
@classmethod
126
126
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 )
129
129
logging .debug ('wiped %s' % TMUXP_DIR )
130
130
131
131
0 commit comments