From 6e0002ab7902146898bfa7e485fc4fb138ff8cd9 Mon Sep 17 00:00:00 2001 From: Domagoj Fijan Date: Tue, 9 Apr 2024 13:20:23 -0400 Subject: [PATCH] more ruff fixes --- ConservedWaterSearch/utils.py | 2 +- tests/test_hydrogen_orientation.py | 10 ++++++---- tests/test_utils.py | 2 +- tests/test_water_clustering.py | 6 +++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/ConservedWaterSearch/utils.py b/ConservedWaterSearch/utils.py index 36492f2..869d9bd 100644 --- a/ConservedWaterSearch/utils.py +++ b/ConservedWaterSearch/utils.py @@ -693,7 +693,7 @@ def visualise_nglview( ) -> NGLWidget: """Creates a nglview visualisation widget for results. - Starts a `nglview `__ visualisation + Starts a `nglview `__ visualisation instance from clustering results. Args: diff --git a/tests/test_hydrogen_orientation.py b/tests/test_hydrogen_orientation.py index 65e8cc9..94b8325 100644 --- a/tests/test_hydrogen_orientation.py +++ b/tests/test_hydrogen_orientation.py @@ -25,7 +25,7 @@ def test_orientation_normalization(): def test_orientation_shape(): orientations = np.asarray([[[1]]]) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="Input array must be 2-dimensional"): ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( orientations ) @@ -33,7 +33,7 @@ def test_orientation_shape(): def test_orientation_dimensions(): orientations = np.asarray([[1, 0], [0, 1]]) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="Input array must have shape (N, 3)"): ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( orientations ) @@ -48,7 +48,7 @@ def test_orientation_valid_input(): def test_orientation_size(): orientations = np.asarray([[1, 0, 0]]) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="Input array must have shape (N, 3)"): ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( orientations ) @@ -56,7 +56,9 @@ def test_orientation_size(): def test_orientation_array_odd(): orientations = np.asarray([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) - with pytest.raises(ValueError): + with pytest.raises( + ValueError, match="Input array must have an even number of rows" + ): ConservedWaterSearch.hydrogen_orientation.hydrogen_orientation_analysis( orientations ) diff --git a/tests/test_utils.py b/tests/test_utils.py index 0829d83..5e1a661 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -14,7 +14,7 @@ @pytest.fixture(autouse=True) -def pymol_skip(): +def _pymol_skip(): pytest.importorskip("pymol") diff --git a/tests/test_water_clustering.py b/tests/test_water_clustering.py index 6d5ddaa..15b0ad1 100644 --- a/tests/test_water_clustering.py +++ b/tests/test_water_clustering.py @@ -3,6 +3,7 @@ import numpy as np import numpy.testing as npt +import pytest from ConservedWaterSearch.utils import ( get_orientations_from_positions, @@ -140,10 +141,9 @@ def test_create_from_file(): def test_read_and_set_water_clust_options_file_not_found(): wc = WaterClustering(9) - try: + with pytest.raises(FileNotFoundError, match="output file not found") as e: wc.read_and_set_water_clust_options("tests/data/nonexistent.dat") - except Exception as e: - assert str(e) == "output file not found" + assert str(e.value) == "output file not found" def test_restart_cluster_onlyO():