test_dependency_tf.py 760 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env python
  2. import os
  3. import sys
  4. if __name__ == "__main__":
  5. # Do not import tf for testing purposes.
  6. os.environ["RLLIB_TEST_NO_TF_IMPORT"] = "1"
  7. from ray.rllib.agents.a3c import A2CTrainer
  8. assert "tensorflow" not in sys.modules, \
  9. "`tensorflow` initially present, when it shouldn't!"
  10. # Note: No ray.init(), to test it works without Ray
  11. trainer = A2CTrainer(
  12. env="CartPole-v0", config={
  13. "framework": "torch",
  14. "num_workers": 0
  15. })
  16. trainer.train()
  17. assert "tensorflow" not in sys.modules, \
  18. "`tensorflow` should not be imported after creating and " \
  19. "training A3CTrainer!"
  20. # Clean up.
  21. del os.environ["RLLIB_TEST_NO_TF_IMPORT"]
  22. print("ok")