|
| 1 | +import unittest |
| 2 | +from unittest.mock import patch, mock_open |
| 3 | +from not_gitmodules import initializer |
| 4 | +from not_gitmodules.cli import cli |
| 5 | + |
| 6 | + |
| 7 | +class TestInitializerFunction(unittest.TestCase): |
| 8 | + @patch( |
| 9 | + "builtins.open", |
| 10 | + new_callable=mock_open, |
| 11 | + read_data="repos:\n file_reader: https://github.com/Free-Apps-for-All/file_manager_git_module", |
| 12 | + ) |
| 13 | + @patch("not_gitmodules.core.read_yaml") |
| 14 | + def test_initializer_with_valid_yaml(self, mock_read_yaml, mock_file): |
| 15 | + mock_read_yaml.return_value = { |
| 16 | + "repos": { |
| 17 | + "file_reader": "https://github.com/Free-Apps-for-All/file_manager_git_module" |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | + initializer("notgitmodules.yaml") |
| 22 | + |
| 23 | + mock_read_yaml.assert_called_once_with("notgitmodules.yaml") |
| 24 | + |
| 25 | + @patch("builtins.open", new_callable=mock_open, read_data="repos:\n invalid_repo") |
| 26 | + def test_initializer_with_invalid_yaml(self, mock_file): |
| 27 | + with self.assertRaises(FileNotFoundError): |
| 28 | + initializer("notgitmodules.yaml") |
| 29 | + |
| 30 | + @patch( |
| 31 | + "builtins.open", |
| 32 | + new_callable=mock_open, |
| 33 | + read_data="repos:\n file_reader: https://github.com/Free-Apps-for-All/file_manager_git_module", |
| 34 | + ) |
| 35 | + @patch("not_gitmodules.core.read_yaml") |
| 36 | + def test_cli_with_default_input(self, mock_read_yaml, mock_file): |
| 37 | + with patch("builtins.input", return_value=""): |
| 38 | + cli() |
| 39 | + |
| 40 | + mock_read_yaml.assert_called_once_with("notgitmodules.yaml") |
| 41 | + |
| 42 | + |
| 43 | +if __name__ == "__main__": |
| 44 | + unittest.main() |
0 commit comments