Skip to content

Commit

Permalink
CU-8694wh3d5: Add relevant tests to automatic usage monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mart-r committed Jul 17, 2024
1 parent 9b660f8 commit 166d933
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/utils/test_usage_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import tempfile

from unittest import TestCase
from unittest.mock import patch


class UsageMonitorBaseTests(TestCase):
Expand Down Expand Up @@ -86,3 +87,41 @@ def test_some_in_file(self):
lines = self._get_saved_lines()
self.assertTrue(lines)
self.assertEqual(len(lines), self.expected_in_file)


class UMT(UsageMonitorBaseTests):
ENABLED_DICT = {
"MEDCAT_LOGS": "True",
"MEDCAT_LOGS_LOCATION": "."
}
DISABLED_DICT_1 = {
"MEDCAT_LOGS": "False",
"MEDCAT_LOGS_LOCATION": "FAIL" # should not change anything
}
DISABLED_DICT_2 = {
"MEDCAT_LOGS": "0",
"MEDCAT_LOGS_LOCATION": "."
}

def setUp(self) -> None:
super().setUp()
self.config.enabled = "auto"
self.config.log_folder = self._temp_dir.name
self.monitor = usage_monitoring.UsageMonitor(self.MODEL_HASH,
self.config)

@patch.dict(os.environ, ENABLED_DICT)
def test_listens_to_os_environ_enabled(self):
self.assertTrue(self.monitor._should_log())
self.assertNotEqual(self.config.log_folder, self._temp_dir.name)
self.assertEqual(self.config.log_folder, self.ENABLED_DICT["MEDCAT_LOGS_LOCATION"])

@patch.dict(os.environ, DISABLED_DICT_1)
def test_listens_to_os_environ_disabled_1(self):
self.assertFalse(self.monitor._should_log())
self.assertEqual(self.config.log_folder, self._temp_dir.name)

@patch.dict(os.environ, DISABLED_DICT_2)
def test_listens_to_os_environ_disabled_2(self):
self.assertFalse(self.monitor._should_log())
self.assertEqual(self.config.log_folder, self._temp_dir.name)

0 comments on commit 166d933

Please sign in to comment.