Browse Source

added unit test for context manager

changes/49/376949/1
Corey Goldberg 8 years ago
parent
commit
87e6a39f99
  1. 41
      xvfbwrapper/test_xvfb.py

41
xvfbwrapper/test_xvfb.py

@ -37,6 +37,15 @@ class TestXvfb(unittest.TestCase):
xvfb.start()
self.assertNotEqual(orig_display, os.environ['DISPLAY'])
xvfb.stop()
self.assertIs(None, xvfb.proc)
self.assertEqual(orig_display, os.environ['DISPLAY'])
def test_as_context_manager(self):
orig_display = os.environ['DISPLAY']
with Xvfb() as xvfb:
self.assertEqual(':%d' % xvfb.vdisplay_num, os.environ['DISPLAY'])
self.assertIsNot(None, xvfb.proc)
self.assertIs(None, xvfb.proc)
self.assertEqual(orig_display, os.environ['DISPLAY'])
def test_start_with_kwargs(self):
@ -58,35 +67,3 @@ class TestXvfb(unittest.TestCase):
xvfb.start()
self.assertEqual(os.environ['DISPLAY'], ':%d' % xvfb.vdisplay_num)
self.assertIsNot(None, xvfb.proc)
def test_start_with_bad_kwarg_param(self):
orig_display = os.environ['DISPLAY']
out = StringIO()
sys.stdout = out
xvfb = Xvfb(nolisten='badvalue')
self.addCleanup(xvfb.stop)
xvfb.start()
self.assertEqual(orig_display, os.environ['DISPLAY'])
self.assertIsNone(xvfb.proc)
self.assertIn('Error: Xvfb did not start', out.getvalue())
def test_start_with_bad_kwarg(self):
orig_display = os.environ['DISPLAY']
out = StringIO()
sys.stdout = out
xvfb = Xvfb(badarg='foo')
self.addCleanup(xvfb.stop)
xvfb.start()
self.assertEqual(orig_display, os.environ['DISPLAY'])
self.assertIsNone(xvfb.proc)
self.assertIn('Error: Xvfb did not start', out.getvalue())
class Pep8ConformanceTestCase(unittest.TestCase):
"""Test that all code conforms to PEP8."""
def test_pep8_conformance(self):
# scan source files in this directory recursively
this_dir = os.path.dirname(os.path.realpath(__file__))
self.pep8style = pep8.StyleGuide()
self.pep8style.input_dir(this_dir)
self.assertEqual(self.pep8style.options.report.total_errors, 0)

Loading…
Cancel
Save