Use TypeError instead of AssertionError for no sequence
Improve/extends tests.
This commit is contained in:
		
							parent
							
								
									09a0e45492
								
							
						
					
					
						commit
						b10ab0211c
					
				| 
						 | 
					@ -1430,7 +1430,8 @@ class LineMatcher:
 | 
				
			||||||
        :param str match_nickname: the nickname for the match function that
 | 
					        :param str match_nickname: the nickname for the match function that
 | 
				
			||||||
            will be logged to stdout when a match occurs
 | 
					            will be logged to stdout when a match occurs
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        assert isinstance(lines2, collections.abc.Sequence)
 | 
					        if not isinstance(lines2, collections.abc.Sequence):
 | 
				
			||||||
 | 
					            raise TypeError("invalid type for lines2: {}".format(type(lines2).__name__))
 | 
				
			||||||
        lines2 = self._getlines(lines2)
 | 
					        lines2 = self._getlines(lines2)
 | 
				
			||||||
        lines1 = self.lines[:]
 | 
					        lines1 = self.lines[:]
 | 
				
			||||||
        nextline = None
 | 
					        nextline = None
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -458,15 +458,26 @@ def test_testdir_run_timeout_expires(testdir) -> None:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_linematcher_with_nonlist() -> None:
 | 
					def test_linematcher_with_nonlist() -> None:
 | 
				
			||||||
    """Test LineMatcher with regard to passing in a set (accidentally)."""
 | 
					    """Test LineMatcher with regard to passing in a set (accidentally)."""
 | 
				
			||||||
 | 
					    from _pytest._code.source import Source
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    lm = LineMatcher([])
 | 
					    lm = LineMatcher([])
 | 
				
			||||||
    with pytest.raises(AssertionError):
 | 
					    with pytest.raises(TypeError, match="invalid type for lines2: set"):
 | 
				
			||||||
        lm.fnmatch_lines(set())
 | 
					        lm.fnmatch_lines(set())
 | 
				
			||||||
    with pytest.raises(AssertionError):
 | 
					    with pytest.raises(TypeError, match="invalid type for lines2: dict"):
 | 
				
			||||||
        lm.fnmatch_lines({})
 | 
					        lm.fnmatch_lines({})
 | 
				
			||||||
 | 
					    with pytest.raises(TypeError, match="invalid type for lines2: set"):
 | 
				
			||||||
 | 
					        lm.re_match_lines(set())
 | 
				
			||||||
 | 
					    with pytest.raises(TypeError, match="invalid type for lines2: dict"):
 | 
				
			||||||
 | 
					        lm.re_match_lines({})
 | 
				
			||||||
 | 
					    with pytest.raises(TypeError, match="invalid type for lines2: Source"):
 | 
				
			||||||
 | 
					        lm.fnmatch_lines(Source())
 | 
				
			||||||
    lm.fnmatch_lines([])
 | 
					    lm.fnmatch_lines([])
 | 
				
			||||||
    lm.fnmatch_lines(())
 | 
					    lm.fnmatch_lines(())
 | 
				
			||||||
 | 
					    lm.fnmatch_lines("")
 | 
				
			||||||
    assert lm._getlines({}) == {}
 | 
					    assert lm._getlines({}) == {}
 | 
				
			||||||
    assert lm._getlines(set()) == set()
 | 
					    assert lm._getlines(set()) == set()
 | 
				
			||||||
 | 
					    assert lm._getlines(Source()) == []
 | 
				
			||||||
 | 
					    assert lm._getlines(Source("pass\npass")) == ["pass", "pass"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_linematcher_match_failure() -> None:
 | 
					def test_linematcher_match_failure() -> None:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue