• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

reactive-firewall-org / multicast / 16583975596

22 Jul 2025 10:18PM UTC coverage: 27.998% (-69.1%) from 97.128%
16583975596

push

github

reactive-firewall
[FIX] Initial Tuning of over limited concurancy settings

Changes in file .github/workflows/CI-BUILD.yml:
 * Removed limits reverting to previous LGV

Changes in file .github/workflows/CI-CHGLOG.yml:
 * Removed limits reverting to previous LGV

Changes in file .github/workflows/CI-DOCS.yml:
 * Removed limits reverting to previous LGV

Changes in file .github/workflows/CI-MATs.yml:
 * Removed limits reverting to previous LGV

Changes in file .github/workflows/Tests.yml:
 * Removed limits (kept throttling)

Changes in file .github/workflows/bandit.yml:
 * Removed limits reverting to previous LGV

Changes in file .github/workflows/codeql-analysis.yml:
 * Retuned limit for schedule runs

Changes in file .github/workflows/flake8.yml:
 * Removed limits reverting to previous LGV

Changes in file .github/workflows/makefile-lint.yml:
 * Removed limits reverting to previous LGV

Changes in file .github/workflows/markdown-lint.yml:
 * Removed limits reverting to previous LGV

Changes in file .github/workflows/scorecard.yml:
 * Retuned limit for schedule runs

Changes in file .github/workflows/shellcheck.yml:
 * Removed limits reverting to previous LGV

37 of 133 branches covered (27.82%)

Branch coverage included in aggregate %.

626 of 2235 relevant lines covered (28.01%)

0.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/tests/profiling.py
1
#! /usr/bin/env python
2
# -*- coding: utf-8 -*-
3

4
# Python Test Repo Template
5
# ..................................
6
# Copyright (c) 2017-2025, Mr. Walls
7
# ..................................
8
# Licensed under MIT (the "License");
9
# you may not use this file except in compliance with the License.
10
# You may obtain a copy of the License at
11
# ..........................................
12
# https://github.com/reactive-firewall/python-repo/blob/HEAD/LICENSE.md
13
# ..........................................
14
# Unless required by applicable law or agreed to in writing, software
15
# distributed under the License is distributed on an "AS IS" BASIS,
16
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
# See the License for the specific language governing permissions and
18
# limitations under the License.
19

20
# Third-party Acknowledgement:
21
# ..........................................
22
# Some code (namely: class timewith, @do_cprofile, @do_line_profile) was modified/derived from:
23
# https://github.com/zapier/profiling-python-like-a-boss/tree/1ab93a1154
24
# Copyright (c) 2013, Zapier Inc. All rights reserved.
25
# which was under BSD-3 Clause license.
26
# see https://github.com/zapier/profiling-python-like-a-boss/blob/1ab93a1154/LICENSE.md for details
27
# ..........................................
28
# NO ASSOCIATION
29

30
__module__ = "tests.profiling"
×
31
"""This is pythonrepo testing module Template."""
×
32

33
try:
×
34
        import sys
×
35
        if not hasattr(sys, 'modules') or not sys.modules:  # pragma: no branch
36
                raise ModuleNotFoundError(
37
                        "[CWE-440] OMG! sys.modules is not available or empty.",
38
                ) from None
39
except ImportError as _cause:
40
        raise ImportError("[CWE-440] Unable to import sys module.") from _cause
41

42
try:
×
43
        if 'os' not in sys.modules:
44
                import os
45
        else:  # pragma: no branch
46
                os = sys.modules["os"]
47
except Exception as _cause:  # pragma: no branch
48
        baton = ModuleNotFoundError(_cause, str("[CWE-758] Test module failed completely."))
49
        baton.module = __module__
50
        baton.path = __file__
51
        baton.__cause__ = _cause
52
        raise baton from _cause
53

54
try:
×
55
        if 'functools' not in sys.modules:
56
                import functools
57
        else:  # pragma: no branch
58
                functools = sys.modules["functools"]
59
except Exception as _cause:  # pragma: no branch
60
        baton = ModuleNotFoundError(_cause, str("[CWE-758] Test module failed completely."))
61
        baton.module = __module__
62
        baton.path = __file__
63
        baton.__cause__ = _cause
64
        raise baton from _cause
65

66
try:
×
67
        import time
×
68
        if time.__name__ is None:  # pragma: no branch
×
69
                raise NotImplementedError("[CWE-440] We could not import time. Are we in the speed-force!")
70
except Exception as _cause:  # pragma: no branch
71
        baton = ImportError(_cause, str("[CWE-758] Test module failed completely."))
72
        baton.module = __module__
73
        baton.path = __file__
74
        baton.__cause__ = _cause
75
        raise baton from _cause
76

77
try:
×
78
        if 'cProfile' not in sys.modules:
79
                import cProfile
80
        else:  # pragma: no branch
81
                cProfile = sys.modules["cProfile"]
82
except Exception as _cause:  # pragma: no branch
83
        baton = ModuleNotFoundError(_cause, str("[CWE-758] Test module failed completely."))
84
        baton.module = __module__
85
        baton.path = __file__
86
        baton.__cause__ = _cause
87
        raise baton from _cause
88

89
try:
×
90
        try:
×
91
                sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), str('..'))))
×
92
                sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), str('.'))))
×
93
        except Exception as _root_cause:  # pragma: no branch
94
                raise ImportError(
95
                        _root_cause, str("[CWE-758] Profile module failed completely."),
96
                ) from _root_cause
97
except Exception as _cause:  # pragma: no branch
98
        baton = ImportError(_cause, str("[CWE-758] Test module failed completely."))
99
        baton.module = __module__
100
        baton.path = __file__
101
        baton.__cause__ = _cause
102
        raise baton from _cause
103

104

105
class timewith():
×
106
        """Basic timer for do_time_profile."""
107

108
        def __init__(self, name=""):
×
109
                self.name = name
×
110
                self.start = time.time()
×
111

112
        @property
×
113
        def elapsed(self):
×
114
                return time.time() - self.start
×
115

116
        def checkpoint(self, name=""):
×
117
                print(
×
118
                        str(f"{self.name} {name} took {self.elapsed} seconds").strip()
119
                )
120

121
        def __enter__(self):
×
122
                return self
×
123

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

127

128
def do_time_profile(func, timer_name="time_profile"):
×
129
        """Run a function with a timer.
130

131
        Time Testing:
132

133
                First some test fixtures:
134

135
                >>> import tests.context as context
136
                >>> from context import profiling as profiling
137
                >>>
138

139
        Testcase 0: test the time_profile.
140

141
                >>> def doWork():
142
                ...    \"""Does some work.\"""
143
                ...    for i in range(0, 42):
144
                ...        print(str("Do Task {}").format(int(i)))
145
                >>>
146
                >>> profiling.do_time_profile(
147
                ...    doWork,
148
                ...    timer_name=str("work time test")
149
                ... )() #doctest: -DONT_ACCEPT_BLANKLINE, +ELLIPSIS
150
                work...Start Timer...
151
                ...Do Task...
152
                work...Stop Timer...
153
                work...took ... seconds
154
                >>>
155

156
        """
157
        @functools.wraps(func)
×
158
        def timer_profile_func(*args, **kwargs):
×
159
                """Wraps a function in timewith() function."""
160
                theOutput = None
×
161
                with timewith(timer_name) as timer:
×
162
                        timer.checkpoint(str("Start Timer"))
×
163
                        theOutput = func(*args, **kwargs)
×
164
                        timer.checkpoint(str("Stop Timer"))
×
165
                return theOutput
×
166
        return timer_profile_func
×
167

168

169
def do_cprofile(func):
×
170
        """Use built-in profiler to profile.
171

172
        Time Testing:
173

174
                First some test fixtures:
175

176
                >>> import tests.context as context
177
                >>> from context import profiling as profiling
178
                >>>
179

180
        Testcase 0: test the time_profile.
181

182
                >>> def doWork():
183
                ...    \"""Does some work.\"""
184
                ...    for i in range(0, 42):
185
                ...        print(str("Do Task {}").format(int(i)))
186
                >>>
187
                >>> profiling.do_cprofile(
188
                ...    doWork
189
                ... )() #doctest: -DONT_ACCEPT_BLANKLINE, +ELLIPSIS
190
                Do Task 0...Do Task 10...Do Task 20...Do Task 30...Do Task 40...
191
                ...function calls in ... seconds...Ordered by: standard name...
192
                ...ncalls  tottime  percall  cumtime  percall filename:lineno(function)...
193
                ...<...>:1(doWork)...{built-in method builtins.print}...
194
                <BLANKLINE>
195
                <BLANKLINE>
196
                >>>
197

198
        """
199
        @functools.wraps(func)
×
200
        def profiled_func(*args, **kwargs):
×
201
                """Wraps a function in profile.enable/disable() functions."""
202
                profile = cProfile.Profile()
×
203
                try:
×
204
                        profile.enable()
×
205
                        result = func(*args, **kwargs)
×
206
                        profile.disable()
×
207
                        return result
×
208
                finally:
209
                        profile.print_stats()
×
210
        return profiled_func
×
211

212

213
try:  # noqa
×
214
        from line_profiler import LineProfiler
×
215

216
        def do_profile(follow=None):  # pragma: no cover
217
                if follow is None:
218
                        follow = []
219

220
                def inner(func):
221
                        def profiled_func(*args, **kwargs):
222
                                try:
223
                                        profiler = LineProfiler()
224
                                        profiler.add_function(func)
225
                                        for f in follow:
226
                                                profiler.add_function(f)
227
                                        profiler.enable_by_count()
228
                                        return func(*args, **kwargs)
229
                                finally:
230
                                        profiler.print_stats()
231
                        return profiled_func
232
                return inner
233

234
except ImportError:  # pragma: no cover
235
        def do_profile(follow=None):
236
                "Helpful if you accidentally leave in production!"
237
                if follow is None:
238
                        follow = []
239

240
                def inner(func):
241
                        def nothing(*args, **kwargs):
242
                                return func(*args, **kwargs)
243
                        return nothing
244
                return inner
245

246

247
def main(*argv):  # pragma: no cover
248
        """The Main Event makes no sense to profiling."""
249
        raise NotImplementedError("CRITICAL - test profiling main() not implemented. yet?") from None
250

251

252
if __name__ in '__main__':  # pragma: no cover
253
        exitcode = 2
254
        try:
255
                exitcode = main(sys.argv[1:])
256
        finally:
257
                exit(exitcode)  # skipcq: PYL-R1722 - intentionally allow overwriteing exit for testing
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc