lint fixes
This commit is contained in:
parent
4d726abc8e
commit
8662a5f1fa
|
@ -1,3 +1,3 @@
|
||||||
from xvfbwrapper import *
|
from xvfbwrapper import *
|
||||||
|
|
||||||
__version__ = '0.1.1'
|
__version__ = '0.1.2'
|
||||||
|
|
|
@ -9,7 +9,7 @@ import unittest
|
||||||
class TestHomepages(unittest.TestCase):
|
class TestHomepages(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.vdisplay = Xvfb(width=1280, height=720)
|
self.vdisplay = Xvfb(width=800, height=600)
|
||||||
self.vdisplay.start()
|
self.vdisplay.start()
|
||||||
self.browser = webdriver.Firefox()
|
self.browser = webdriver.Firefox()
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
#
|
#
|
||||||
|
# * Corey Goldberg, 2012
|
||||||
#
|
#
|
||||||
# - inspired by PyVirtualDisplay: http://pypi.python.org/pypi/PyVirtualDisplay
|
# * inspired by:
|
||||||
# - Corey Goldberg, 2012
|
# PyVirtualDisplay: http://pypi.python.org/pypi/PyVirtualDisplay
|
||||||
|
|
||||||
|
|
||||||
"""wrapper for running display inside X virtual framebuffer (Xvfb)"""
|
"""wrapper for running display inside X virtual framebuffer (Xvfb)"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import random
|
import random
|
||||||
|
@ -16,7 +16,6 @@ import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Xvfb(object):
|
class Xvfb(object):
|
||||||
|
|
||||||
def __init__(self, width=800, height=680, colordepth=24):
|
def __init__(self, width=800, height=680, colordepth=24):
|
||||||
|
@ -26,8 +25,8 @@ class Xvfb(object):
|
||||||
|
|
||||||
self.xvfb_proc = None
|
self.xvfb_proc = None
|
||||||
self.old_display_num = \
|
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):
|
def start(self):
|
||||||
self.vdisplay_num = self.search_for_free_display()
|
self.vdisplay_num = self.search_for_free_display()
|
||||||
|
@ -46,7 +45,6 @@ class Xvfb(object):
|
||||||
time.sleep(0.1) # give Xvfb time to start
|
time.sleep(0.1) # give Xvfb time to start
|
||||||
self._redirect_display(self.vdisplay_num)
|
self._redirect_display(self.vdisplay_num)
|
||||||
|
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self._redirect_display(self.old_display_num)
|
self._redirect_display(self.old_display_num)
|
||||||
if self.xvfb_proc is not None:
|
if self.xvfb_proc is not None:
|
||||||
|
@ -54,9 +52,8 @@ class Xvfb(object):
|
||||||
self.xvfb_proc.wait()
|
self.xvfb_proc.wait()
|
||||||
self.xvfb_proc = None
|
self.xvfb_proc = None
|
||||||
|
|
||||||
|
|
||||||
def search_for_free_display(self):
|
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
|
min_display_num = 1000
|
||||||
if len(ls):
|
if len(ls):
|
||||||
display_num = max(min_display_num, max(ls) + 1)
|
display_num = max(min_display_num, max(ls) + 1)
|
||||||
|
@ -66,7 +63,6 @@ class Xvfb(object):
|
||||||
display_num += random.randint(0, 100)
|
display_num += random.randint(0, 100)
|
||||||
return display_num
|
return display_num
|
||||||
|
|
||||||
|
|
||||||
def _lock_files(self):
|
def _lock_files(self):
|
||||||
tmpdir = '/tmp'
|
tmpdir = '/tmp'
|
||||||
pattern = '.X*-lock'
|
pattern = '.X*-lock'
|
||||||
|
@ -75,6 +71,5 @@ class Xvfb(object):
|
||||||
ls = [p for p in ls if os.path.isfile(p)]
|
ls = [p for p in ls if os.path.isfile(p)]
|
||||||
return ls
|
return ls
|
||||||
|
|
||||||
|
|
||||||
def _redirect_display(self, display_num):
|
def _redirect_display(self, display_num):
|
||||||
os.environ['DISPLAY'] = ':%s' % display_num
|
os.environ['DISPLAY'] = ':%s' % display_num
|
||||||
|
|
Loading…
Reference in New Issue