Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
Unreleased
----------

* Ignore unrelated warnings from MDAnalysis
* Added argcomplete for tab completion
* Updated docs

Expand Down
2 changes: 1 addition & 1 deletion src/mdacli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def main():

mdacli.cli(
name="MDAnalysis",
module_list=[f"MDAnalysis.analysis.{m}" for m in __all__],
module_list=[f"MDAnalysis.analysis.{m}" for m in __all__ if m != "hbonds"],
version=mdacli.__version__,
description=__doc__,
skip_modules=skip_mods,
Expand Down
2 changes: 1 addition & 1 deletion src/mdacli/libcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def find_cls_members(cls, modules, ignore_warnings=False):
Flag to ignore warnings
"""
with warnings.catch_warnings():
if not ignore_warnings:
Copy link
Collaborator

Choose a reason for hiding this comment

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

hahaha this was easy.

Maybe we add a test for the ignore_warnings switch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

?
should I add a test regarding this - about ignoring warnings?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah basically, running this function once with ignore_warnings=True (checking that no warning will be emitted) and once with ignore_warnings=False (checking that a warning with pytest.warns is emitted)

if ignore_warnings:
warnings.simplefilter("ignore")
return find_classes_in_modules(cls, *[m for m in modules])

Expand Down
45 changes: 45 additions & 0 deletions tests/test_libcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import logging
import os
import sys
import warnings
from io import StringIO
from json.decoder import JSONDecodeError
from pathlib import Path
Expand Down Expand Up @@ -125,6 +126,50 @@ def test_find_cls_members_single(cls):
assert members[1] is InterRDF_s


def test_find_cls_members_ignore_warnings_true():
"""Test that warnings are suppressed when ignore_warnings=True."""
with patch("mdacli.libcli.find_classes_in_modules") as mocked:

def warn_func(*_args, **_kwargs):
warnings.warn("warning", DeprecationWarning, stacklevel=2)
return ["OK"]

mocked.side_effect = warn_func

with warnings.catch_warnings():
warnings.simplefilter("error")

members = find_cls_members(
AnalysisBase,
modules=["dummy.mod"],
ignore_warnings=True,
)

assert members == ["OK"]


def test_find_cls_members_ignore_warnings_false():
"""Test that warnings are emitted when ignore_warnings=False."""
with patch("mdacli.libcli.find_classes_in_modules") as mocked:

def warn_func(*_args, **_kwargs):
warnings.warn(
"This module was moved to ...", DeprecationWarning, stacklevel=2
)
return ["OK"]

mocked.side_effect = warn_func

with pytest.warns(DeprecationWarning, match="moved to"):
members = find_cls_members(
AnalysisBase,
modules=["dummy.mod"],
ignore_warnings=False,
)

assert members == ["OK"]


@pytest.mark.parametrize(
"cls", [AnalysisBase, [AnalysisBase, AnalysisBase], (AnalysisBase, AnalysisBase)]
)
Expand Down