|
| 1 | +import __main__ |
| 2 | +from unittest import TestCase |
| 3 | +from unittest.mock import patch |
| 4 | + |
| 5 | +from veadk.utils.misc import get_agents_dir |
| 6 | + |
| 7 | + |
| 8 | +class GetAgentsDirTest(TestCase): |
| 9 | + @patch.object(__main__, "__file__", "/test/path/app/main.py") |
| 10 | + def test_get_agents_dir_from_main(self): |
| 11 | + """Test get_agents_dir using __main__.__file__""" |
| 12 | + self.assertEqual(get_agents_dir(), "/test/path") |
| 13 | + |
| 14 | + def test_get_agents_dir_from_argv(self): |
| 15 | + """Test get_agents_dir using sys.argv""" |
| 16 | + with patch("veadk.utils.misc.sys") as mock_sys: |
| 17 | + mock_sys.argv = ["/test/path/app/main.py"] |
| 18 | + with patch("veadk.utils.misc.hasattr") as mock_hasattr: |
| 19 | + mock_hasattr.return_value = False |
| 20 | + self.assertEqual(get_agents_dir(), "/test/path") |
| 21 | + |
| 22 | + @patch("veadk.utils.misc.os.getcwd") |
| 23 | + @patch("veadk.utils.misc.sys") |
| 24 | + def test_get_agents_dir_from_cwd(self, mock_sys, mock_getcwd): |
| 25 | + """Test get_agents_dir using os.getcwd""" |
| 26 | + mock_sys.argv = [""] |
| 27 | + mock_getcwd.return_value = "/test/path/app" |
| 28 | + with patch("veadk.utils.misc.hasattr") as mock_hasattr: |
| 29 | + mock_hasattr.return_value = False |
| 30 | + self.assertEqual(get_agents_dir(), "/test/path") |
| 31 | + |
| 32 | + @patch("veadk.utils.misc.os.getcwd") |
| 33 | + @patch("veadk.utils.misc.sys") |
| 34 | + def test_get_agents_dir_from_cwd_empty_argv(self, mock_sys, mock_getcwd): |
| 35 | + """Test get_agents_dir using os.getcwd with empty argv""" |
| 36 | + mock_sys.argv = [] |
| 37 | + mock_getcwd.return_value = "/test/path/app" |
| 38 | + with patch("veadk.utils.misc.hasattr") as mock_hasattr: |
| 39 | + mock_hasattr.return_value = False |
| 40 | + self.assertEqual(get_agents_dir(), "/test/path") |
0 commit comments