gc1.py 767 B

12345678910111213141516171819202122232425262728293031323334
  1. # basic tests for gc module
  2. try:
  3. import gc
  4. except ImportError:
  5. print("SKIP")
  6. raise SystemExit
  7. print(gc.isenabled())
  8. gc.disable()
  9. print(gc.isenabled())
  10. gc.enable()
  11. print(gc.isenabled())
  12. gc.collect()
  13. if hasattr(gc, 'mem_free'):
  14. # uPy has these extra functions
  15. # just test they execute and return an int
  16. assert type(gc.mem_free()) is int
  17. assert type(gc.mem_alloc()) is int
  18. if hasattr(gc, 'threshold'):
  19. # uPy has this extra function
  20. # check execution and returns
  21. assert(gc.threshold(1) is None)
  22. assert(gc.threshold() == 0)
  23. assert(gc.threshold(-1) is None)
  24. assert(gc.threshold() == -1)
  25. # Setting a low threshold should trigger collection at the list alloc
  26. gc.threshold(1)
  27. [[], []]
  28. gc.threshold(-1)