Ejemplo n.º 1
0
def test_getenv():
    environ["foo"] = "bar"

    assert getenv("foo") == "bar"
    del environ["foo"]
    assert getenv("foo", "quux") == "quux"
    assert getenv("foo") is None
Ejemplo n.º 2
0
def test_environ():
    for key, value in iteritems(environ):
        assert isinstance(key, fsnative)
        assert isinstance(value, fsnative)

    environ[fsnative(u"foo")] = fsnative(u"bar")
    assert getenv(fsnative(u"foo")) == "bar"
    assert isinstance(getenv("foo"), fsnative)

    assert environ["foo"] == "bar"
    assert isinstance(environ["foo"], fsnative)

    del environ["foo"]
    assert getenv("foo") is None
    with pytest.raises(KeyError):
        del environ["foo"]

    if os.name == "nt":
        with pytest.raises(ValueError):
            environ["=="] = "bla"
    else:
        environ["=="] = "bla"
        assert environ["=="] == "bla"

    assert len(environ) == len(environ.keys())
    repr(environ)
Ejemplo n.º 3
0
def test_environ():
    for key, value in iteritems(environ):
        assert isinstance(key, fsnative)
        assert isinstance(value, fsnative)

    environ[fsnative(u"foo")] = fsnative(u"bar")
    assert getenv(fsnative(u"foo")) == "bar"
    assert isinstance(getenv("foo"), fsnative)

    assert environ["foo"] == "bar"
    assert isinstance(environ["foo"], fsnative)

    del environ["foo"]
    assert getenv("foo") is None
    with pytest.raises(KeyError):
        del environ["foo"]

    try:
        environ["=="] = "bla"
    except ValueError:
        # fails on Windows and on Linux with some Python versions
        pass

    assert len(environ) == len(environ.keys())
    repr(environ)
Ejemplo n.º 4
0
def test_unsetenv():
    putenv("foo", "bar")
    # for some reason getenv goes to the cache, which makes it hard to test
    # things
    assert getenv("foo") is None
    unsetenv("foo")
    unsetenv("foo")
    assert getenv("foo") is None
Ejemplo n.º 5
0
def test_environ_mirror():
    with preserve_environ():
        os.environ.pop("BLA", None)
        environ["BLA"] = u"\ud83d"
        assert "BLA" in os.environ
        assert os.environ["BLA"] in (u"\ud83d", "?")
        assert get_windows_env_var(u"BLA") == u"\ud83d"
        del environ["BLA"]
        assert "BLA" not in os.environ
        assert getenv("BLA") is None