Skip to content

Commit

Permalink
Tests update
Browse files Browse the repository at this point in the history
  • Loading branch information
Gossty committed May 15, 2024
1 parent 933bdde commit 8102d3b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 50 deletions.
7 changes: 5 additions & 2 deletions qiita_db/test/test_software.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,11 @@ def test_processing_jobs(self):
'6ad4d590-4fa3-44d3-9a8f-ddbb472b1b5f',
'063e553b-327c-4818-ab4a-adfe58e49860',
'ac653cb5-76a6-4a45-929e-eb9b2dee6b63']
exp = [qdb.processing_job.ProcessingJob(j) for j in exp_jids]
self.assertCountEqual(qdb.software.Command(1).processing_jobs, exp)

exp = set([qdb.processing_job.ProcessingJob(j) for j in exp_jids])
set_jobs = set(qdb.software.Command(1).processing_jobs)

self.assertEqual(len(set_jobs & exp), len(exp_jids))

exp_jids = ['bcc7ebcd-39c1-43e4-af2d-822e3589f14d']
exp = [qdb.processing_job.ProcessingJob(j) for j in exp_jids]
Expand Down
7 changes: 0 additions & 7 deletions qiita_db/test/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,17 +491,10 @@ def test_jobs(self):
limit=1, ignore_status=ignore_status), [
PJ('b72369f9-a886-4193-8d3d-f7b504168e75')])

# no jobs
self.assertEqual(qdb.user.User('[email protected]').jobs(
ignore_status=ignore_status), [])

# generates expected jobs
jobs = qdb.user.User('[email protected]').jobs()
self.assertEqual(jobs, [])

# no jobs
self.assertEqual(qdb.user.User('[email protected]').jobs(), [])

def test_update_email(self):
user = qdb.user.User('[email protected]')
with self.assertRaisesRegex(IncorrectEmailError, 'Bad email given:'):
Expand Down
48 changes: 7 additions & 41 deletions qiita_db/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1312,49 +1312,15 @@ def setUp(self):
self.CNAME = "Split libraries FASTQ"
self.SNAME = "QIIMEq2"
self.col_name = 'samples * columns'
self.df = self.get_df()

def get_df(self):
with qdb.sql_connection.TRN:
sql = f"""
SELECT
s.name AS sName,
s.version AS sVersion,
sc.command_id AS cID,
sc.name AS cName,
pr.processing_job_id AS processing_job_id,
pr.command_parameters AS parameters,
sra.samples AS samples,
sra.columns AS columns,
sra.input_size AS input_size,
sra.extra_info AS extra_info,
sra.memory_used AS memory_used,
sra.walltime_used AS walltime_used
FROM
qiita.processing_job pr
JOIN
qiita.software_command sc ON pr.command_id = sc.command_id
JOIN
qiita.software s ON sc.software_id = s.software_id
JOIN
qiita.slurm_resource_allocations sra
ON pr.processing_job_id = sra.processing_job_id
WHERE
sc.name = '{self.CNAME}'
AND s.name = '{self.SNAME}';
"""

qdb.sql_connection.TRN.add(sql)
res = qdb.sql_connection.TRN.execute_fetchindex()
columns = [
"sName", "sVersion", "cID", "cName",
"processing_job_id", "parameters", "samples", "columns",
"input_size", "extra_info", "MaxRSSRaw", "ElapsedRaw"]
df = pd.DataFrame(res, columns=columns)
return df
self.columns = [
"sName", "sVersion", "cID", "cName", "processing_job_id",
"parameters", "samples", "columns", "input_size", "extra_info",
"MaxRSSRaw", "ElapsedRaw"]
self.df = pd.DataFrame(
qdb.util._retrieve_resource_data(self.CNAME, self.SNAME),
columns=self.columns)

def test_plot_return(self):

# check the plot returns correct objects
fig1, axs1 = qdb.util.resource_allocation_plot(
self.df, self.CNAME, self.SNAME, self.col_name)
Expand Down
35 changes: 35 additions & 0 deletions qiita_db/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2380,6 +2380,41 @@ def resource_allocation_plot(df, cname, sname, col_name):
return fig, axs


def _retrieve_resource_data(cname, sname):
with qdb.sql_connection.TRN:
sql = """
SELECT
s.name AS sName,
s.version AS sVersion,
sc.command_id AS cID,
sc.name AS cName,
pr.processing_job_id AS processing_job_id,
pr.command_parameters AS parameters,
sra.samples AS samples,
sra.columns AS columns,
sra.input_size AS input_size,
sra.extra_info AS extra_info,
sra.memory_used AS memory_used,
sra.walltime_used AS walltime_used
FROM
qiita.processing_job pr
JOIN
qiita.software_command sc ON pr.command_id = sc.command_id
JOIN
qiita.software s ON sc.software_id = s.software_id
JOIN
qiita.slurm_resource_allocations sra
ON pr.processing_job_id = sra.processing_job_id
WHERE
sc.name = %s
AND s.name = %s;
"""
qdb.sql_connection.TRN.add(sql, sql_args=[cname, sname])
res = qdb.sql_connection.TRN.execute_fetchindex()
return res
pass


def _resource_allocation_plot_helper(
df, ax, cname, sname, curr, models, col_name):
"""Helper function for resource allocation plot. Builds plot for MaxRSSRaw
Expand Down

0 comments on commit 8102d3b

Please sign in to comment.