Revision | cb490d24024846fec14ab6c49defe4c2a7f41bcd (tree) |
---|---|
Time | 2022-07-06 04:44:03 |
Author | Antoon Pardon <aej@pard...> |
Commiter | Antoon Pardon |
generalising the postmortem call
@@ -5,3 +5,4 @@ | ||
5 | 5 | .*.sw? |
6 | 6 | documentation/ |
7 | 7 | .* |
8 | +waiting-room/ |
@@ -1,3 +1,3 @@ | ||
1 | -version = '0.01.04h' | |
2 | -modified = '2022-07-03 @ 13:26:36' | |
1 | +version = '0.01.05a' | |
2 | +modified = '2022-07-05 @ 21:43:28' | |
3 | 3 | installed = '*********************' |
@@ -2,15 +2,17 @@ | ||
2 | 2 | This modules contains a number of functions that are useful during the startup of the program |
3 | 3 | """ |
4 | 4 | |
5 | -from typing import List, Callable | |
5 | +# pylint: disable=unused-import | |
6 | +from typing import List, Callable, Any | |
6 | 7 | import sys |
7 | 8 | |
8 | -def postmortem_main(main: Callable[[List[str]], int]) -> None: | |
9 | +def postmortem_call(call: Callable[[tuple], Any], args: tuple) -> None: | |
9 | 10 | """ |
10 | 11 | Use this function if you would like to have a more useful traceback or postmortum dump |
11 | 12 | of your program. Just call it with the main function of your application |
12 | 13 | """ |
14 | + # pylint: disable=broad-except | |
13 | 15 | try: |
14 | - main(sys.argv) | |
15 | - except ValueError: | |
16 | - sys.stderr.write('\n') | |
16 | + call(*args) | |
17 | + except Exception as err: | |
18 | + sys.stderr.write("%s('%s')\n" % (type(err).__name__, err)) |
@@ -3,12 +3,12 @@ | ||
3 | 3 | # pylint: disable=no-self-argument,self-assigning-variable |
4 | 4 | |
5 | 5 | from unittest import TestCase, main as unitmain #, skip |
6 | -from typing import List | |
6 | +#from typing import List, Any | |
7 | 7 | from contextlib import redirect_stderr |
8 | 8 | from io import StringIO |
9 | 9 | |
10 | 10 | # pylint: disable=unused-import |
11 | -from AGPlib.startersup import postmortem_main | |
11 | +from AGPlib.startersup import postmortem_call | |
12 | 12 | # pylint: enable=unused-import |
13 | 13 | |
14 | 14 | class PostmortemTest(TestCase): |
@@ -17,19 +17,19 @@ | ||
17 | 17 | """ |
18 | 18 | |
19 | 19 | def test_do_nothing(s): |
20 | - def do_nothing(argv: List[str]): | |
21 | - argv = argv | |
20 | + def do_nothing(): | |
21 | + pass | |
22 | 22 | |
23 | 23 | with redirect_stderr(StringIO()) as redirected_stderr: |
24 | - postmortem_main(do_nothing) | |
24 | + postmortem_call(do_nothing, ()) | |
25 | 25 | s.assertEqual(redirected_stderr.getvalue(), '') |
26 | 26 | |
27 | 27 | def test_ValueException(s): |
28 | - def Raise_ValueException(argv: List[str]): | |
29 | - raise ValueError("Something wrong with {}\n".format(argv[0])) | |
28 | + def Raise_Exception(exception): | |
29 | + raise exception | |
30 | 30 | |
31 | 31 | with redirect_stderr(StringIO()) as redirected_stderr: |
32 | - postmortem_main(Raise_ValueException) | |
33 | - s.assertEqual(redirected_stderr.getvalue(), '\n') | |
32 | + postmortem_call(Raise_Exception, (ValueError('Wrong Value'),)) | |
33 | + s.assertEqual(redirected_stderr.getvalue(), "ValueError('Wrong Value')\n") | |
34 | 34 | |
35 | 35 | unitmain() |