Skip to content

Commit 6302a9e

Browse files
committed
Add test for __main__ entry point module
1 parent f172366 commit 6302a9e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/test_main.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
"""test the __main__ entry point module"""
3+
4+
import importlib
5+
import importlib.machinery
6+
import importlib.util
7+
from unittest.mock import MagicMock, patch
8+
9+
from tests import ICATestCase
10+
11+
12+
class TestMain(ICATestCase):
13+
14+
@patch("ica.cli.main", return_value=None)
15+
def test_main(self, cli_main: MagicMock) -> None:
16+
"""should import main"""
17+
# Load the module spec and create the module
18+
loader = importlib.machinery.SourceFileLoader("__main__", "./ica/__main__.py")
19+
spec = importlib.util.spec_from_loader(loader.name, loader)
20+
if not spec:
21+
raise ImportError("Failed to load module spec")
22+
main_module = importlib.util.module_from_spec(spec)
23+
# Expose package information to dynamically-imported module
24+
main_module.__package__ = __package__
25+
loader.exec_module(main_module)
26+
cli_main.assert_called_once()

0 commit comments

Comments
 (0)