Skip to content

Commit

Permalink
[TESTS] Testing possible fix for PYL-C0414 (- WIP #80 -)
Browse files Browse the repository at this point in the history
### ChangeLog:

Changes in file tests/__init__.py:
 Unknown Changes

Changes in file tests/context.py:
 Unknown Changes

Changes in file tests/profiling.py:
 def checkpoint(self, name=''):
 def do_cprofile(func):
 def do_time_profile(func, timer_name="time_profile"):

Changes in file tests/test_basic.py:
 Unknown Changes

Changes in file tests/test_usage.py:
 Unknown Changes
  • Loading branch information
reactive-firewall committed Sep 11, 2024
1 parent c009b87 commit ff5a77e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 37 deletions.
3 changes: 2 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@


__module__ = """tests"""
"""This is multicast testing module."""

try:
import sys
Expand Down Expand Up @@ -86,7 +87,7 @@
sys.path.insert(0, os.path.abspath(os.path.join(_BASE_NAME, _PARENT_DIR_NAME)))
if 'tests' in __file__:
sys.path.insert(0, os.path.abspath(os.path.join(_BASE_NAME, _DIR_NAME)))
from tests import profiling as profiling
from tests import profiling as profiling # skipcq: PYL-C0414
from tests import test_basic
from tests import test_usage

Expand Down
4 changes: 2 additions & 2 deletions tests/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

try:
if 'Process' not in sys.modules:
from multiprocessing import Process as Process
from multiprocessing import Process as Process # skipcq: PYL-C0414
else: # pragma: no branch
Process = sys.modules["""Process"""]
except Exception: # pragma: no branch
Expand All @@ -100,7 +100,7 @@

try:
if 'tests.profiling' not in sys.modules:
import profiling as profiling
import tests.profiling as profiling
else: # pragma: no branch
profiling = sys.modules["""tests.profiling"""]
except Exception: # pragma: no branch
Expand Down
88 changes: 59 additions & 29 deletions tests/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,60 +29,90 @@
# NO ASSOCIATION


__module__ = """tests.profiling"""
"""This is pythonrepo testing module Template."""


try:
import sys
if sys.__name__ is None: # pragma: no branch
raise ImportError("[CWE-758] OMG! we could not import sys! ABORT. ABORT.")
except Exception as err: # pragma: no branch
raise ImportError(err)
except Exception as badErr: # pragma: no branch
baton = ImportError(badErr, str("[CWE-758] Test module failed completely."))
baton.module = __module__
baton.path = __file__
baton.__cause__ = badErr
raise baton


try:
if 'os' not in sys.modules:
import os
else: # pragma: no branch
os = sys.modules["""os"""]
except Exception: # pragma: no branch
raise ImportError("[CWE-758] OS Failed to import.")
except Exception as badErr: # pragma: no branch
baton = ImportError(badErr, str("[CWE-758] Test module failed completely."))
baton.module = __module__
baton.path = __file__
baton.__cause__ = badErr
raise baton


try:
if 'functools' not in sys.modules:
import functools
else: # pragma: no branch
functools = sys.modules["""functools"""]
except Exception as badErr: # pragma: no branch
baton = ImportError(badErr, str("[CWE-758] Test module failed completely."))
baton.module = __module__
baton.path = __file__
baton.__cause__ = badErr
raise baton


try:
import time
if time.__name__ is None: # pragma: no branch
raise NotImplementedError("[CWE-440] We could not import time. Are we in the speed-force!")
except Exception as err:
raise ImportError(err)
exit(3)
except Exception as badErr: # pragma: no branch
baton = ImportError(badErr, str("[CWE-758] Test module failed completely."))
baton.module = __module__
baton.path = __file__
baton.__cause__ = badErr
raise baton


try:
import cProfile
if cProfile.__name__ is None: # pragma: no branch
raise NotImplementedError("[CWE-440] We could not import cProfile. ABORT!")
except Exception as err: # pragma: no branch
raise ImportError(err)
exit(3)
if 'cProfile' not in sys.modules:
import cProfile
else: # pragma: no branch
cProfile = sys.modules["""cProfile"""]
except Exception as badErr: # pragma: no branch
baton = ImportError(badErr, str("[CWE-758] Test module failed completely."))
baton.module = __module__
baton.path = __file__
baton.__cause__ = badErr
raise baton


try:
try:
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), str('..'))))
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), str('.'))))
except Exception as ImportErr: # pragma: no branch
print(str(''))
print(str(type(ImportErr)))
print(str(ImportErr))
print(str((ImportErr.args)))
print(str(''))
ImportErr = None
del ImportErr
raise ImportError(str("[CWE-758] Profile module failed completely."))
except Exception: # pragma: no branch
raise ImportError("[CWE-440] Failed to import test profiling")
raise ImportError(ImportErr, str("[CWE-758] Profile module failed completely."))
except Exception as badErr: # pragma: no branch
baton = ImportError(badErr, str("[CWE-758] Test module failed completely."))
baton.module = __module__
baton.path = __file__
baton.__cause__ = badErr
raise baton


class timewith():
"""Basic timer for do_time_profile."""

def __init__(self, name=''):
self.name = name
self.start = time.time()
Expand All @@ -103,13 +133,12 @@ def checkpoint(self, name=''):
def __enter__(self):
return self

def __exit__(self, type, value, traceback):
def __exit__(self, type, value, traceback): # skipcq: PYL-W0622
self.checkpoint(str("finished"))
pass


def do_time_profile(func, timer_name="time_profile"):
"""Runs a function with a timer.
"""Run a function with a timer.
Time Testing:
Expand All @@ -136,12 +165,11 @@ def do_time_profile(func, timer_name="time_profile"):
work...took ... seconds
>>>
"""
import functools
"""
@functools.wraps(func)
def timer_profile_func(*args, **kwargs):
"""Wraps a function in timewith()"""
"""Wraps a function in timewith() function."""
theOutput = None
with timewith(timer_name) as timer:
timer.checkpoint(str("Start Timer"))
Expand Down Expand Up @@ -183,7 +211,9 @@ def do_cprofile(func):
"""
@functools.wraps(func)
def profiled_func(*args, **kwargs):
"""Wraps a function in profile.enable/disable() functions."""
profile = cProfile.Profile()
try:
profile.enable()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
if context.__name__ is None:
raise ImportError("[CWE-758] Failed to import context")
else:
from context import unittest as unittest
from context import unittest
from context import sys as _sys
except Exception: # pragma: no branch
raise ImportError("[CWE-758] Failed to import test context")
Expand Down
8 changes: 4 additions & 4 deletions tests/test_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
if context.__name__ is None:
raise ImportError("[CWE-758] Failed to import context")
else:
from context import multicast as multicast
from context import unittest as unittest
from context import subprocess as subprocess
from context import Process as Process
from context import multicast as multicast # skipcq: PYL-C0414
from context import unittest
from context import subprocess
from context import Process
except Exception:
raise ImportError("[CWE-758] Failed to import test context")

Expand Down

1 comment on commit ff5a77e

@reactive-firewall
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙊 OOPS! 🙈
This is NOT related to issue 80 rather it concerns issue #81

Please sign in to comment.