Skip to content

Commit

Permalink
Merge branch 'unit-tests' into develop
Browse files Browse the repository at this point in the history
* unit-tests:
  Added test recipe
  Using mock data on unit tests (#1)
  Addded unit test for pre-processing
  • Loading branch information
wleoncio committed Jul 1, 2024
2 parents a9b2418 + 13ced0a commit 59272f9
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ build:

local-install:
$(ENV_PATH)pip install .

test:
$(ENV_PATH)pytest
58 changes: 58 additions & 0 deletions tests/test_discovery_svm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from pCRscore import discovery_svm
import pandas as pd
from unittest import mock
import pytest
import numpy as np

@pytest.fixture
def mock_data():
# Define the column names
columns = [
"Trial", "Mixture", "B.cells.Memory", "B.cells.Naive", "CAFs.MSC.iCAF.like",
"CAFs.myCAF.like", "DCs", "Endothelial.ACKR1", "Endothelial.CXCL12",
"Endothelial.LYVE1", "Endothelial.RGS5", "GenMod1", "GenMod2", "GenMod3",
"GenMod4", "GenMod5", "GenMod6", "GenMod7", "Luminal.Progenitors",
"Macrophage", "Mature.Luminal", "Monocyte", "Myoepithelial", "NK.cells",
"NKT.cells", "Plasmablasts", "PVL.Differentiated", "PVL.Immature",
"T.cells.CD4.", "T.cells.CD8.", "Cancer.Cells", "Normal.Epi", "TCells",
"Myeloids", "BCells", "CAFs", "PVLs", "Endothelials", "ER", "Response",
"Cohort", "PAM50", "PAM50_Normal", "PAM50_LumA", "PAM50_Her2", "PAM50_LumB",
"PAM50_Basal"
]

# Number of rows you want in your DataFrame
num_rows = 100 # Adjust this based on how many rows you need

# Create a dataframe with random values in (0, 1) for the numerical columns
n_numerical_columns = 7
df = pd.DataFrame(
np.random.rand(num_rows, len(columns) - n_numerical_columns),
columns = columns[:-n_numerical_columns]
)

# Adding the non-numerical columns manually
df['Trial'] = 'E-MTAB-4439'
df['Mixture'] = 'Mixture1'
df['Cohort'] = 'Discovery'
df['Response'] = np.random.choice(['pCR', 'RD'], num_rows)
df['ER'] = np.random.choice(['Positive', 'Negative'], num_rows)
df['PAM50'] = np.random.choice(['LumA', 'Basal'], num_rows)
df['PAM50_Normal'] = np.random.choice([True, False], num_rows)
df['PAM50_LumA'] = np.random.choice([True, False], num_rows)
df['PAM50_Her2'] = np.random.choice([True, False], num_rows)
df['PAM50_LumB'] = np.random.choice([True, False], num_rows)
df['PAM50_Basal'] = np.random.choice([True, False], num_rows)

return df

@mock.patch('pandas.read_csv')
def test_preprocess(mock_read_csv, mock_data):
# Configure the mock to return your predefined DataFrame
mock_read_csv.return_value = mock_data

data = pd.read_csv("Data NAC cohort _1_.csv") # returns mock data instead
data = discovery_svm.preprocess(data)
assert data.shape == (100, 48)

X, y = discovery_svm.extract_features(data)
assert X.shape == (100, 44)

0 comments on commit 59272f9

Please sign in to comment.