+
+ print " testing scratches"
+ retry = False
+ scratchlimit = 5
+ while scratchlimit > 0:
+ scratchlimit -= 1
+ c.disable()
+ print " starting a track"
+ c.play(track)
+ c.enable()
+ p = c.playing()
+ 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
+ if scratchlimit == 0:
+ # TODO this is really not a great approach!
+ print " didn't complete in a reasonable time"
+ sys.exit(77)
+ print " waiting for scratch to complete"
+ p = c.recent()
+ while p is not None:
+ time.sleep(1)
+ p = c.playing()
+ assert p is None, "checking nothing is playing"
+ assert c.enabled() == True
+ c.random_enable()
+ assert c.random_enabled() == True