-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_main.py
36 lines (31 loc) · 1.51 KB
/
test_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import unittest
import sys
from unittest.mock import patch, MagicMock
import main
class TestMain(unittest.TestCase):
@patch('main.run_script')
def test_mern_stack(self, mock_run_script):
test_args = ["main.py", "MERN", "my_project"]
with patch.object(sys, 'argv', test_args):
main.main()
mock_run_script.assert_called_once_with("mern.py", "my_project", "/frontend-stack-automation/templates/server")
@patch('main.run_script')
def test_mevn_stack(self, mock_run_script):
test_args = ["main.py", "MEVN", "my_project"]
with patch.object(sys, 'argv', test_args):
main.main()
mock_run_script.assert_called_once_with("mevn.py", "my_project", "/frontend-stack-automation/templates/server")
@patch('main.run_script')
def test_mean_stack(self, mock_run_script):
test_args = ["main.py", "MEAN", "my_project"]
with patch.object(sys, 'argv', test_args):
main.main()
mock_run_script.assert_called_once_with("mean.py", "my_project", "/frontend-stack-automation/templates/server")
def test_invalid_stack(self):
test_args = ["main.py", "INVALID", "my_project"]
with patch.object(sys, 'argv', test_args), patch('builtins.print') as mocked_print, patch('sys.exit') as mock_exit:
main.main()
mocked_print.assert_called_with("Invalid stack name. Please choose MERN, MEVN or MEAN.")
mock_exit.assert_called_once_with(1)
if __name__ == '__main__':
unittest.main()