53
59
class DisplayFixture(Fixture):
54
"""Fixture to create a virtual display with pyvirtualdisplay.Display."""
56
logger_names = ['easyprocess', 'pyvirtualdisplay']
58
def __init__(self, visible=False, size=(1280, 1024)):
60
"""Fixture to create a virtual display with `xvfb-run`.
62
This will set the ``DISPLAY`` environment variable once it's up and
63
running (and reset it when it shuts down).
66
def __init__(self, size=(1280, 1024), depth=24):
59
67
super(DisplayFixture, self).__init__()
60
self.visible = visible
68
self.width, self.height = size
73
"""The command this fixture will start.
75
``xvfb-run`` is the executable used, to which the following arguments
79
``-ac`` disables host-based access control mechanisms. See
81
``-screen`` forces a screen configuration. At the time of writing
82
there is some disagreement between xvfb-run(1) and Xvfb(1)
83
about what the default is.
86
Try to get a free server number, starting at 99. See xvfb-run(1).
88
``xvfb-run`` is asked to chain to ``bash``, which echos the
89
``DISPLAY`` environment variable and execs ``cat``. This lets us shut
90
down the framebuffer simply by closing the process's stdin.
92
spec = "{self.width}x{self.height}x{self.depth}".format(self=self)
93
args = "-ac -screen 0 %s" % spec
95
"xvfb-run", "--server-args", args, "--auto-servernum", "--",
96
"bash", "-c", "echo $DISPLAY && exec cat",
64
100
super(DisplayFixture, self).setUp()
65
self.useFixture(LoggerSilencerFixture(self.logger_names))
66
self.display = Display(
67
visible=self.visible, size=self.size)
69
self.addCleanup(self.display.stop)
101
self.process = Popen(self.command, stdin=PIPE, stdout=PIPE)
102
self.display = self.process.stdout.readline().strip()
103
if not self.display or self.process.poll() is not None:
104
raise CalledProcessError(self.process.returncode, self.command)
105
self.useFixture(EnvironmentVariableFixture("DISPLAY", self.display))
106
self.addCleanup(self.shutdown)
109
self.process.stdin.close()
110
if self.process.wait() != 0:
111
raise CalledProcessError(self.process.returncode, self.command)
72
114
class SSTFixture(Fixture):
91
133
super(ProxiesDisabledFixture, self).setUp()
92
134
self.useFixture(EnvironmentVariableFixture("http_proxy"))
93
135
self.useFixture(EnvironmentVariableFixture("https_proxy"))
138
class TempWDFixture(TempDir):
139
"""Change the current working directory into a temp dir.
141
This will restore the original WD and delete the temp directory on cleanup.
146
super(TempWDFixture, self).setUp()
147
self.addCleanup(os.chdir, cwd)