From 8662a5f1faca7d2c6b5f67249a6431c562519e31 Mon Sep 17 00:00:00 2001 From: Corey Goldberg Date: Sun, 2 Dec 2012 13:15:17 -0500 Subject: [PATCH] lint fixes --- xvfbwrapper/__init__.py | 2 +- xvfbwrapper/test_xvfb_selenium.py | 4 ++-- xvfbwrapper/xvfbwrapper.py | 29 ++++++++++++----------------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/xvfbwrapper/__init__.py b/xvfbwrapper/__init__.py index 09525bd..5367092 100644 --- a/xvfbwrapper/__init__.py +++ b/xvfbwrapper/__init__.py @@ -1,3 +1,3 @@ from xvfbwrapper import * -__version__ = '0.1.1' +__version__ = '0.1.2' diff --git a/xvfbwrapper/test_xvfb_selenium.py b/xvfbwrapper/test_xvfb_selenium.py index 5417a21..423725f 100644 --- a/xvfbwrapper/test_xvfb_selenium.py +++ b/xvfbwrapper/test_xvfb_selenium.py @@ -7,9 +7,9 @@ import unittest class TestHomepages(unittest.TestCase): - + def setUp(self): - self.vdisplay = Xvfb(width=1280, height=720) + self.vdisplay = Xvfb(width=800, height=600) self.vdisplay.start() self.browser = webdriver.Firefox() diff --git a/xvfbwrapper/xvfbwrapper.py b/xvfbwrapper/xvfbwrapper.py index c157aa6..909d9af 100644 --- a/xvfbwrapper/xvfbwrapper.py +++ b/xvfbwrapper/xvfbwrapper.py @@ -1,14 +1,14 @@ #!/usr/bin/env python # +# * Corey Goldberg, 2012 # -# - inspired by PyVirtualDisplay: http://pypi.python.org/pypi/PyVirtualDisplay -# - Corey Goldberg, 2012 +# * inspired by: +# PyVirtualDisplay: http://pypi.python.org/pypi/PyVirtualDisplay """wrapper for running display inside X virtual framebuffer (Xvfb)""" - import os import fnmatch import random @@ -16,23 +16,22 @@ import subprocess import time - class Xvfb(object): - + def __init__(self, width=800, height=680, colordepth=24): self.width = width self.height = height self.colordepth = colordepth - + self.xvfb_proc = None self.old_display_num = \ - os.environ['DISPLAY'].split(':')[1] if 'DISPLAY' in os.environ else 0 - + os.environ['DISPLAY'].split(':')[1] \ + if 'DISPLAY' in os.environ else 0 def start(self): self.vdisplay_num = self.search_for_free_display() self.xvfb_cmd = 'Xvfb :{0} -screen 0 {1}x{2}x{3} 2>&1 >{4}'.format( - self.vdisplay_num, + self.vdisplay_num, self.width, self.height, self.colordepth, @@ -45,8 +44,7 @@ class Xvfb(object): ) time.sleep(0.1) # give Xvfb time to start self._redirect_display(self.vdisplay_num) - - + def stop(self): self._redirect_display(self.old_display_num) if self.xvfb_proc is not None: @@ -54,19 +52,17 @@ class Xvfb(object): self.xvfb_proc.wait() self.xvfb_proc = None - def search_for_free_display(self): - ls = map(lambda x:int(x.split('X')[1].split('-')[0]), self._lock_files()) + ls = [int(x.split('X')[1].split('-')[0]) for x in self._lock_files()] min_display_num = 1000 if len(ls): display_num = max(min_display_num, max(ls) + 1) else: display_num = min_display_num random.seed() - display_num += random.randint(0, 100) + display_num += random.randint(0, 100) return display_num - - + def _lock_files(self): tmpdir = '/tmp' pattern = '.X*-lock' @@ -74,7 +70,6 @@ class Xvfb(object): ls = [os.path.join(tmpdir, child) for child in names] ls = [p for p in ls if os.path.isfile(p)] return ls - def _redirect_display(self, display_num): os.environ['DISPLAY'] = ':%s' % display_num