def test_launch_context_locals():
    """Test "locals" feature of LaunchContext class."""
    lc = LaunchContext()

    assert len(lc.get_locals_as_dict()) == 0

    lc.extend_locals({'foo': 1})

    assert 'foo' in lc.get_locals_as_dict()
    assert lc.get_locals_as_dict()['foo'] == 1
    assert lc.locals.foo == 1
    with pytest.raises(AttributeError):
        lc.locals.foo = 2

    lc._push_locals()
    assert lc.locals.foo == 1
    lc.extend_locals({'foo': 2, 'bar': 3})
    assert lc.locals.foo == 2
    assert lc.locals.bar == 3
    lc._pop_locals()
    assert lc.locals.foo == 1
    with pytest.raises(AttributeError):
        assert lc.locals.bar == 3

    with pytest.raises(RuntimeError):
        lc._pop_locals()
Ejemplo n.º 2
0
def test_this_launch_file_path_methods():
    """Test the methods of the ThisLaunchFileDir class."""
    tlfp = ThisLaunchFileDir()

    lc = LaunchContext()
    with pytest.raises(SubstitutionFailure):
        tlfp.perform(lc)
    lc.extend_locals({'current_launch_file_directory': 'foo'})
    assert tlfp.perform(lc) == 'foo'