Skip to content

Commit 92c9f39

Browse files
Merge branch 'add-ignore-module-cli-option'
2 parents 3c205b5 + 5e7f5c0 commit 92c9f39

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/pynguin/analyses/module.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import astroid
3434

35+
import pynguin.configuration as config
3536
import pynguin.utils.statistics.statistics as stat
3637
import pynguin.utils.typetracing as tt
3738

@@ -85,7 +86,8 @@
8586

8687
LOGGER = logging.getLogger(__name__)
8788

88-
# A set of modules that shall be blacklisted from analysis (keep them sorted!!!):
89+
# A set of modules that shall be blacklisted from analysis (keep them sorted to ease
90+
# future manipulations or looking up module names of this set!!!):
8991
# The modules that are listed here are not prohibited from execution, but Pynguin will
9092
# not consider any classes or functions from these modules for generating inputs to
9193
# other routines
@@ -188,27 +190,30 @@ def _is_blacklisted(element: Any) -> bool:
188190
Returns:
189191
Is the element blacklisted?
190192
"""
193+
module_blacklist = set(MODULE_BLACKLIST).union(config.configuration.ignore_modules)
194+
method_blacklist = set(METHOD_BLACKLIST).union(config.configuration.ignore_methods)
195+
191196
if inspect.ismodule(element):
192-
return element.__name__ in MODULE_BLACKLIST
197+
return element.__name__ in module_blacklist
193198
if inspect.isclass(element):
194199
if element.__module__ == "builtins" and (
195200
element in PRIMITIVES or element in COLLECTIONS
196201
):
197202
# Allow some builtin types
198203
return False
199-
return element.__module__ in MODULE_BLACKLIST
204+
return element.__module__ in module_blacklist
200205
if inspect.isfunction(element):
201206
# Some modules can be run standalone using a main function or provide a small
202207
# set of tests ('test'). We don't want to include those functions.
203208
return (
204-
element.__module__ in MODULE_BLACKLIST
209+
element.__module__ in module_blacklist
205210
or element.__qualname__.startswith(
206211
(
207212
"main",
208213
"test",
209214
)
210215
)
211-
or f"{element.__module__}.{element.__qualname__}" in METHOD_BLACKLIST
216+
or f"{element.__module__}.{element.__qualname__}" in method_blacklist
212217
)
213218
# Something that is not supported yet.
214219
return False

src/pynguin/configuration.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,12 @@ class Configuration:
627627
random: RandomConfiguration = dataclasses.field(default_factory=RandomConfiguration)
628628
"""Configuration used for the RANDOM algorithm."""
629629

630+
ignore_modules: list[str] = dataclasses.field(default_factory=list)
631+
"""Ignore the modules specified here from the module analysis."""
632+
633+
ignore_methods: list[str] = dataclasses.field(default_factory=list)
634+
"""Ignore the methods specified here from the module analysis."""
635+
630636

631637
# Singleton instance of the configuration.
632638
configuration = Configuration(

0 commit comments

Comments
 (0)