Mercurial > public > mercurial-scm > hg
annotate tests/filtertraceback.py @ 52430:31c4987034b9
tests: drop py2 support from `filtertraceback.py`
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 02 Dec 2024 12:52:39 -0500 |
parents | 8431296a93e8 |
children | 3afe0be4f4b7 |
rev | line source |
---|---|
45830
c102b704edb5
global: use python3 in shebangs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44654
diff
changeset
|
1 #!/usr/bin/env python3 |
41462
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 # Filters traceback lines from stdin. |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 |
44654
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
6 import io |
41462
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 import sys |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 |
52430
31c4987034b9
tests: drop py2 support from `filtertraceback.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52428
diff
changeset
|
9 # Prevent \r from being inserted on Windows. |
31c4987034b9
tests: drop py2 support from `filtertraceback.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52428
diff
changeset
|
10 sys.stdout = io.TextIOWrapper( |
31c4987034b9
tests: drop py2 support from `filtertraceback.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52428
diff
changeset
|
11 sys.stdout.buffer, |
31c4987034b9
tests: drop py2 support from `filtertraceback.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52428
diff
changeset
|
12 sys.stdout.encoding, |
31c4987034b9
tests: drop py2 support from `filtertraceback.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52428
diff
changeset
|
13 sys.stdout.errors, |
31c4987034b9
tests: drop py2 support from `filtertraceback.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52428
diff
changeset
|
14 newline="\n", |
31c4987034b9
tests: drop py2 support from `filtertraceback.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52428
diff
changeset
|
15 line_buffering=sys.stdout.line_buffering, |
31c4987034b9
tests: drop py2 support from `filtertraceback.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52428
diff
changeset
|
16 ) |
44654
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
17 |
41462
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
18 state = 'none' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
19 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
20 for line in sys.stdin: |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
21 if state == 'none': |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
22 if line.startswith('Traceback '): |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
23 state = 'tb' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
24 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 elif state == 'tb': |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
26 if line.startswith(' File '): |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
27 state = 'file' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
28 continue |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
30 elif not line.startswith(' '): |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
31 state = 'none' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 |
49869
fe044ce4bb17
tests: filter out PEP 657 error locations in tracebacks (issue6780)
Anton Shestakov <av6@dwimlabs.net>
parents:
48875
diff
changeset
|
33 elif not line.replace('^', '').replace('~', '').strip(): |
fe044ce4bb17
tests: filter out PEP 657 error locations in tracebacks (issue6780)
Anton Shestakov <av6@dwimlabs.net>
parents:
48875
diff
changeset
|
34 # PEP 657: Fine-grained error locations in tracebacks |
fe044ce4bb17
tests: filter out PEP 657 error locations in tracebacks (issue6780)
Anton Shestakov <av6@dwimlabs.net>
parents:
48875
diff
changeset
|
35 # ~~~~~~^^^^^^^^^ |
fe044ce4bb17
tests: filter out PEP 657 error locations in tracebacks (issue6780)
Anton Shestakov <av6@dwimlabs.net>
parents:
48875
diff
changeset
|
36 continue |
fe044ce4bb17
tests: filter out PEP 657 error locations in tracebacks (issue6780)
Anton Shestakov <av6@dwimlabs.net>
parents:
48875
diff
changeset
|
37 |
41462
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 elif state == 'file': |
52428
8431296a93e8
tests: fix `filtertraceback.py` to handle contiguous "File" lines
Matt Harbison <matt_harbison@yahoo.com>
parents:
49869
diff
changeset
|
39 # Ignore one line after " File ", but sometimes "File" lines are |
8431296a93e8
tests: fix `filtertraceback.py` to handle contiguous "File" lines
Matt Harbison <matt_harbison@yahoo.com>
parents:
49869
diff
changeset
|
40 # contiguous: |
8431296a93e8
tests: fix `filtertraceback.py` to handle contiguous "File" lines
Matt Harbison <matt_harbison@yahoo.com>
parents:
49869
diff
changeset
|
41 # File "<frozen importlib._bootstrap>", line 1007, in _find_and_load |
8431296a93e8
tests: fix `filtertraceback.py` to handle contiguous "File" lines
Matt Harbison <matt_harbison@yahoo.com>
parents:
49869
diff
changeset
|
42 # File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked |
8431296a93e8
tests: fix `filtertraceback.py` to handle contiguous "File" lines
Matt Harbison <matt_harbison@yahoo.com>
parents:
49869
diff
changeset
|
43 # File "<frozen importlib._bootstrap>", line 680, in _load_unlocked |
8431296a93e8
tests: fix `filtertraceback.py` to handle contiguous "File" lines
Matt Harbison <matt_harbison@yahoo.com>
parents:
49869
diff
changeset
|
44 if not line.startswith(' File '): |
8431296a93e8
tests: fix `filtertraceback.py` to handle contiguous "File" lines
Matt Harbison <matt_harbison@yahoo.com>
parents:
49869
diff
changeset
|
45 state = 'tb' |
41462
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 continue |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
47 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
48 print(line, end='') |