Commit MetaInfo

Revisioncb490d24024846fec14ab6c49defe4c2a7f41bcd (tree)
Time2022-07-06 04:44:03
AuthorAntoon Pardon <aej@pard...>
CommiterAntoon Pardon

Log Message

generalising the postmortem call

Change Summary

Incremental Difference

diff -r cdd63674fa3e -r cb490d240248 .hgignore
--- a/.hgignore Sun Jul 03 13:26:36 2022 +0200
+++ b/.hgignore Tue Jul 05 21:44:03 2022 +0200
@@ -5,3 +5,4 @@
55 .*.sw?
66 documentation/
77 .*
8+waiting-room/
diff -r cdd63674fa3e -r cb490d240248 source/release.cfg
--- a/source/release.cfg Sun Jul 03 13:26:36 2022 +0200
+++ b/source/release.cfg Tue Jul 05 21:44:03 2022 +0200
@@ -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'
33 installed = '*********************'
diff -r cdd63674fa3e -r cb490d240248 source/startersup.py
--- a/source/startersup.py Sun Jul 03 13:26:36 2022 +0200
+++ b/source/startersup.py Tue Jul 05 21:44:03 2022 +0200
@@ -2,15 +2,17 @@
22 This modules contains a number of functions that are useful during the startup of the program
33 """
44
5-from typing import List, Callable
5+# pylint: disable=unused-import
6+from typing import List, Callable, Any
67 import sys
78
8-def postmortem_main(main: Callable[[List[str]], int]) -> None:
9+def postmortem_call(call: Callable[[tuple], Any], args: tuple) -> None:
910 """
1011 Use this function if you would like to have a more useful traceback or postmortum dump
1112 of your program. Just call it with the main function of your application
1213 """
14+ # pylint: disable=broad-except
1315 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))
diff -r cdd63674fa3e -r cb490d240248 tests/startersup.py
--- a/tests/startersup.py Sun Jul 03 13:26:36 2022 +0200
+++ b/tests/startersup.py Tue Jul 05 21:44:03 2022 +0200
@@ -3,12 +3,12 @@
33 # pylint: disable=no-self-argument,self-assigning-variable
44
55 from unittest import TestCase, main as unitmain #, skip
6-from typing import List
6+#from typing import List, Any
77 from contextlib import redirect_stderr
88 from io import StringIO
99
1010 # pylint: disable=unused-import
11-from AGPlib.startersup import postmortem_main
11+from AGPlib.startersup import postmortem_call
1212 # pylint: enable=unused-import
1313
1414 class PostmortemTest(TestCase):
@@ -17,19 +17,19 @@
1717 """
1818
1919 def test_do_nothing(s):
20- def do_nothing(argv: List[str]):
21- argv = argv
20+ def do_nothing():
21+ pass
2222
2323 with redirect_stderr(StringIO()) as redirected_stderr:
24- postmortem_main(do_nothing)
24+ postmortem_call(do_nothing, ())
2525 s.assertEqual(redirected_stderr.getvalue(), '')
2626
2727 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
3030
3131 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")
3434
3535 unitmain()
Show on old repository browser