28
28
spec = ['vdisplay_num' , 'start' , 'stop' ], vdisplay_num = 2010 )
29
29
30
30
31
- @pytest .mark .parametrize ('disp_var ' , [':0 ' , 'localhost:0 ' , 'localhost:0 .1' ])
32
- def test_display_parse (monkeypatch , disp_var ):
31
+ @pytest .mark .parametrize ('dispvar ' , [':12 ' , 'localhost:12 ' , 'localhost:12 .1' ])
32
+ def test_display_parse (monkeypatch , dispvar ):
33
33
"""Check that when $DISPLAY is defined, the display is correctly parsed"""
34
34
config ._display = None
35
- dispstr = ':0'
36
- old_disp = os .getenv ('DISPLAY' )
37
- os .environ ['DISPLAY' ] = disp_var
38
- assert config .get_display () == dispstr
35
+ config ._config .remove_option ('execution' , 'display_variable' )
36
+ monkeypatch .setenv ('DISPLAY' , dispvar )
37
+ assert config .get_display () == ':12'
39
38
# Test that it was correctly cached
40
- assert config .get_display () == dispstr
41
- if old_disp is not None :
42
- os .environ ['DISPLAY' ] = old_disp
43
- else :
44
- del os .environ ['DISPLAY' ]
39
+ assert config .get_display () == ':12'
45
40
46
41
47
42
@pytest .mark .parametrize ('dispnum' , range (5 ))
@@ -88,10 +83,17 @@ def test_display_noconfig_nosystem_patched(monkeypatch):
88
83
config ._config .remove_option ('execution' , 'display_variable' )
89
84
monkeypatch .delitem (os .environ , 'DISPLAY' , raising = False )
90
85
monkeypatch .setitem (sys .modules , 'xvfbwrapper' , xvfbpatch )
86
+ monkeypatch .setattr (sys , 'platform' , value = 'linux' )
91
87
assert config .get_display () == ":2010"
92
88
# Test that it was correctly cached
93
89
assert config .get_display () == ':2010'
94
90
91
+ # Check that raises in Mac
92
+ config ._display = None
93
+ monkeypatch .setattr (sys , 'platform' , value = 'darwin' )
94
+ with pytest .raises (RuntimeError ):
95
+ config .get_display ()
96
+
95
97
96
98
def test_display_empty_patched (monkeypatch ):
97
99
"""
@@ -103,10 +105,16 @@ def test_display_empty_patched(monkeypatch):
103
105
config ._config .remove_option ('execution' , 'display_variable' )
104
106
monkeypatch .setenv ('DISPLAY' , '' )
105
107
monkeypatch .setitem (sys .modules , 'xvfbwrapper' , xvfbpatch )
108
+ monkeypatch .setattr (sys , 'platform' , value = 'linux' )
106
109
assert config .get_display () == ':2010'
107
110
# Test that it was correctly cached
108
111
assert config .get_display () == ':2010'
109
112
113
+ # Check that raises in Mac
114
+ config ._display = None
115
+ monkeypatch .setattr (sys , 'platform' , value = 'darwin' )
116
+ with pytest .raises (RuntimeError ):
117
+ config .get_display ()
110
118
111
119
def test_display_noconfig_nosystem_patched_oldxvfbwrapper (monkeypatch ):
112
120
"""
@@ -118,10 +126,16 @@ def test_display_noconfig_nosystem_patched_oldxvfbwrapper(monkeypatch):
118
126
config ._config .remove_option ('execution' , 'display_variable' )
119
127
monkeypatch .delitem (os .environ , 'DISPLAY' , raising = False )
120
128
monkeypatch .setitem (sys .modules , 'xvfbwrapper' , xvfbpatch_old )
129
+ monkeypatch .setattr (sys , 'platform' , value = 'linux' )
121
130
assert config .get_display () == ":2010"
122
131
# Test that it was correctly cached
123
132
assert config .get_display () == ':2010'
124
133
134
+ # Check that raises in Mac
135
+ config ._display = None
136
+ monkeypatch .setattr (sys , 'platform' , value = 'darwin' )
137
+ with pytest .raises (RuntimeError ):
138
+ config .get_display ()
125
139
126
140
def test_display_empty_patched_oldxvfbwrapper (monkeypatch ):
127
141
"""
@@ -133,10 +147,16 @@ def test_display_empty_patched_oldxvfbwrapper(monkeypatch):
133
147
config ._config .remove_option ('execution' , 'display_variable' )
134
148
monkeypatch .setenv ('DISPLAY' , '' )
135
149
monkeypatch .setitem (sys .modules , 'xvfbwrapper' , xvfbpatch_old )
150
+ monkeypatch .setattr (sys , 'platform' , value = 'linux' )
136
151
assert config .get_display () == ':2010'
137
152
# Test that it was correctly cached
138
153
assert config .get_display () == ':2010'
139
154
155
+ # Check that raises in Mac
156
+ config ._display = None
157
+ monkeypatch .setattr (sys , 'platform' , value = 'darwin' )
158
+ with pytest .raises (RuntimeError ):
159
+ config .get_display ()
140
160
141
161
def test_display_noconfig_nosystem_notinstalled (monkeypatch ):
142
162
"""
@@ -146,7 +166,7 @@ def test_display_noconfig_nosystem_notinstalled(monkeypatch):
146
166
config ._display = None
147
167
if config .has_option ('execution' , 'display_variable' ):
148
168
config ._config .remove_option ('execution' , 'display_variable' )
149
- monkeypatch .delitem ( os . environ , 'DISPLAY' , raising = False )
169
+ monkeypatch .delenv ( 'DISPLAY' , raising = False )
150
170
monkeypatch .setitem (sys .modules , 'xvfbwrapper' , None )
151
171
with pytest .raises (RuntimeError ):
152
172
config .get_display ()
@@ -167,6 +187,7 @@ def test_display_empty_notinstalled(monkeypatch):
167
187
168
188
169
189
@pytest .mark .skipif (not has_Xvfb , reason = 'xvfbwrapper not installed' )
190
+ @pytest .mark .skipif ('darwin' in sys .platform , reason = 'macosx requires root for Xvfb' )
170
191
def test_display_noconfig_nosystem_installed (monkeypatch ):
171
192
"""
172
193
Check that actually uses xvfbwrapper when installed (not mocked)
@@ -175,14 +196,15 @@ def test_display_noconfig_nosystem_installed(monkeypatch):
175
196
config ._display = None
176
197
if config .has_option ('execution' , 'display_variable' ):
177
198
config ._config .remove_option ('execution' , 'display_variable' )
178
- monkeypatch .delitem ( os . environ , 'DISPLAY' , raising = False )
199
+ monkeypatch .delenv ( 'DISPLAY' , raising = False )
179
200
newdisp = config .get_display ()
180
201
assert int (newdisp .split (':' )[- 1 ]) > 1000
181
202
# Test that it was correctly cached
182
203
assert config .get_display () == newdisp
183
204
184
205
185
206
@pytest .mark .skipif (not has_Xvfb , reason = 'xvfbwrapper not installed' )
207
+ @pytest .mark .skipif ('darwin' in sys .platform , reason = 'macosx requires root for Xvfb' )
186
208
def test_display_empty_installed (monkeypatch ):
187
209
"""
188
210
Check that actually uses xvfbwrapper when installed (not mocked)
@@ -207,7 +229,7 @@ def test_display_empty_macosx(monkeypatch):
207
229
config ._display = None
208
230
if config .has_option ('execution' , 'display_variable' ):
209
231
config ._config .remove_option ('execution' , 'display_variable' )
210
- monkeypatch .delitem ( os . environ , 'DISPLAY' , '' )
232
+ monkeypatch .delenv ( 'DISPLAY' , '' )
211
233
212
234
monkeypatch .setattr (sys , 'platform' , 'darwin' )
213
235
with pytest .raises (RuntimeError ):
0 commit comments