m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB

6 months ago
  1. from sympy.assumptions import ask, Q
  2. from sympy.assumptions.assume import assuming, global_assumptions
  3. from sympy.abc import x, y
  4. def test_assuming():
  5. with assuming(Q.integer(x)):
  6. assert ask(Q.integer(x))
  7. assert not ask(Q.integer(x))
  8. def test_assuming_nested():
  9. assert not ask(Q.integer(x))
  10. assert not ask(Q.integer(y))
  11. with assuming(Q.integer(x)):
  12. assert ask(Q.integer(x))
  13. assert not ask(Q.integer(y))
  14. with assuming(Q.integer(y)):
  15. assert ask(Q.integer(x))
  16. assert ask(Q.integer(y))
  17. assert ask(Q.integer(x))
  18. assert not ask(Q.integer(y))
  19. assert not ask(Q.integer(x))
  20. assert not ask(Q.integer(y))
  21. def test_finally():
  22. try:
  23. with assuming(Q.integer(x)):
  24. 1/0
  25. except ZeroDivisionError:
  26. pass
  27. assert not ask(Q.integer(x))
  28. def test_remove_safe():
  29. global_assumptions.add(Q.integer(x))
  30. with assuming():
  31. assert ask(Q.integer(x))
  32. global_assumptions.remove(Q.integer(x))
  33. assert not ask(Q.integer(x))
  34. assert ask(Q.integer(x))
  35. global_assumptions.clear() # for the benefit of other tests