Skip to content

Commit 06d004d

Browse files
author
Jeremi Do Dinh
authored
PYSCAN-42 Fix code coverage for the __main__ file. (#22)
1 parent ad82b78 commit 06d004d

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/test_main.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#
2+
# Sonar Scanner Python
3+
# Copyright (C) 2011-2023 SonarSource SA.
4+
# mailto:info AT sonarsource DOT com
5+
#
6+
# This program is free software; you can redistribute it and/or
7+
# modify it under the terms of the GNU Lesser General Public
8+
# License as published by the Free Software Foundation; either
9+
# version 3 of the License, or (at your option) any later version.
10+
# This program is distributed in the hope that it will be useful,
11+
#
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
# Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with this program; if not, write to the Free Software Foundation,
18+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
#
20+
import unittest
21+
from unittest.mock import patch, Mock, MagicMock
22+
from py_sonar_scanner.__main__ import scan
23+
from py_sonar_scanner.scanner import Scanner
24+
25+
26+
class TestMain(unittest.TestCase):
27+
@patch("py_sonar_scanner.scanner.Scanner")
28+
@patch("py_sonar_scanner.__main__.Environment")
29+
@patch("py_sonar_scanner.__main__.Configuration")
30+
def test_main_scan(self, mock_cfg, mock_env, mock_scanner):
31+
configuration_instance = MagicMock()
32+
configuration_instance.setup = Mock()
33+
mock_cfg.return_value = configuration_instance
34+
35+
environment_instance = MagicMock()
36+
environment_instance.setup = Mock()
37+
mock_scanner.scan = Mock()
38+
environment_instance.scanner.return_value = mock_scanner
39+
mock_env.return_value = environment_instance
40+
41+
scan()
42+
43+
configuration_instance.setup.assert_called_once()
44+
environment_instance.setup.assert_called_once()
45+
environment_instance.scanner.assert_called_once()
46+
mock_scanner.scan.assert_called_once()

0 commit comments

Comments
 (0)