KiTE.tests.validation_test

 1from KiTE import none_arg_msg
 2from KiTE.validation import check_attributes
 3import numpy as np
 4import pytest
 5import re
 6
 7
 8class Test_check_attributes:
 9    def test_None_inputs(self):
10        with pytest.raises(ValueError, match=none_arg_msg):
11            check_attributes(None, None)
12        with pytest.raises(ValueError, match=none_arg_msg):
13            check_attributes([], None)
14
15    def test_incompatible_dims(self):
16        X = np.array([[1, 2, 3], [11, 21, 31]])
17        with pytest.raises(
18            ValueError,
19            match=re.escape(
20                f"Incompatible dimension for X and e matrices. X and e should have the same feature dimension: X.shape[0] = {X.shape[0]} while e.shape[0] = {X.T.shape[0]}."
21            ),
22        ):
23            check_attributes(X, X.T)
24
25    def test_invalid_iterations(self):
26        X = np.array([[1, 2, 3], [None, 21, 31]])
27        str_input = "cake"
28        neg_input = -1
29        with pytest.raises(
30            ValueError,
31            match=f"iterations has incorrect type or less than 2. iterations: {str_input}",
32        ):
33            check_attributes(X, X, str_input)
34        with pytest.raises(
35            ValueError,
36            match=f"iterations has incorrect type or less than 2. iterations: {neg_input}",
37        ):
38            check_attributes(X, X, neg_input)
39
40    def test_invalid_n_jobs(self):
41        X = np.array([[1, 2, 3], [11, 21, 31]])
42        str_input = "cake"
43        neg_input = -1
44        with pytest.raises(
45            ValueError,
46            match=f"n_jobs is incorrect type or less than 1. n_jobs: {str_input}",
47        ):
48            check_attributes(X, X, n_jobs=str_input)
49        with pytest.raises(
50            ValueError,
51            match=f"n_jobs is incorrect type or less than 1. n_jobs: {neg_input}",
52        ):
53            check_attributes(X, X, n_jobs=neg_input)
class Test_check_attributes:
 9class Test_check_attributes:
10    def test_None_inputs(self):
11        with pytest.raises(ValueError, match=none_arg_msg):
12            check_attributes(None, None)
13        with pytest.raises(ValueError, match=none_arg_msg):
14            check_attributes([], None)
15
16    def test_incompatible_dims(self):
17        X = np.array([[1, 2, 3], [11, 21, 31]])
18        with pytest.raises(
19            ValueError,
20            match=re.escape(
21                f"Incompatible dimension for X and e matrices. X and e should have the same feature dimension: X.shape[0] = {X.shape[0]} while e.shape[0] = {X.T.shape[0]}."
22            ),
23        ):
24            check_attributes(X, X.T)
25
26    def test_invalid_iterations(self):
27        X = np.array([[1, 2, 3], [None, 21, 31]])
28        str_input = "cake"
29        neg_input = -1
30        with pytest.raises(
31            ValueError,
32            match=f"iterations has incorrect type or less than 2. iterations: {str_input}",
33        ):
34            check_attributes(X, X, str_input)
35        with pytest.raises(
36            ValueError,
37            match=f"iterations has incorrect type or less than 2. iterations: {neg_input}",
38        ):
39            check_attributes(X, X, neg_input)
40
41    def test_invalid_n_jobs(self):
42        X = np.array([[1, 2, 3], [11, 21, 31]])
43        str_input = "cake"
44        neg_input = -1
45        with pytest.raises(
46            ValueError,
47            match=f"n_jobs is incorrect type or less than 1. n_jobs: {str_input}",
48        ):
49            check_attributes(X, X, n_jobs=str_input)
50        with pytest.raises(
51            ValueError,
52            match=f"n_jobs is incorrect type or less than 1. n_jobs: {neg_input}",
53        ):
54            check_attributes(X, X, n_jobs=neg_input)
Test_check_attributes()
def test_None_inputs(self):
10    def test_None_inputs(self):
11        with pytest.raises(ValueError, match=none_arg_msg):
12            check_attributes(None, None)
13        with pytest.raises(ValueError, match=none_arg_msg):
14            check_attributes([], None)
def test_incompatible_dims(self):
16    def test_incompatible_dims(self):
17        X = np.array([[1, 2, 3], [11, 21, 31]])
18        with pytest.raises(
19            ValueError,
20            match=re.escape(
21                f"Incompatible dimension for X and e matrices. X and e should have the same feature dimension: X.shape[0] = {X.shape[0]} while e.shape[0] = {X.T.shape[0]}."
22            ),
23        ):
24            check_attributes(X, X.T)
def test_invalid_iterations(self):
26    def test_invalid_iterations(self):
27        X = np.array([[1, 2, 3], [None, 21, 31]])
28        str_input = "cake"
29        neg_input = -1
30        with pytest.raises(
31            ValueError,
32            match=f"iterations has incorrect type or less than 2. iterations: {str_input}",
33        ):
34            check_attributes(X, X, str_input)
35        with pytest.raises(
36            ValueError,
37            match=f"iterations has incorrect type or less than 2. iterations: {neg_input}",
38        ):
39            check_attributes(X, X, neg_input)
def test_invalid_n_jobs(self):
41    def test_invalid_n_jobs(self):
42        X = np.array([[1, 2, 3], [11, 21, 31]])
43        str_input = "cake"
44        neg_input = -1
45        with pytest.raises(
46            ValueError,
47            match=f"n_jobs is incorrect type or less than 1. n_jobs: {str_input}",
48        ):
49            check_attributes(X, X, n_jobs=str_input)
50        with pytest.raises(
51            ValueError,
52            match=f"n_jobs is incorrect type or less than 1. n_jobs: {neg_input}",
53        ):
54            check_attributes(X, X, n_jobs=neg_input)