Browse Source

fixed tests

master
Corey Goldberg 5 years ago
parent
commit
a40e8ad53d
2 changed files with 16 additions and 8 deletions
  1. +8
    -3
      test_xvfb.py
  2. +8
    -5
      xvfbwrapper.py

+ 8
- 3
test_xvfb.py View File

@ -28,8 +28,8 @@ class TestXvfb(unittest.TestCase):
xvfb.start()
self.assertNotEqual(orig_display, os.environ['DISPLAY'])
xvfb.stop()
self.assertIsNone(xvfb.proc)
self.assertEqual(orig_display, os.environ['DISPLAY'])
self.assertIsNone(xvfb.proc)
def test_start_without_existing_display(self):
del os.environ['DISPLAY']
@ -47,8 +47,8 @@ class TestXvfb(unittest.TestCase):
display_var = ':{}'.format(xvfb.new_display)
self.assertEqual(display_var, os.environ['DISPLAY'])
self.assertIsNotNone(xvfb.proc)
self.assertIsNone(xvfb.proc)
self.assertEqual(orig_display, os.environ['DISPLAY'])
self.assertIsNone(xvfb.proc)
def test_start_with_kwargs(self):
w = 800
@ -64,10 +64,15 @@ class TestXvfb(unittest.TestCase):
self.assertEqual(display_var, os.environ['DISPLAY'])
self.assertIsNotNone(xvfb.proc)
def test_start_with_arbitrary_kwarg(self):
def test_start_with_arbitrary_kwargs(self):
xvfb = Xvfb(nolisten='tcp')
self.addCleanup(xvfb.stop)
xvfb.start()
display_var = ':{}'.format(xvfb.new_display)
self.assertEqual(display_var, os.environ['DISPLAY'])
self.assertIsNotNone(xvfb.proc)
def test_start_fails_with_unknown_kwargs(self):
xvfb = Xvfb(foo='bar')
with self.assertRaises(RuntimeError):
xvfb.start()

+ 8
- 5
xvfbwrapper.py View File

@ -68,8 +68,11 @@ class Xvfb:
else:
self._set_display_var(self.orig_display)
if self.proc is not None:
self.proc.terminate()
self.proc.wait()
try:
self.proc.terminate()
self.proc.wait()
except OSError:
pass
self.proc = None
def _get_next_unused_display(self):
@ -81,11 +84,11 @@ class Xvfb:
highest_display = max(existing_displays) if existing_displays else 0
return highest_display + 1
def _set_display_var(self, display):
os.environ['DISPLAY'] = ':{}'.format(display)
def xvfb_exists(self):
"""Check that Xvfb is available on PATH and is executable."""
paths = os.environ['PATH'].split(os.pathsep)
return any(os.access(os.path.join(path, 'Xvfb'), os.X_OK)
for path in paths)
def _set_display_var(self, display):
os.environ['DISPLAY'] = ':{}'.format(display)

Loading…
Cancel
Save