@@ -413,8 +413,8 @@ class RunResult:
413
413
def __init__ (
414
414
self ,
415
415
ret : Union [int , ExitCode ],
416
- outlines : Sequence [str ],
417
- errlines : Sequence [str ],
416
+ outlines : List [str ],
417
+ errlines : List [str ],
418
418
duration : float ,
419
419
) -> None :
420
420
try :
@@ -1327,48 +1327,42 @@ class LineMatcher:
1327
1327
1328
1328
The constructor takes a list of lines without their trailing newlines, i.e.
1329
1329
``text.splitlines()``.
1330
-
1331
1330
"""
1332
1331
1333
- def __init__ (self , lines ) :
1332
+ def __init__ (self , lines : List [ str ]) -> None :
1334
1333
self .lines = lines
1335
- self ._log_output = []
1336
-
1337
- def str (self ):
1338
- """Return the entire original text."""
1339
- return "\n " .join (self .lines )
1334
+ self ._log_output = [] # type: List[str]
1340
1335
1341
- def _getlines (self , lines2 ) :
1336
+ def _getlines (self , lines2 : Union [ str , Sequence [ str ], Source ]) -> Sequence [ str ] :
1342
1337
if isinstance (lines2 , str ):
1343
1338
lines2 = Source (lines2 )
1344
1339
if isinstance (lines2 , Source ):
1345
1340
lines2 = lines2 .strip ().lines
1346
1341
return lines2
1347
1342
1348
- def fnmatch_lines_random (self , lines2 ) :
1343
+ def fnmatch_lines_random (self , lines2 : Sequence [ str ]) -> None :
1349
1344
"""Check lines exist in the output using in any order.
1350
1345
1351
1346
Lines are checked using ``fnmatch.fnmatch``. The argument is a list of
1352
1347
lines which have to occur in the output, in any order.
1353
-
1354
1348
"""
1355
1349
self ._match_lines_random (lines2 , fnmatch )
1356
1350
1357
- def re_match_lines_random (self , lines2 ) :
1351
+ def re_match_lines_random (self , lines2 : Sequence [ str ]) -> None :
1358
1352
"""Check lines exist in the output using ``re.match``, in any order.
1359
1353
1360
1354
The argument is a list of lines which have to occur in the output, in
1361
1355
any order.
1362
-
1363
1356
"""
1364
- self ._match_lines_random (lines2 , lambda name , pat : re .match (pat , name ))
1357
+ self ._match_lines_random (lines2 , lambda name , pat : bool ( re .match (pat , name ) ))
1365
1358
1366
- def _match_lines_random (self , lines2 , match_func ):
1359
+ def _match_lines_random (
1360
+ self , lines2 : Sequence [str ], match_func : Callable [[str , str ], bool ]
1361
+ ) -> None :
1367
1362
"""Check lines exist in the output.
1368
1363
1369
1364
The argument is a list of lines which have to occur in the output, in
1370
1365
any order. Each line can contain glob whildcards.
1371
-
1372
1366
"""
1373
1367
lines2 = self ._getlines (lines2 )
1374
1368
for line in lines2 :
@@ -1380,25 +1374,24 @@ def _match_lines_random(self, lines2, match_func):
1380
1374
self ._log ("line %r not found in output" % line )
1381
1375
raise ValueError (self ._log_text )
1382
1376
1383
- def get_lines_after (self , fnline ) :
1377
+ def get_lines_after (self , fnline : str ) -> Sequence [ str ] :
1384
1378
"""Return all lines following the given line in the text.
1385
1379
1386
1380
The given line can contain glob wildcards.
1387
-
1388
1381
"""
1389
1382
for i , line in enumerate (self .lines ):
1390
1383
if fnline == line or fnmatch (line , fnline ):
1391
1384
return self .lines [i + 1 :]
1392
1385
raise ValueError ("line %r not found in output" % fnline )
1393
1386
1394
- def _log (self , * args ):
1387
+ def _log (self , * args ) -> None :
1395
1388
self ._log_output .append (" " .join (str (x ) for x in args ))
1396
1389
1397
1390
@property
1398
- def _log_text (self ):
1391
+ def _log_text (self ) -> str :
1399
1392
return "\n " .join (self ._log_output )
1400
1393
1401
- def fnmatch_lines (self , lines2 ) :
1394
+ def fnmatch_lines (self , lines2 : Sequence [ str ]) -> None :
1402
1395
"""Search captured text for matching lines using ``fnmatch.fnmatch``.
1403
1396
1404
1397
The argument is a list of lines which have to match and can use glob
@@ -1408,7 +1401,7 @@ def fnmatch_lines(self, lines2):
1408
1401
__tracebackhide__ = True
1409
1402
self ._match_lines (lines2 , fnmatch , "fnmatch" )
1410
1403
1411
- def re_match_lines (self , lines2 ) :
1404
+ def re_match_lines (self , lines2 : Sequence [ str ]) -> None :
1412
1405
"""Search captured text for matching lines using ``re.match``.
1413
1406
1414
1407
The argument is a list of lines which have to match using ``re.match``.
@@ -1417,9 +1410,16 @@ def re_match_lines(self, lines2):
1417
1410
The matches and non-matches are also shown as part of the error message.
1418
1411
"""
1419
1412
__tracebackhide__ = True
1420
- self ._match_lines (lines2 , lambda name , pat : re .match (pat , name ), "re.match" )
1413
+ self ._match_lines (
1414
+ lines2 , lambda name , pat : bool (re .match (pat , name )), "re.match"
1415
+ )
1421
1416
1422
- def _match_lines (self , lines2 , match_func , match_nickname ):
1417
+ def _match_lines (
1418
+ self ,
1419
+ lines2 : Sequence [str ],
1420
+ match_func : Callable [[str , str ], bool ],
1421
+ match_nickname : str ,
1422
+ ) -> None :
1423
1423
"""Underlying implementation of ``fnmatch_lines`` and ``re_match_lines``.
1424
1424
1425
1425
:param list[str] lines2: list of string patterns to match. The actual
@@ -1465,23 +1465,27 @@ def _match_lines(self, lines2, match_func, match_nickname):
1465
1465
self ._fail (msg )
1466
1466
self ._log_output = []
1467
1467
1468
- def no_fnmatch_line (self , pat ) :
1468
+ def no_fnmatch_line (self , pat : str ) -> None :
1469
1469
"""Ensure captured lines do not match the given pattern, using ``fnmatch.fnmatch``.
1470
1470
1471
1471
:param str pat: the pattern to match lines.
1472
1472
"""
1473
1473
__tracebackhide__ = True
1474
1474
self ._no_match_line (pat , fnmatch , "fnmatch" )
1475
1475
1476
- def no_re_match_line (self , pat ) :
1476
+ def no_re_match_line (self , pat : str ) -> None :
1477
1477
"""Ensure captured lines do not match the given pattern, using ``re.match``.
1478
1478
1479
1479
:param str pat: the regular expression to match lines.
1480
1480
"""
1481
1481
__tracebackhide__ = True
1482
- self ._no_match_line (pat , lambda name , pat : re .match (pat , name ), "re.match" )
1482
+ self ._no_match_line (
1483
+ pat , lambda name , pat : bool (re .match (pat , name )), "re.match"
1484
+ )
1483
1485
1484
- def _no_match_line (self , pat , match_func , match_nickname ):
1486
+ def _no_match_line (
1487
+ self , pat : str , match_func : Callable [[str , str ], bool ], match_nickname : str
1488
+ ) -> None :
1485
1489
"""Ensure captured lines does not have a the given pattern, using ``fnmatch.fnmatch``
1486
1490
1487
1491
:param str pat: the pattern to match lines
@@ -1502,8 +1506,12 @@ def _no_match_line(self, pat, match_func, match_nickname):
1502
1506
self ._log ("{:>{width}}" .format ("and:" , width = wnick ), repr (line ))
1503
1507
self ._log_output = []
1504
1508
1505
- def _fail (self , msg ) :
1509
+ def _fail (self , msg : str ) -> None :
1506
1510
__tracebackhide__ = True
1507
1511
log_text = self ._log_text
1508
1512
self ._log_output = []
1509
1513
pytest .fail (log_text )
1514
+
1515
+ def str (self ) -> str :
1516
+ """Return the entire original text."""
1517
+ return "\n " .join (self .lines )
0 commit comments