xlocal / test_xlocal.py

from __future__ import with_statement

import pytest

@pytest.fixture
def xlocal(request):
    import xlocal
    return xlocal.xlocal()

def test_scoping(xlocal):
    def f():
        assert xlocal.x == 3

    with xlocal(x=3):
        f()
    assert not hasattr(xlocal, "x")
    assert not xlocal._storage # no garbage

def test_stacking(xlocal):
    def f():
        assert xlocal.x == 3

    with xlocal(x=5):
        assert xlocal.x == 5
        with xlocal(x=3):
            assert xlocal.x == 3
        assert xlocal.x == 5
    assert not hasattr(xlocal, "x")

def test_nodelset(xlocal):
    with xlocal(y=3):
        assert xlocal.y == 3
        pytest.raises(AttributeError, lambda: delattr(xlocal, "y"))
    assert not hasattr(xlocal, "y")
    pytest.raises(AttributeError, lambda: setattr(xlocal, "x", None))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.