-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtest_main.py
21 lines (18 loc) · 918 Bytes
/
test_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from importlib.machinery import SourceFileLoader
from importlib.util import spec_from_loader, module_from_spec
import os
from tests.tests_dsl import replace
# pylint: disable=missing-function-docstring
class TestMain():
# a def __init__ deve retornar None
@replace('source.severino.Severino.__init__', None, lambda init_mock: init_mock.assert_called_once())
def test_main_deve_iniciar_severino(self, _: None) -> None:
diretorio_atual = os.path.realpath(os.path.curdir)
# o modulo sera carregado manualmente para simular uma chamada do terminal
# referencia: https://stackoverflow.com/a/49012866/7653600
nome = '__main__'
spec = spec_from_loader(nome, SourceFileLoader(nome, f'{diretorio_atual}/source/main.py'))
assert spec is not None
assert spec.loader is not None
modulo = module_from_spec(spec)
spec.loader.exec_module(modulo)