test_chroma_db.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # ruff: noqa: E501
  2. import unittest
  3. from unittest.mock import patch
  4. from embedchain import App
  5. from embedchain.config import InitConfig
  6. from embedchain.vectordb.chroma_db import ChromaDB, chromadb
  7. class TestChromaDbHosts(unittest.TestCase):
  8. def test_init_with_host_and_port(self):
  9. """
  10. Test if the `ChromaDB` instance is initialized with the correct host and port values.
  11. """
  12. host = "test-host"
  13. port = "1234"
  14. with patch.object(chromadb, "Client") as mock_client:
  15. _db = ChromaDB(host=host, port=port)
  16. expected_settings = chromadb.config.Settings(
  17. chroma_api_impl="rest",
  18. chroma_server_host=host,
  19. chroma_server_http_port=port,
  20. )
  21. mock_client.assert_called_once_with(expected_settings)
  22. # Review this test
  23. class TestChromaDbHostsInit(unittest.TestCase):
  24. @patch("embedchain.vectordb.chroma_db.chromadb.Client")
  25. def test_init_with_host_and_port(self, mock_client):
  26. """
  27. Test if the `App` instance is initialized with the correct host and port values.
  28. """
  29. host = "test-host"
  30. port = "1234"
  31. config = InitConfig(host=host, port=port)
  32. _app = App(config)
  33. # self.assertEqual(mock_client.call_args[0][0].chroma_server_host, host)
  34. # self.assertEqual(mock_client.call_args[0][0].chroma_server_http_port, port)
  35. class TestChromaDbHostsNone(unittest.TestCase):
  36. @patch("embedchain.vectordb.chroma_db.chromadb.Client")
  37. def test_init_with_host_and_port(self, mock_client):
  38. """
  39. Test if the `App` instance is initialized without default hosts and ports.
  40. """
  41. _app = App()
  42. self.assertEqual(mock_client.call_args[0][0].chroma_server_host, None)
  43. self.assertEqual(mock_client.call_args[0][0].chroma_server_http_port, None)
  44. class TestChromaDbHostsLoglevel(unittest.TestCase):
  45. @patch("embedchain.vectordb.chroma_db.chromadb.Client")
  46. def test_init_with_host_and_port(self, mock_client):
  47. """
  48. Test if the `App` instance is initialized without a config that does not contain default hosts and ports.
  49. """
  50. config = InitConfig(log_level="DEBUG")
  51. _app = App(config)
  52. self.assertEqual(mock_client.call_args[0][0].chroma_server_host, None)
  53. self.assertEqual(mock_client.call_args[0][0].chroma_server_http_port, None)