From fbd86838604530b426d8744a630cc23e725ad0fb Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Mon, 6 Feb 2023 00:05:09 -0500 Subject: [PATCH 1/4] Add a context manager format --- sbvirtualdisplay/abstractdisplay.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sbvirtualdisplay/abstractdisplay.py b/sbvirtualdisplay/abstractdisplay.py index 4fb1727..86fbc07 100644 --- a/sbvirtualdisplay/abstractdisplay.py +++ b/sbvirtualdisplay/abstractdisplay.py @@ -95,6 +95,15 @@ def stop(self): self._clear_xauth() return self + def __enter__(self): + """Used by the :keyword:`with` statement""" + self.start() + return self + + def __exit__(self, *exc_info): + """Used by the :keyword:`with` statement""" + self.stop() + def _setup_xauth(self): """Set up the Xauthority file & the XAUTHORITY environment variable.""" handle, filename = tempfile.mkstemp( From 1853afa480020f2ce1da6e33619302d43ba61b4d Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Mon, 6 Feb 2023 00:05:21 -0500 Subject: [PATCH 2/4] Update the ReadMe --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index b5dccbf..d2d7277 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,14 @@ display.start() display.stop() ``` +### Or as a context manager: + +```python +with Display(visible=0, size=(1440, 1880)): + # Run browser tests in a headless environment + ... +``` + ## When to use: If you need to run browser tests on a headless machine (such as a Linux backend), and you can't use a browser's headless mode (such as Chrome's headless mode), then this may help. For example, Chrome does not allow extensions in headless mode, so if you need to run automated tests on a headless Linux machine and you need to use Chrome extensions, then this will let you run those tests using a virtual display. From 0f2f92dcb90095e8575a16778e12f5c5f1db7fe3 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Mon, 6 Feb 2023 00:05:57 -0500 Subject: [PATCH 3/4] Version 1.2.0 --- sbvirtualdisplay/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbvirtualdisplay/__version__.py b/sbvirtualdisplay/__version__.py index b38d951..0829a2b 100755 --- a/sbvirtualdisplay/__version__.py +++ b/sbvirtualdisplay/__version__.py @@ -1,2 +1,2 @@ # sbvirtualdisplay package -__version__ = "1.1.1" +__version__ = "1.2.0" From 3e5de782a7501d7e91f8bfc42587039f98426f39 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Mon, 6 Feb 2023 00:10:50 -0500 Subject: [PATCH 4/4] Update the ReadMe (Use spaces. Not tabs.) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d2d7277..8280397 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ display.stop() ```python with Display(visible=0, size=(1440, 1880)): - # Run browser tests in a headless environment + # Run browser tests in a headless environment ... ```