Skip to content

Commit defb45e

Browse files
tweak to apese deepsource padantics.
1 parent 1b4734b commit defb45e

File tree

3 files changed

+52
-42
lines changed

3 files changed

+52
-42
lines changed

tests/__init__.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,8 @@
3737
if test_basic.__name__ is None:
3838
raise ImportError(str("Test module failed to import even the basic tests."))
3939
except Exception as badErr:
40-
print(str(''))
41-
print(str(type(badErr)))
42-
print(str(badErr))
43-
print(str((badErr.args)))
44-
print(str(''))
45-
badErr = None
46-
del badErr
47-
exit(0)
40+
baton = ImportError(badErr, str("[CWE-758] Test module failed completely."))
41+
baton.module = __module__
42+
baton.path = __file__
43+
baton.__cause__ = badErr
44+
raise baton

tests/context.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@
2222
import os
2323
if 'pythonrepo' in __file__:
2424
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
25-
except Exception as ImportErr:
26-
print(str(type(ImportErr)))
27-
print(str(ImportErr))
28-
print(str((ImportErr.args)))
29-
ImportErr = None
30-
del ImportErr
31-
raise ImportError("Python Repo Failed to Import")
25+
except Exception as badErr:
26+
baton = ImportError(badErr, str("[CWE-758] Test module failed completely."))
27+
baton.module = __module__
28+
baton.path = __file__
29+
baton.__cause__ = badErr
30+
raise baton
3231

3332

3433
try:
3534
import pythonrepo as pythonrepo
3635
if pythonrepo.__name__ is None:
3736
raise ImportError("Failed to import pythonrepo.")
38-
except Exception as importErr:
39-
importErr = None
40-
del importErr
41-
raise ImportError("Test module failed to load pythonrepo for test.")
42-
exit(0)
37+
except Exception as badErr:
38+
baton = ImportError(badErr, str("[CWE-758] Test module failed to load pythonrepo for test."))
39+
baton.module = __module__
40+
baton.path = __file__
41+
baton.__cause__ = badErr
42+
raise baton

tests/profiling.py

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,52 +33,65 @@
3333
import sys
3434
if sys.__name__ is None: # pragma: no branch
3535
raise ImportError("[CWE-758] OMG! we could not import sys! ABORT. ABORT.")
36-
except Exception as err: # pragma: no branch
37-
raise ImportError(err)
36+
except Exception as badErr: # pragma: no branch
37+
baton = ImportError(badErr, str("[CWE-758] Test module failed completely."))
38+
baton.module = __module__
39+
baton.path = __file__
40+
baton.__cause__ = badErr
41+
raise baton
3842

3943

4044
try:
4145
if 'os' not in sys.modules:
4246
import os
4347
else: # pragma: no branch
4448
os = sys.modules["""os"""]
45-
except Exception: # pragma: no branch
46-
raise ImportError("[CWE-758] OS Failed to import.")
49+
except Exception as badErr: # pragma: no branch
50+
baton = ImportError(badErr, str("[CWE-758] Test module failed completely."))
51+
baton.module = __module__
52+
baton.path = __file__
53+
baton.__cause__ = badErr
54+
raise baton
4755

4856

4957
try:
5058
import time
5159
if time.__name__ is None: # pragma: no branch
5260
raise NotImplementedError("[CWE-440] We could not import time. Are we in the speed-force!")
53-
except Exception as err:
54-
raise ImportError(err)
55-
exit(3)
61+
except Exception as badErr: # pragma: no branch
62+
baton = ImportError(badErr, str("[CWE-758] Test module failed completely."))
63+
baton.module = __module__
64+
baton.path = __file__
65+
baton.__cause__ = badErr
66+
raise baton
5667

5768

5869
try:
59-
import cProfile
60-
if cProfile.__name__ is None: # pragma: no branch
61-
raise NotImplementedError("[CWE-440] We could not import cProfile. ABORT!")
62-
except Exception as err: # pragma: no branch
63-
raise ImportError(err)
64-
exit(3)
70+
if 'cProfile' not in sys.modules:
71+
import cProfile
72+
else: # pragma: no branch
73+
cProfile = sys.modules["""cProfile"""]
74+
except Exception as badErr: # pragma: no branch
75+
baton = ImportError(badErr, str("[CWE-758] Test module failed completely."))
76+
baton.module = __module__
77+
baton.path = __file__
78+
baton.__cause__ = badErr
79+
raise baton
6580

6681

6782
try:
6883
try:
6984
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), str('..'))))
7085
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), str('.'))))
7186
except Exception as ImportErr: # pragma: no branch
72-
print(str(''))
73-
print(str(type(ImportErr)))
74-
print(str(ImportErr))
75-
print(str((ImportErr.args)))
76-
print(str(''))
77-
ImportErr = None
78-
del ImportErr
87+
7988
raise ImportError(str("[CWE-758] Profile module failed completely."))
80-
except Exception: # pragma: no branch
81-
raise ImportError("[CWE-440] Failed to import test profiling")
89+
except Exception as badErr: # pragma: no branch
90+
baton = ImportError(badErr, str("[CWE-758] Test module failed completely."))
91+
baton.module = __module__
92+
baton.path = __file__
93+
baton.__cause__ = badErr
94+
raise baton
8295

8396

8497
class timewith():

0 commit comments

Comments
 (0)