From 146bd56eb763af09d0930228583523f9feaa66e4 Mon Sep 17 00:00:00 2001 From: vicpaton Date: Tue, 10 Sep 2024 14:53:16 +0200 Subject: [PATCH] updated tests --- tests/test_moon.py | 8 ++++---- tests/test_omics.py | 17 ++++++++--------- tests/test_visual.py | 5 +---- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/tests/test_moon.py b/tests/test_moon.py index 3f45fa0..5998297 100644 --- a/tests/test_moon.py +++ b/tests/test_moon.py @@ -122,7 +122,7 @@ def test_filter_input_nodes_not_in_pkn(mock_log): assert len(filtered_data) == 2 # Check that _log was called with the correct message - mock_log.assert_called_with("COSMOS: 1 input/measured nodes are not in PKN anymore: ['Gene3']") + mock_log.assert_called_with("MOON: 1 input/measured nodes are not in PKN anymore: ['Gene3']") @patch('networkcommons.methods._moon._log') @@ -336,7 +336,7 @@ def test_run_moon_core_while_loop(mock_log): assert len(result.index) > 0, "Unexpected number of rows in result" assert not result.empty, "Empty result" - mock_log.assert_any_call("Iteration count: 1") + mock_log.assert_any_call("MOON: scoring layer 1 from downstream nodes...") result_wmean = _moon.run_moon_core( upstream_input=upstream_input, @@ -352,7 +352,7 @@ def test_run_moon_core_while_loop(mock_log): assert not result_wmean.empty, "Empty result" # Check that the while loop executed by checking log calls - mock_log.assert_any_call("Iteration count: 1") + mock_log.assert_any_call("MOON: scoring layer 1 from downstream nodes...") result_norm_wmean = _moon.run_moon_core( upstream_input=upstream_input, @@ -368,7 +368,7 @@ def test_run_moon_core_while_loop(mock_log): assert not result_norm_wmean.empty, "Empty result" # Check that the while loop executed by checking log calls - mock_log.assert_any_call("Iteration count: 1") + mock_log.assert_any_call("MOON: scoring layer 1 from downstream nodes...") def test_filter_incoherent_TF_target(): diff --git a/tests/test_omics.py b/tests/test_omics.py index 2c841d7..864e9fd 100644 --- a/tests/test_omics.py +++ b/tests/test_omics.py @@ -127,7 +127,7 @@ def test_maybe_download_exists(mock_md5, mock_exists, mock_conf_get, mock_log, m mock_md5.assert_called_once_with(url.encode()) mock_conf_get.assert_called_once_with('cachedir') mock_exists.assert_called_once_with('/mock/cache/dir/dummyhash-file.txt') - mock_log.assert_called_once_with('Looking up in cache: `http://example.com/file.txt` -> `/mock/cache/dir/dummyhash-file.txt`.') + mock_log.assert_called_once_with('Utils: Looking up in cache: `http://example.com/file.txt` -> `/mock/cache/dir/dummyhash-file.txt`.') mock_download.assert_not_called() assert path == '/mock/cache/dir/dummyhash-file.txt' @@ -153,8 +153,8 @@ def test_maybe_download_not_exists(mock_md5, mock_exists, mock_conf_get, mock_lo mock_md5.assert_called_once_with(url.encode()) mock_conf_get.assert_called_once_with('cachedir') mock_exists.assert_called_once_with('/mock/cache/dir/dummyhash-file.txt') - mock_log.assert_any_call('Looking up in cache: `http://example.com/file.txt` -> `/mock/cache/dir/dummyhash-file.txt`.') - mock_log.assert_any_call('Not found in cache, initiating download: `http://example.com/file.txt`.') + mock_log.assert_any_call('Utils: Looking up in cache: `http://example.com/file.txt` -> `/mock/cache/dir/dummyhash-file.txt`.') + mock_log.assert_any_call('Utils: Not found in cache, initiating download: `http://example.com/file.txt`.') mock_download.assert_called_once_with(url, '/mock/cache/dir/dummyhash-file.txt') assert path == '/mock/cache/dir/dummyhash-file.txt' @@ -180,8 +180,8 @@ def test_download(mock_conf_get, mock_log, mock_requests_session, tmp_path): # Assertions mock_conf_get.assert_any_call('http_read_timout') mock_conf_get.assert_any_call('http_connect_timout') - mock_log.assert_any_call(f'Downloading `{url}` to `{path}`.') - mock_log.assert_any_call(f'Finished downloading `{url}` to `{path}`.') + mock_log.assert_any_call(f'Utils: Downloading `{url}` to `{path}`.') + mock_log.assert_any_call(f'Utils: Finished downloading `{url}` to `{path}`.') mock_requests_session.assert_called_once() mock_session.get.assert_called_once_with(url, timeout=(5, 5), stream=True) mock_response.raise_for_status.assert_called_once() @@ -909,8 +909,8 @@ def test_convert_ensembl_to_gene_symbol_median(): }) pd.testing.assert_frame_equal(result_df, expected_df) - -def test_convert_ensembl_to_gene_symbol_no_match(): +@patch('networkcommons.data.omics._common._log') +def test_convert_ensembl_to_gene_symbol_no_match(mock_log): dataframe = pd.DataFrame({ 'idx': ['ENSG000001.1', 'ENSG000003', 'ENSG000001.02'], 'value': [10, 20, 15] @@ -921,13 +921,12 @@ def test_convert_ensembl_to_gene_symbol_no_match(): }) with patch('builtins.print') as mocked_print: result_df = omics.convert_ensembl_to_gene_symbol(dataframe, equivalence_df, summarisation='mean') - print(mocked_print.mock_calls) expected_df = pd.DataFrame({ 'gene_symbol': ['GeneA'], 'value': [12.5] }) pd.testing.assert_frame_equal(result_df, expected_df) - mocked_print.assert_any_call("Number of non-matched Ensembl IDs: 1 (33.33%)") + mock_log.assert_any_call("Utils: Number of non-matched Ensembl IDs: 1 (33.33%)") @patch('biomart.BiomartServer') diff --git a/tests/test_visual.py b/tests/test_visual.py index 23e2ac7..833938c 100644 --- a/tests/test_visual.py +++ b/tests/test_visual.py @@ -7,7 +7,7 @@ from unittest.mock import patch import pytest -@pytest.mark.slow + def test_pca_with_metadata_df(): df = pd.DataFrame({ 'idx': ['A', 'B', 'C'], @@ -26,7 +26,6 @@ def test_pca_with_metadata_df(): assert 'group' in result_df.columns -@pytest.mark.slow def test_pca_with_metadata_array(): df = pd.DataFrame({ 'idx': ['A', 'B', 'C'], @@ -42,7 +41,6 @@ def test_pca_with_metadata_array(): assert 'group' in result_df.columns -@pytest.mark.slow def test_pca_no_numeric_columns(): df = pd.DataFrame({'idx': ['A', 'B', 'C']}) metadata_df = pd.DataFrame({ @@ -55,7 +53,6 @@ def test_pca_no_numeric_columns(): assert str(e) == "The dataframe contains no numeric columns suitable for PCA." -@pytest.mark.slow def test_pca_zero_std_columns(): df_with_zero_std = pd.DataFrame({ 'idx': ['feature1', 'feature2', 'feature3'],