Commits

luensdorf  committed 1f9b6ba

Use generator expression in condition value to be even more dict-like.

  • Participants
  • Parent commits 1a3cb1c

Comments (0)

Files changed (3)

File simpy/events.py

         return '<ConditionValue %s>' % self.todict()
 
     def keys(self):
-        return self.events
+        return (event for event in self.events)
 
     def values(self):
-        return [event._value for event in self.events]
+        return (event._value for event in self.events)
 
     def items(self):
-        return [(event, event._value) for event in self.events]
+        return ((event, event._value) for event in self.events)
 
     def todict(self):
         return dict((event, event._value) for event in self.events)

File simpy/test/test_condition.py

         assert cond is not orig
 
         results = yield cond
-        assert results.values() == [1, 2, 0]
+        assert list(results.values()) == [1, 2, 0]
 
     env.process(process(env))
     env.run()
         assert cond is not orig
 
         results = yield cond
-        assert results.values() == [1, 0]
+        assert list(results.values()) == [1, 0]
 
     env.process(process(env))
     env.run()
         assert cond is not orig
 
         results = yield cond
-        assert results.values() == [0]
+        assert list(results.values()) == [0]
 
     env.process(process(env))
     env.run()
         assert cond is not orig
 
         results = yield cond
-        assert results.values() == [0]
+        assert list(results.values()) == [0]
 
     env.process(process(env))
     env.run()
 
     def p(env, timeouts):
         results = yield env.all_of(timeouts)
-        assert results.keys() == timeouts
+        assert list(results.keys()) == timeouts
 
     env.process(p(env, timeouts))
     env.run()
 
     def p(env, timeouts):
         results = yield condition
-        assert results.keys() == timeouts
+        assert list(results.keys()) == timeouts
 
     env.process(p(env, timeouts))
     env.run()

File simpy/test/test_util.py

         condition_A &= condition_B
 
         results = yield condition_A
-        assert results.values() == [0, 1, 0, 1]
+        assert list(results.values()) == [0, 1, 0, 1]
 
     env.process(parent(env))
     env.run()
         condition = condition_A & condition_B
         result = ConditionValue()
         condition._populate_value(result)
-        assert result.values() == [0, 0]
+        assert list(result.values()) == [0, 0]
 
         results = yield condition
-        assert results.values() == [0, 1, 0, 1]
+        assert list(results.values()) == [0, 1, 0, 1]
 
     env.process(parent(env))
     env.run()
         events = [env.timeout(0, value='spam'), env.timeout(1, value='eggs')]
         yield env.timeout(2)
 
-        values = (yield env.all_of(events)).values()
+        values = list((yield env.all_of(events)).values())
         assert values == ['spam', 'eggs']
 
     env.process(parent(env))
         condition_A |= condition_B
 
         results = yield condition_A
-        assert results.values() == ['b']
+        assert list(results.values()) == ['b']
 
     env.process(parent(env))
     env.run()
         events = [env.timeout(0, value='spam'), env.timeout(1, value='eggs')]
         yield env.timeout(2)
 
-        values = (yield env.any_of(events)).values()
+        values = list((yield env.any_of(events)).values())
         assert values == ['spam', 'eggs']
 
     env.process(parent(env))