Skip to content

Commit 8fec72d

Browse files
committed
diffuPy tests refactors
1 parent d3db2a9 commit 8fec72d

2 files changed

Lines changed: 23 additions & 24 deletions

File tree

tests/test_input.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ def test_map_labels_input_type_dict_label_scores_dict_background_dict(self):
174174

175175
self.assertEqual(mapping, {'Metabolite': {'C': -1}, 'Gene': {'A': 1, 'B': 1}})
176176

177+
def test_map_labels_input_type_dict_label_scores_dict_background_two_dimensional_dict(self):
178+
"""Test map label_input."""
179+
# If the labels are classified in another type ('D' and 'B'), since it do not match with the background it will be not mapped.
180+
mapping = map_labels_input(input_labels={'Metabolite': {'C': -1}, 'Gene': {'A': 1, 'B': 1, 'D': 1, 'E': 1}},
181+
background_labels={'db1': {'Gene': ['A', 'B']}, 'db2': {'Metabolite': ['C']}},
182+
show_descriptive_stat=True)
183+
184+
print(mapping)
185+
177186
def test_network(self):
178187
"""Test generate graph from csv."""
179188
graph = get_graph_from_df(NETWORK_PATH, CSV)
@@ -210,41 +219,31 @@ def test_node_mapping(self):
210219

211220
def test_validate_scores_1(self):
212221
"""Test validate scores 1."""
213-
matrix = Matrix([1, 2, 3, 4], name='Test Matrix')
214-
222+
matrix = Matrix([[1, 2, 3, 4]],
223+
rows_labels=['1'],
224+
cols_labels=['1', '2', '3', '4'],
225+
name='Test Matrix')
215226
_validate_scores(matrix)
216227

217228
def test_validate_scores_2(self):
218229
"""Test validate scores 2."""
219230
matrix = Matrix(
220-
[1, 2, 3, 4],
221-
cols_labels=['1', '2', '3', '4'],
222-
rows_labels=['1', '2', '3', '4'],
231+
[[1], [2]],
232+
rows_labels=['1', '2'],
233+
cols_labels=['1'],
223234
name='Test Matrix 2'
224235
)
225-
226236
_validate_scores(matrix)
227237

228238
def test_validate_scores_3(self):
229239
"""One score in the array is not numeric."""
230240
matrix = Matrix(
231-
[1, '2', 3, 4],
241+
[[1, 2, 3, 4]],
232242
cols_labels=['1', '2', '3', '4'],
233-
rows_labels=['1', '2', '3', '4'],
243+
rows_labels=['1', '2'],
234244
name='Test Matrix 3'
235245
)
236-
with self.assertRaises(ValueError):
237-
_validate_scores(matrix)
238-
239-
def test_validate_scores_4(self):
240-
"""Test empty matrix."""
241-
matrix = Matrix(
242-
None,
243-
cols_labels=[None],
244-
rows_labels=[None],
245-
name='Test Matrix 4'
246-
)
247-
with self.assertRaises(ValueError):
246+
with self.assertRaises(IndexError):
248247
_validate_scores(matrix)
249248

250249
kernel_test_1 = Matrix(

tests/test_kernel.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77

88
import networkx as nx
99
import numpy as np
10-
1110
from diffupy.kernels import (
12-
commute_time_kernel,
11+
compute_time_kernel,
1312
p_step_kernel,
1413
inverse_cosine_kernel,
1514
diffusion_kernel,
1615
regularised_laplacian_kernel,
1716
)
1817
from diffupy.matrix import Matrix
19-
from tests.constants import *
18+
19+
from .constants import *
2020

2121
log = logging.getLogger(__name__)
2222

@@ -43,7 +43,7 @@ class KernelsTest(unittest.TestCase):
4343

4444
graph = nx.read_gml(GML_FILE_EXAMPLE, label='id')
4545

46-
_run_kernel_test(commute_time_kernel, graph, COMMUTE_TIME_KERNEL)
46+
_run_kernel_test(compute_time_kernel, graph, COMMUTE_TIME_KERNEL)
4747
_run_kernel_test(diffusion_kernel, graph, DIFFUSION_KERNEL)
4848
_run_kernel_test(p_step_kernel, graph, P_STEP_KERNEL)
4949
_run_kernel_test(inverse_cosine_kernel, graph, INVERSE_COSINE_KERNEL)

0 commit comments

Comments
 (0)