def from_name(cls, name=None): """ Connect to the display with the given ``name``. ``name`` is a byte or unicode string containing the name of a display (e.g. ``':0'``). If ``name`` is ``None``, the value of ``$DISPLAY`` is used. If ``name`` refers to a non-existing display, or if ``name`` is empty and ``$DISPLAY`` is empty or refers to a non-existing display, the display connection fails, and :exc:`DisplayError` is raised. Return a :class:`Display` object representing the connection to the display. Raise :exc:`DisplayError`, if no display could be opened. """ if name is not None: name = ensure_byte_string(name) return cls(xlib.open_display(name))
def test_open_display(): display = xlib.open_display(None) assert display xlib.close_display(display)
def test_open_display_no_display(): with mock.patch.dict(os.environ, {}, clear=True): assert not xlib.open_display(None)