Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Add test for models module

davidmezzettid53f1f5b1094
diff --git a/test/python/testmodels.py b/test/python/testmodels.py
new file mode 100644
index 00000000..f14dd73c
--- /dev/null
+++ b/test/python/testmodels.py
@@ -0,0 +1,33 @@
+"""
+Models module tests
+"""
+
+import unittest
+
+from unittest.mock import patch
+
+from txtai.models import Models
+
+
+class TestModels(unittest.TestCase):
+ """
+ Models tests.
+ """
+
+ @patch("torch.cuda.is_available")
+ def testDeviceid(self, cuda):
+ """
+ Tests the deviceid method
+ """
+
+ cuda.return_value = True
+ self.assertEqual(Models.deviceid(True), 0)
+ self.assertEqual(Models.deviceid(False), -1)
+ self.assertEqual(Models.deviceid(0), 0)
+ self.assertEqual(Models.deviceid(1), 1)
+
+ cuda.return_value = False
+ self.assertEqual(Models.deviceid(True), -1)
+ self.assertEqual(Models.deviceid(False), -1)
+ self.assertEqual(Models.deviceid(0), -1)
+ self.assertEqual(Models.deviceid(1), -1)