Skip to content

Commit

Permalink
cleaned up tests and precommit
Browse files Browse the repository at this point in the history
  • Loading branch information
ntalluri committed Jul 29, 2024
1 parent b6d319d commit b6610ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
2 changes: 1 addition & 1 deletion spras/analysis/ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def df_error(dataframe: pd.DataFrame):
if min(dataframe.shape) <= 1:
raise ValueError(f"ML post-processing cannot proceed because the available number of pathways is insufficient. "
f"The ml post-processing requires more than one pathway, but currently "
f"there are only {min(concated_df.shape)} pathways.")
f"there are only {min(dataframe.shape)} pathways.")

def create_palette(column_names):
"""
Expand Down
30 changes: 8 additions & 22 deletions test/ml/test_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,38 +42,24 @@ def test_summarize_networks_wrong_direction(self):
with pytest.raises(ValueError):
ml.summarize_networks([INPUT_DIR + 'test-data-wrong-direction/wrong-direction.txt'])

# TODO: Can I move everything into one test?
def test_empty_pca(self):
def test_empty(self):
dataframe = ml.summarize_networks([INPUT_DIR + 'test-data-empty/empty.txt'])
with pytest.raises(ValueError): # raises error if empty dataframe is used for post processing
dataframe = ml.summarize_networks([INPUT_DIR + 'test-data-empty/empty.txt'])
ml.pca(dataframe, OUT_DIR + 'pca-empty.png', OUT_DIR + 'pca-empty-variance.txt',
OUT_DIR + 'pca-empty-coordinates.tsv')

def test_empty_hac_horizontal(self):
with pytest.raises(ValueError): # raises error if empty dataframe is used for post processing
dataframe = ml.summarize_networks([INPUT_DIR + 'test-data-empty/empty.txt'])
with pytest.raises(ValueError):
ml.hac_horizontal(dataframe, OUT_DIR + 'hac-empty-horizontal.png', OUT_DIR + 'hac-empty-clusters-horizontal.txt')

def test_empty_hac_vertical(self):
with pytest.raises(ValueError): # raises error if empty dataframe is used for post processing
dataframe = ml.summarize_networks([INPUT_DIR + 'test-data-empty/empty.txt'])
with pytest.raises(ValueError):
ml.hac_vertical(dataframe, OUT_DIR + 'hac-empty-vertical.png', OUT_DIR + 'hac-empty-clusters-vertical.txt')

# TODO: Can I move everything into one test?
def test_single_line_pca(self):
def test_single_line(self):
dataframe = ml.summarize_networks([INPUT_DIR + 'test-data-empty/empty.txt'])
with pytest.raises(ValueError): # raises error if single line in file s.t. single row in dataframe is used for post processing
dataframe = ml.summarize_networks([INPUT_DIR + 'test-data-empty/empty.txt'])
ml.pca(dataframe, OUT_DIR + 'pca-single-line.png', OUT_DIR + 'pca-single-line-variance.txt',
OUT_DIR + 'pca-single-line-coordinates.tsv')

def test_single_line_hac_horizontal(self):
with pytest.raises(ValueError): # raises error if single line in file s.t. single row in dataframe is used for post processing
dataframe = ml.summarize_networks([INPUT_DIR + 'test-data-empty/empty.txt'])
with pytest.raises(ValueError):
ml.hac_horizontal(dataframe, OUT_DIR + 'hac-single-line-horizontal.png', OUT_DIR + 'hac-single-line-clusters-horizontal.txt')

def test_single_line_hac_vertical(self):
with pytest.raises(ValueError): # raises error if single line in file s.t. single row in dataframe is used for post processing
dataframe = ml.summarize_networks([INPUT_DIR + 'test-data-empty/empty.txt'])
with pytest.raises(ValueError):
ml.hac_vertical(dataframe, OUT_DIR + 'hac-single-line-vertical.png', OUT_DIR + 'hac-single-line-clusters-vertical.txt')

def test_pca(self):
Expand Down

0 comments on commit b6610ae

Please sign in to comment.