summaryrefslogtreecommitdiffstats
path: root/python/mozperftest/mozperftest/tests/test_visualtools.py
blob: 9e5af583d4cc81a322159467bf029f0ecfacd1ad (plain)
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
#!/usr/bin/env python
import os
from unittest import mock

import mozunit
import pytest

from mozperftest.test.browsertime.visualtools import get_dependencies, xvfb
from mozperftest.utils import temporary_env


@mock.patch(
    "mozperftest.test.browsertime.visualtools.find_executable", new=lambda name: "Xvfb"
)
def test_xvfb(*mocked):
    with temporary_env(DISPLAY="ME"):
        with mock.patch("subprocess.Popen") as mocked, xvfb():
            mocked.assert_called()
        assert os.environ["DISPLAY"] == "ME"


@mock.patch(
    "mozperftest.test.browsertime.visualtools.find_executable", new=lambda name: "Xvfb"
)
def test_xvfb_env(*mocked):
    with temporary_env(DISPLAY=None):
        with mock.patch("subprocess.Popen") as mocked, xvfb():
            mocked.assert_called()
        assert "DISPLAY" not in os.environ


@mock.patch(
    "mozperftest.test.browsertime.visualtools.find_executable", new=lambda name: None
)
def test_xvfb_none(*mocked):
    with pytest.raises(FileNotFoundError), xvfb():
        pass


def test_get_dependencies():
    # Making sure we get a list on all supported platforms.
    # If we miss one, this raises a KeyError.
    get_dependencies()


if __name__ == "__main__":
    mozunit.main()