Ejemplo n.º 1
0
def q_application():
    global TestQtApp
    assert hasattr(TestQtApp,
                   'app'), "Can only initialize QApplication once per process"

    if TestQtApp.app is None:
        if 'PYDEV_CONSOLE_ENCODING' in os.environ:
            # PyDev destroys session scoped fixtures after each test, so we can't clean up the XvfbServer
            global server
            server = XvfbServer()
            with set_env(XAUTHORITY=server.authfile, DISPLAY=server.display):
                TestQtApp.app = QtGui.QApplication(
                    [__name__, '-display', server.display])
            yield TestQtApp
        else:
            with XvfbServer() as server:
                with set_env(XAUTHORITY=server.authfile,
                             DISPLAY=server.display):
                    TestQtApp.app = QtGui.QApplication(
                        [__name__, '-display', server.display])
                yield TestQtApp
                TestQtApp.app.exit()
                del TestQtApp.app
                gc.collect()

    else:
        yield TestQtApp
Ejemplo n.º 2
0
def test_set_env_ok_if_not_exists():
    if TEMP_NAME in os.environ:
        del os.environ[TEMP_NAME]

    with util.set_env(TEMP_NAME, "anything"):
        assert os.environ[TEMP_NAME] == "anything"
    assert TEMP_NAME not in os.environ
Ejemplo n.º 3
0
def test_set_env_ok_if_exists():
    ev = os.environ[TEMP_NAME] = "junk_name"
    try:
        with util.set_env(TEMP_NAME, "not_junk"):
            assert os.environ[TEMP_NAME] == "not_junk"
        assert os.environ[TEMP_NAME] == ev
    finally:
        del os.environ[TEMP_NAME]
Ejemplo n.º 4
0
def test_PYTHONPATH_not_present_in_testing_env_if_set():
    with util.set_env('PYTHONPATH', 'fred'):
        with mock.patch.object(util.Workspace, 'run') as run:
            util.TmpVirtualEnv()
            call = run.mock_calls[0]
            assert 'PYTHONPATH' not in call[2]['env']

            util.TmpVirtualEnv({'PYTHONPATH': 'john'})
            call = run.mock_calls[1]
            assert 'PYTHONPATH' not in call[2]['env']
Ejemplo n.º 5
0
def test_set_env_with_kwargs_updates():
    test_env = {"TESTING_A": "a", "TESTING_B": "b", "TESTING_C": "c"}
    os.environ.update(test_env)
    with util.set_env("TESTING_A", 1, TESTING_B="fred", TESTING_C=None):
        assert os.environ["TESTING_A"] == "1"
        assert os.environ["TESTING_B"] == "fred"
        assert "C" not in os.environ
    assert os.environ["TESTING_A"] == "a"
    assert os.environ["TESTING_B"] == "b"
    assert os.environ["TESTING_C"] == "c"
Ejemplo n.º 6
0
def test_subprocess_set_env_ok_if_not_exists():
    if TEMP_NAME in os.environ:
        del os.environ[TEMP_NAME]
    with util.set_env(TEMP_NAME, "anything"):
        out, _ = util.launch("env")
        for o in out.split("\n"):
            if o.startswith(TEMP_NAME):
                assert o == "%s=anything" % TEMP_NAME
                break
        else:
            assert False, "%s not found in os.environ" % TEMP_NAME
Ejemplo n.º 7
0
def q_application():
    global TestQtApp
    assert hasattr(TestQtApp, 'app'), "Can only initialize QApplication once per process"

    if TestQtApp.app is None:
        if 'PYDEV_CONSOLE_ENCODING' in os.environ:
            # PyDev destroys session scoped fixtures after each test, so we can't clean up the XvfbServer
            global server
            server = XvfbServer()
            with set_env(XAUTHORITY=server.authfile, DISPLAY=server.display):
                TestQtApp.app = QtGui.QApplication([__name__, '-display', server.display])
            yield TestQtApp
        else:
            with XvfbServer() as server:
                with set_env(XAUTHORITY=server.authfile, DISPLAY=server.display):
                    TestQtApp.app = QtGui.QApplication([__name__, '-display', server.display])
                yield TestQtApp
                TestQtApp.app.exit()
                del TestQtApp.app
                gc.collect()

    else:
        yield TestQtApp
Ejemplo n.º 8
0
def test_subprocess_set_env_ok_if_exists():
    ev = os.environ[TEMP_NAME] = "junk_name"
    try:
        with util.set_env(TEMP_NAME, "anything"):
            out, _ = util.launch("env")
            for o in out.split("\n"):
                if o.startswith(TEMP_NAME):
                    assert o == "%s=anything" % TEMP_NAME
                    break
            else:
                assert False, "%s not found in os.environ" % TEMP_NAME
        assert os.environ[TEMP_NAME] == ev

    finally:
        del os.environ[TEMP_NAME]