lint fixes

This commit is contained in:
Corey Goldberg 2012-12-02 13:15:17 -05:00
parent 4d726abc8e
commit 8662a5f1fa
3 changed files with 15 additions and 20 deletions

View File

@ -1,3 +1,3 @@
from xvfbwrapper import *
__version__ = '0.1.1'
__version__ = '0.1.2'

View File

@ -9,7 +9,7 @@ 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()

View File

@ -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,7 +16,6 @@ import subprocess
import time
class Xvfb(object):
def __init__(self, width=800, height=680, colordepth=24):
@ -26,8 +25,8 @@ class Xvfb(object):
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()
@ -46,7 +45,6 @@ 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,9 +52,8 @@ 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)
@ -66,7 +63,6 @@ class Xvfb(object):
display_num += random.randint(0, 100)
return display_num
def _lock_files(self):
tmpdir = '/tmp'
pattern = '.X*-lock'
@ -75,6 +71,5 @@ class Xvfb(object):
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