- r = c.recent()
- ts = filter(lambda t: t['id'] == i, r)
- assert len(ts) == 1, "check scratched track appears exactly once in recent"
- assert ts[0]['state'] == 'scratched', "checking track scratched"
+ if p is None:
+ print " track played too quickly, trying again..."
+ continue
+ print " scratching track"
+ i = p['id']
+ c.scratch(i)
+ print " waiting for track to finish"
+ p = c.playing()
+ limit = 60
+ while (p is not None and p['id'] == i) and limit > 0:
+ time.sleep(1)
+ p = c.playing()
+ limit -= 1
+ assert limit > 0, "check track finishes in a reasonable period"
+ print " checking scratched track turned up in recent list"
+ r = c.recent()
+ ts = filter(lambda t: t['id'] == i, r)
+ assert len(ts) == 1, "check scratched track appears exactly once in recent"
+ if ts[0]['state'] == 'ok':
+ print " track played too quickly, trying again..."
+ continue
+ assert ts[0]['state'] == 'scratched', "checking track scratched"
+ break