Changeset 42 for trunk

Show
Ignore:
Timestamp:
17/02/05 01:58:20 (7 years ago)
Author:
steve
Message:

Clarification for case #3: errors are still raised if trying to #foreach over non-iterable value that is not None

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/airspeed.py

    r41 r42  
    660660            if hasattr(iterable, 'keys'): iterable = iterable.keys() 
    661661            if not hasattr(iterable, '__getitem__'): 
    662                 raise AttributeError("value for $%s is not iterable in #foreach: %s" % (self.loop_var_name, iterable)) 
     662                raise ValueError("value for $%s is not iterable in #foreach: %s" % (self.loop_var_name, iterable)) 
    663663            for item in iterable: 
    664664                namespace = LocalNamespace(namespace) 
  • trunk/airspeed_test.py

    r41 r42  
    425425        template = airspeed.Template('#foreach($value in $values)foo#end') 
    426426        self.assertEquals('', template.merge({})) 
     427 
     428    def test_foreach_with_non_iterable_variable_raises_error(self): 
     429        template = airspeed.Template('#foreach($value in $values)foo#end') 
     430        self.assertRaises(ValueError, template.merge, {'values': 1}) 
    427431 
    428432#