Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vicpaton committed Sep 10, 2024
1 parent 06c81eb commit 146bd56
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
8 changes: 4 additions & 4 deletions tests/test_moon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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():
Expand Down
17 changes: 8 additions & 9 deletions tests/test_omics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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'

Expand All @@ -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()
Expand Down Expand Up @@ -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]
Expand All @@ -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')
Expand Down
5 changes: 1 addition & 4 deletions tests/test_visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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'],
Expand All @@ -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({
Expand All @@ -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'],
Expand Down

0 comments on commit 146bd56

Please sign in to comment.