Skip to content

Commit

Permalink
Merge pull request #6242 from cankupeli/master
Browse files Browse the repository at this point in the history
implemented tests for branch coverage for function printSummary
  • Loading branch information
wRAR committed Mar 14, 2024
2 parents 7255dfd + 8d917c0 commit 02b97f9
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions tests/test_command_check.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sys
from io import StringIO
from unittest.mock import Mock, PropertyMock, patch
from unittest.mock import Mock, PropertyMock, call, patch

from scrapy.commands.check import Command
from scrapy.commands.check import Command, TextTestResult
from tests.test_commands import CommandTest


Expand Down Expand Up @@ -100,6 +100,55 @@ def test_SCRAPY_CHECK_set(self):
"""
self._test_contract(parse_def=parse_def)

def test_printSummary_with_unsuccessful_test_result_without_errors_and_without_failures(
self,
):
result = TextTestResult(Mock(), descriptions=False, verbosity=1)
start_time = 1.0
stop_time = 2.0
result.testsRun = 5
result.failures = []
result.errors = []
result.unexpectedSuccesses = ["a", "b"]
with patch.object(result.stream, "write") as mock_write:
result.printSummary(start_time, stop_time)
mock_write.assert_has_calls([call("FAILED"), call("\n")])

def test_printSummary_with_unsuccessful_test_result_with_only_failures(self):
result = TextTestResult(Mock(), descriptions=False, verbosity=1)
start_time = 1.0
stop_time = 2.0
result.testsRun = 5
result.failures = [(self, "failure")]
result.errors = []
with patch.object(result.stream, "writeln") as mock_write:
result.printSummary(start_time, stop_time)
mock_write.assert_called_with(" (failures=1)")

def test_printSummary_with_unsuccessful_test_result_with_only_errors(self):
result = TextTestResult(Mock(), descriptions=False, verbosity=1)
start_time = 1.0
stop_time = 2.0
result.testsRun = 5
result.failures = []
result.errors = [(self, "error")]
with patch.object(result.stream, "writeln") as mock_write:
result.printSummary(start_time, stop_time)
mock_write.assert_called_with(" (errors=1)")

def test_printSummary_with_unsuccessful_test_result_with_both_failures_and_errors(
self,
):
result = TextTestResult(Mock(), descriptions=False, verbosity=1)
start_time = 1.0
stop_time = 2.0
result.testsRun = 5
result.failures = [(self, "failure")]
result.errors = [(self, "error")]
with patch.object(result.stream, "writeln") as mock_write:
result.printSummary(start_time, stop_time)
mock_write.assert_called_with(" (failures=1, errors=1)")

@patch("scrapy.commands.check.ContractsManager")
def test_run_with_opts_list_prints_spider(self, cm_cls_mock):
output = StringIO()
Expand Down

0 comments on commit 02b97f9

Please sign in to comment.