File: test_xvfb.py

package info (click to toggle)
python-xvfbwrapper 0.2.4-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 100 kB
  • ctags: 43
  • sloc: python: 210; makefile: 25
file content (62 lines) | stat: -rw-r--r-- 1,855 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python


from xvfbwrapper import Xvfb

import os
import sys
import unittest


class TestXvfb(unittest.TestCase):

    def setUp(self):
        sys.stdout = sys.__stdout__
        self.addCleanup(self.restore_stdout)

    def restore_stdout(self):
        sys.stdout = sys.__stdout__

    def test_start(self):
        xvfb = Xvfb()
        self.addCleanup(xvfb.stop)
        xvfb.start()
        self.assertEqual(':%d' % xvfb.vdisplay_num, os.environ['DISPLAY'])
        self.assertIsNotNone(xvfb.proc)

    def test_stop(self):
        orig_display = os.environ['DISPLAY']
        xvfb = Xvfb()
        xvfb.start()
        self.assertNotEqual(orig_display, os.environ['DISPLAY'])
        xvfb.stop()
        self.assertIsNone(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.assertIsNotNone(xvfb.proc)
        self.assertIsNone(xvfb.proc)
        self.assertEqual(orig_display, os.environ['DISPLAY'])

    def test_start_with_kwargs(self):
        w = 800
        h = 600
        depth = 16
        xvfb = Xvfb(width=w, height=h, colordepth=depth)
        self.addCleanup(xvfb.stop)
        xvfb.start()
        self.assertEqual(w, xvfb.width)
        self.assertEqual(h, xvfb.height)
        self.assertEqual(depth, xvfb.colordepth)
        self.assertEqual(os.environ['DISPLAY'], ':%d' % xvfb.vdisplay_num)
        self.assertIsNotNone(xvfb.proc)

    def test_start_with_arbitrary_kwarg(self):
        xvfb = Xvfb(nolisten='tcp')
        self.addCleanup(xvfb.stop)
        xvfb.start()
        self.assertEqual(os.environ['DISPLAY'], ':%d' % xvfb.vdisplay_num)
        self.assertIsNotNone(xvfb.proc)