Commit fbce8c28 authored by Francisco Arcila Salamanca's avatar Francisco Arcila Salamanca
Browse files

add test for filter_cells user input function

parent 9384f460
......@@ -260,13 +260,8 @@ def pd_sql_queries(database, db, filter_cells, output_path, test=False):
JOIN {database}.donor ON donor.donor_id = sample.donor_id;"
if filter_cells:
list_population = pd.read_sql(
f"SELECT sort.population FROM {database}.sort;", db
).population.tolist()
dict_population = {list_population.index(x): x for x in list_population}
params_keys, string_reps = input_cell_types(dict_population)
params_keys, string_reps = input_cell_types(database, db)
print(params_keys, string_reps)
params = {
"sql": rearrangements_query % string_reps,
"con": db,
......@@ -292,7 +287,12 @@ def pd_sql_queries(database, db, filter_cells, output_path, test=False):
)
def input_cell_types(dict_population: dict) -> str:
def input_cell_types(database: str, db) -> str:
list_population = pd.read_sql(
f"SELECT sort.population FROM {database}.sort;", db
).population.tolist()
dict_population = {list_population.index(x): x for x in list_population}
""" function for the filter_cells flag, choose a set of sort.population to be exported as a repertoire"""
......
......@@ -5,6 +5,7 @@ import os
import sys
import filecmp
import shutil
import builtins
from unittest import TestCase
from _pytest.monkeypatch import MonkeyPatch
import MySQLdb.cursors
......@@ -192,10 +193,16 @@ class TestUtils(TestCase):
# pd.testing.assert_frame_equal(rearrangements_frame, ontologies_df) # todo test
# def test_filter_cells(self): todo
# self.monkeypatch.setitem(aex.DB_ARGS, "filter_cells", True)
# assert aex.main() is True
# pass
def test_filter_cells(self):
"""mock the standard input for input_cell_types()"""
cnx = sr.connect(config_dic, "test_main", ssh_group="test")
self.monkeypatch.setitem(aex.DB_ARGS, "filter_cells", True)
input_cell_types = aex.input_cell_types
with patch.object(builtins, "input", lambda _: "0"):
# aex.input_cell_types() == ""
print(input_cell_types("test_main", cnx))
assert list(input_cell_types("test_main", cnx)[0]) == ["GC"]
cnx.close()
def test_db_read(self):
......@@ -228,6 +235,8 @@ class TestUtils(TestCase):
this_dir, _ = os.path.split(__file__)
test_dir = os.path.join(this_dir, "tmp_path")
aex.input_cell_types.input = input
for db in ["test_main", "test_onto", "test_meta", "test_main_airr"]:
cursor = cnx.cursor()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment