dicthelperstest.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # I need to turn this into a proper unit test.
  2. # uhm, this is horrible. sorry everybody.
  3. # -Bryan
  4. import time
  5. from dicthelpers import fallbackdict
  6. start = time.time()
  7. fallback = {1: '1'}
  8. poop = fallbackdict(fallback)
  9. print 'expect 1 (fallback): ' + poop[1]
  10. fallback[2] = '2'
  11. print 'expect 2 (dynamic fallback): ' + poop[2]
  12. poop[2] = '3'
  13. print 'expect 3 (overridden): ' + poop[2]
  14. del poop[2]
  15. print 'expect 2 (fallback after delete): ' + poop[2]
  16. fallback['three'] = 3
  17. fallback[3] = '3{three}'
  18. print 'expect 33 (formatting): ' + poop[3]
  19. print 'expect 4 (len): ' + str(len(poop))
  20. fallback['infinite'] = '{infinite}'
  21. print 'simple infinite recursion test: ' + poop['infinite']
  22. fallback['infone'] = '{inftwo}'
  23. fallback['inftwo'] = '{infone}'
  24. print 'double infinite recursion test: ' + poop['infone']
  25. fallback['2infone'] = '{2inftwo}'
  26. fallback['2inftwo'] = '{2infone}'
  27. print 'double infinite recursion test: ' + poop['2inftwo']
  28. poop['four'] = 4
  29. poop[4] = '4{four}'
  30. print 'expect 34 (self as string mapping): {three}{four}'.format(**poop)
  31. print 'expect 44 (self formatting): ' + poop[4]
  32. # silent iter length processing.
  33. # this used to take 1 or 2 seconds prior to optimizations
  34. for x in poop: poop[x]
  35. stop = time.time()
  36. print "execution " + str(stop - start)