Forking what is left of ZeroNet and hopefully adding an AT Proto Frontend/Proxy
at main 52 lines 2.6 kB view raw
1from Debug import Debug 2import gevent 3import os 4import re 5 6import pytest 7 8 9class TestDebug: 10 @pytest.mark.parametrize("items,expected", [ 11 (["@/src/A/B/C.py:17"], ["A/B/C.py line 17"]), # basic test 12 (["@/src/Db/Db.py:17"], ["Db.py line 17"]), # path compression 13 (["%s:1" % __file__], ["TestDebug.py line 1"]), 14 (["@/plugins/Chart/ChartDb.py:100"], ["ChartDb.py line 100"]), # plugins 15 (["@/main.py:17"], ["main.py line 17"]), # root 16 (["@\\src\\Db\\__init__.py:17"], ["Db/__init__.py line 17"]), # Windows paths 17 (["<frozen importlib._bootstrap>:1"], []), # importlib builtins 18 (["<frozen importlib._bootstrap_external>:1"], []), # importlib builtins 19 (["/home/ivanq/ZeroNet/src/main.py:13"], ["?/src/main.py line 13"]), # best-effort anonymization 20 (["C:\\ZeroNet\\core\\src\\main.py:13"], ["?/src/main.py line 13"]), 21 (["/root/main.py:17"], ["/root/main.py line 17"]), 22 (["{gevent}:13"], ["<gevent>/__init__.py line 13"]), # modules 23 (["{os}:13"], ["<os> line 13"]), # python builtin modules 24 (["src/gevent/event.py:17"], ["<gevent>/event.py line 17"]), # gevent-overriden __file__ 25 (["@/src/Db/Db.py:17", "@/src/Db/DbQuery.py:1"], ["Db.py line 17", "DbQuery.py line 1"]), # mutliple args 26 (["@/src/Db/Db.py:17", "@/src/Db/Db.py:1"], ["Db.py line 17", "1"]), # same file 27 (["{os}:1", "@/src/Db/Db.py:17"], ["<os> line 1", "Db.py line 17"]), # builtins 28 (["{gevent}:1"] + ["{os}:3"] * 4 + ["@/src/Db/Db.py:17"], ["<gevent>/__init__.py line 1", "...", "Db.py line 17"]) 29 ]) 30 def testFormatTraceback(self, items, expected): 31 q_items = [] 32 for item in items: 33 file, line = item.rsplit(":", 1) 34 if file.startswith("@"): 35 file = Debug.root_dir + file[1:] 36 file = file.replace("{os}", os.__file__) 37 file = file.replace("{gevent}", gevent.__file__) 38 q_items.append((file, int(line))) 39 assert Debug.formatTraceback(q_items) == expected 40 41 def testFormatException(self): 42 try: 43 raise ValueError("Test exception") 44 except Exception: 45 assert re.match(r"ValueError: Test exception in TestDebug.py line [0-9]+", Debug.formatException()) 46 try: 47 os.path.abspath(1) 48 except Exception: 49 assert re.search(r"in TestDebug.py line [0-9]+ > <(posixpath|ntpath)> line ", Debug.formatException()) 50 51 def testFormatStack(self): 52 assert re.match(r"TestDebug.py line [0-9]+ > <_pytest>/python.py line [0-9]+", Debug.formatStack())