28
28
spec = ['vdisplay_num' , 'start' , 'stop' ], vdisplay_num = 2010 )
29
29
30
30
31
+ @pytest .mark .parametrize ('dispvar' , [':12' , 'localhost:12' , 'localhost:12.1' ])
32
+ def test_display_parse (monkeypatch , dispvar ):
33
+ """Check that when $DISPLAY is defined, the display is correctly parsed"""
34
+ config ._display = None
35
+ config ._config .remove_option ('execution' , 'display_variable' )
36
+ monkeypatch .setenv ('DISPLAY' , dispvar )
37
+ assert config .get_display () == ':12'
38
+ # Test that it was correctly cached
39
+ assert config .get_display () == ':12'
40
+
41
+
31
42
@pytest .mark .parametrize ('dispnum' , range (5 ))
32
43
def test_display_config (monkeypatch , dispnum ):
33
44
"""Check that the display_variable option is used ($DISPLAY not set)"""
@@ -46,7 +57,7 @@ def test_display_system(monkeypatch, dispnum):
46
57
config ._display = None
47
58
config ._config .remove_option ('execution' , 'display_variable' )
48
59
dispstr = ':%d' % dispnum
49
- monkeypatch .setitem ( os . environ , 'DISPLAY' , dispstr )
60
+ monkeypatch .setenv ( 'DISPLAY' , dispstr )
50
61
assert config .get_display () == dispstr
51
62
# Test that it was correctly cached
52
63
assert config .get_display () == dispstr
@@ -58,7 +69,7 @@ def test_display_config_and_system(monkeypatch):
58
69
config ._display = None
59
70
dispstr = ':10'
60
71
config .set ('execution' , 'display_variable' , dispstr )
61
- monkeypatch .setitem ( os . environ , 'DISPLAY' , ':0' )
72
+ monkeypatch .setenv ( 'DISPLAY' , ':0' )
62
73
assert config .get_display () == dispstr
63
74
# Test that it was correctly cached
64
75
assert config .get_display () == dispstr
@@ -72,10 +83,17 @@ def test_display_noconfig_nosystem_patched(monkeypatch):
72
83
config ._config .remove_option ('execution' , 'display_variable' )
73
84
monkeypatch .delitem (os .environ , 'DISPLAY' , raising = False )
74
85
monkeypatch .setitem (sys .modules , 'xvfbwrapper' , xvfbpatch )
86
+ monkeypatch .setattr (sys , 'platform' , value = 'linux' )
75
87
assert config .get_display () == ":2010"
76
88
# Test that it was correctly cached
77
89
assert config .get_display () == ':2010'
78
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
+
79
97
80
98
def test_display_empty_patched (monkeypatch ):
81
99
"""
@@ -85,12 +103,18 @@ def test_display_empty_patched(monkeypatch):
85
103
config ._display = None
86
104
if config .has_option ('execution' , 'display_variable' ):
87
105
config ._config .remove_option ('execution' , 'display_variable' )
88
- monkeypatch .setitem ( os . environ , 'DISPLAY' , '' )
106
+ monkeypatch .setenv ( 'DISPLAY' , '' )
89
107
monkeypatch .setitem (sys .modules , 'xvfbwrapper' , xvfbpatch )
108
+ monkeypatch .setattr (sys , 'platform' , value = 'linux' )
90
109
assert config .get_display () == ':2010'
91
110
# Test that it was correctly cached
92
111
assert config .get_display () == ':2010'
93
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 ()
94
118
95
119
def test_display_noconfig_nosystem_patched_oldxvfbwrapper (monkeypatch ):
96
120
"""
@@ -102,10 +126,16 @@ def test_display_noconfig_nosystem_patched_oldxvfbwrapper(monkeypatch):
102
126
config ._config .remove_option ('execution' , 'display_variable' )
103
127
monkeypatch .delitem (os .environ , 'DISPLAY' , raising = False )
104
128
monkeypatch .setitem (sys .modules , 'xvfbwrapper' , xvfbpatch_old )
129
+ monkeypatch .setattr (sys , 'platform' , value = 'linux' )
105
130
assert config .get_display () == ":2010"
106
131
# Test that it was correctly cached
107
132
assert config .get_display () == ':2010'
108
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 ()
109
139
110
140
def test_display_empty_patched_oldxvfbwrapper (monkeypatch ):
111
141
"""
@@ -115,12 +145,18 @@ def test_display_empty_patched_oldxvfbwrapper(monkeypatch):
115
145
config ._display = None
116
146
if config .has_option ('execution' , 'display_variable' ):
117
147
config ._config .remove_option ('execution' , 'display_variable' )
118
- monkeypatch .setitem ( os . environ , 'DISPLAY' , '' )
148
+ monkeypatch .setenv ( 'DISPLAY' , '' )
119
149
monkeypatch .setitem (sys .modules , 'xvfbwrapper' , xvfbpatch_old )
150
+ monkeypatch .setattr (sys , 'platform' , value = 'linux' )
120
151
assert config .get_display () == ':2010'
121
152
# Test that it was correctly cached
122
153
assert config .get_display () == ':2010'
123
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 ()
124
160
125
161
def test_display_noconfig_nosystem_notinstalled (monkeypatch ):
126
162
"""
@@ -130,7 +166,7 @@ def test_display_noconfig_nosystem_notinstalled(monkeypatch):
130
166
config ._display = None
131
167
if config .has_option ('execution' , 'display_variable' ):
132
168
config ._config .remove_option ('execution' , 'display_variable' )
133
- monkeypatch .delitem ( os . environ , 'DISPLAY' , raising = False )
169
+ monkeypatch .delenv ( 'DISPLAY' , raising = False )
134
170
monkeypatch .setitem (sys .modules , 'xvfbwrapper' , None )
135
171
with pytest .raises (RuntimeError ):
136
172
config .get_display ()
@@ -144,13 +180,14 @@ def test_display_empty_notinstalled(monkeypatch):
144
180
config ._display = None
145
181
if config .has_option ('execution' , 'display_variable' ):
146
182
config ._config .remove_option ('execution' , 'display_variable' )
147
- monkeypatch .setitem ( os . environ , 'DISPLAY' , '' )
183
+ monkeypatch .setenv ( 'DISPLAY' , '' )
148
184
monkeypatch .setitem (sys .modules , 'xvfbwrapper' , None )
149
185
with pytest .raises (RuntimeError ):
150
186
config .get_display ()
151
187
152
188
153
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' )
154
191
def test_display_noconfig_nosystem_installed (monkeypatch ):
155
192
"""
156
193
Check that actually uses xvfbwrapper when installed (not mocked)
@@ -159,14 +196,15 @@ def test_display_noconfig_nosystem_installed(monkeypatch):
159
196
config ._display = None
160
197
if config .has_option ('execution' , 'display_variable' ):
161
198
config ._config .remove_option ('execution' , 'display_variable' )
162
- monkeypatch .delitem ( os . environ , 'DISPLAY' , raising = False )
199
+ monkeypatch .delenv ( 'DISPLAY' , raising = False )
163
200
newdisp = config .get_display ()
164
201
assert int (newdisp .split (':' )[- 1 ]) > 1000
165
202
# Test that it was correctly cached
166
203
assert config .get_display () == newdisp
167
204
168
205
169
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' )
170
208
def test_display_empty_installed (monkeypatch ):
171
209
"""
172
210
Check that actually uses xvfbwrapper when installed (not mocked)
@@ -175,7 +213,7 @@ def test_display_empty_installed(monkeypatch):
175
213
config ._display = None
176
214
if config .has_option ('execution' , 'display_variable' ):
177
215
config ._config .remove_option ('execution' , 'display_variable' )
178
- monkeypatch .setitem ( os . environ , 'DISPLAY' , '' )
216
+ monkeypatch .setenv ( 'DISPLAY' , '' )
179
217
newdisp = config .get_display ()
180
218
assert int (newdisp .split (':' )[- 1 ]) > 1000
181
219
# Test that it was correctly cached
@@ -191,7 +229,7 @@ def test_display_empty_macosx(monkeypatch):
191
229
config ._display = None
192
230
if config .has_option ('execution' , 'display_variable' ):
193
231
config ._config .remove_option ('execution' , 'display_variable' )
194
- monkeypatch .delitem ( os . environ , 'DISPLAY' , '' )
232
+ monkeypatch .delenv ( 'DISPLAY' , '' )
195
233
196
234
monkeypatch .setattr (sys , 'platform' , 'darwin' )
197
235
with pytest .raises (RuntimeError ):
0 commit comments