Beispiel #1
0
def test__arg():
    import random
    from roslaunch.substitution_args import _arg, ArgException, SubstitutionException

    ctx = {
        'arg': {
            'foo': '12345',
            'bar': 'hello world',
            'baz': 'sim',
            'empty': '',
        }
    }

    # test invalid
    try:
        _arg('$(arg)', 'arg', [], ctx)
        assert False, "should have thrown"
    except SubstitutionException:
        pass

    # test normal
    tests = [
        ('12345', ('$(arg foo)', 'arg foo', ['foo'], ctx)),
        ('', ('$(arg empty)', 'arg empty', ['empty'], ctx)),
        ('sim', ('$(arg baz)', 'arg baz', ['baz'], ctx)),

        # test with other args present, should only resolve match
        ('1234512345', ('$(arg foo)$(arg foo)', 'arg foo', ['foo'], ctx)),
        ('12345$(arg baz)', ('$(arg foo)$(arg baz)', 'arg foo', ['foo'], ctx)),
        ('$(arg foo)sim', ('$(arg foo)$(arg baz)', 'arg baz', ['baz'], ctx)),

        # test double-resolve safe
        ('12345', ('12345', 'arg foo', ['foo'], ctx)),
    ]

    for result, test in tests:
        resolved, a, args, context = test
        assert result == _arg(resolved, a, args, context)

    #  - test that all fail if ctx is not set
    for result, test in tests:
        resolved, a, args, context = test
        try:
            _arg(resolved, a, args, {})
            assert False, "should have thrown"
        except ArgException as e:
            assert args[0] == str(e)
        try:
            _arg(resolved, a, args, {'arg': {}})
            assert False, "should have thrown"
        except ArgException as e:
            assert args[0] == str(e)
Beispiel #2
0
def test__arg():
    import random
    from roslaunch.substitution_args import _arg, ArgException, SubstitutionException
    
    ctx = { 'arg': {
            'foo': '12345',
            'bar': 'hello world',
            'baz': 'sim',
            'empty': '',
            }
            }
    
    # test invalid
    try:
        _arg('$(arg)', 'arg', [], ctx)
        assert False, "should have thrown"
    except SubstitutionException:
        pass

    # test normal
    tests = [
        ('12345', ('$(arg foo)', 'arg foo', ['foo'], ctx)),
        ('', ('$(arg empty)', 'arg empty', ['empty'], ctx)),
        ('sim', ('$(arg baz)', 'arg baz', ['baz'], ctx)),
        
        # test with other args present, should only resolve match
        ('1234512345', ('$(arg foo)$(arg foo)', 'arg foo', ['foo'], ctx)),
        ('12345$(arg baz)', ('$(arg foo)$(arg baz)', 'arg foo', ['foo'], ctx)),            
        ('$(arg foo)sim', ('$(arg foo)$(arg baz)', 'arg baz', ['baz'], ctx)),            
        
        # test double-resolve safe
        ('12345', ('12345', 'arg foo', ['foo'], ctx)),            
        ]
        
    for result, test in tests:
        resolved, a, args, context = test
        assert result == _arg(resolved, a, args, context)

    #  - test that all fail if ctx is not set
    for result, test in tests:
        resolved, a, args, context = test
        try:
            _arg(resolved, a, args, {})
            assert False, "should have thrown"
        except ArgException as e:
            assert args[0] == str(e)
        try:
            _arg(resolved, a, args, {'arg': {}})
            assert False, "should have thrown"
        except ArgException as e:
            assert args[0] == str(e)