|
15 | 15 | except ImportError:
|
16 | 16 | has_Xvfb = False
|
17 | 17 |
|
18 |
| -xvfbpatch = MagicMock() |
19 |
| -xvfbpatch.Xvfb.return_value = MagicMock(vdisplay_num=2010) |
| 18 | +# Define mocks for xvfbwrapper. Do not forget the spec to ensure that |
| 19 | +# hasattr() checks return False with missing attributes. |
| 20 | +xvfbpatch = MagicMock(spec=['Xvfb']) |
| 21 | +xvfbpatch.Xvfb.return_value = MagicMock(spec=['new_display', 'start', 'stop'], |
| 22 | + new_display=2010) |
| 23 | + |
| 24 | +# Mock the legacy xvfbwrapper.Xvfb class (changed display attribute name) |
| 25 | +xvfbpatch_old = MagicMock(spec=['Xvfb']) |
| 26 | +xvfbpatch_old.Xvfb.return_value = MagicMock(spec=['vdisplay_num', 'start', 'stop'], |
| 27 | + vdisplay_num=2010) |
20 | 28 |
|
21 | 29 |
|
22 | 30 | @pytest.mark.parametrize('dispnum', range(5))
|
@@ -71,6 +79,32 @@ def test_display_empty_patched(monkeypatch):
|
71 | 79 | assert config.get_display() == ':2010'
|
72 | 80 |
|
73 | 81 |
|
| 82 | +def test_display_noconfig_nosystem_patched_oldxvfbwrapper(monkeypatch): |
| 83 | + """ |
| 84 | + Check that when no $DISPLAY nor option are specified, |
| 85 | + a virtual Xvfb is used (with a legacy version of xvfbwrapper). |
| 86 | + """ |
| 87 | + config._display = None |
| 88 | + if config.has_option('execution', 'display_variable'): |
| 89 | + config._config.remove_option('execution', 'display_variable') |
| 90 | + monkeypatch.delitem(os.environ, 'DISPLAY', raising=False) |
| 91 | + monkeypatch.setitem(sys.modules, 'xvfbwrapper', xvfbpatch_old) |
| 92 | + assert config.get_display() == ":2010" |
| 93 | + |
| 94 | + |
| 95 | +def test_display_empty_patched_oldxvfbwrapper(monkeypatch): |
| 96 | + """ |
| 97 | + Check that when $DISPLAY is empty string and no option is specified, |
| 98 | + a virtual Xvfb is used (with a legacy version of xvfbwrapper). |
| 99 | + """ |
| 100 | + config._display = None |
| 101 | + if config.has_option('execution', 'display_variable'): |
| 102 | + config._config.remove_option('execution', 'display_variable') |
| 103 | + monkeypatch.setitem(os.environ, 'DISPLAY', '') |
| 104 | + monkeypatch.setitem(sys.modules, 'xvfbwrapper', xvfbpatch_old) |
| 105 | + assert config.get_display() == ':2010' |
| 106 | + |
| 107 | + |
74 | 108 | def test_display_noconfig_nosystem_notinstalled(monkeypatch):
|
75 | 109 | """
|
76 | 110 | Check that an exception is raised if xvfbwrapper is not installed
|
|
0 commit comments