Skip to content

Commit

Permalink
add microarray tests, refactor (#1980)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Sep 26, 2024
1 parent b652e24 commit 2e12832
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 14 deletions.
6 changes: 3 additions & 3 deletions samplesheets/assayapps/cytof/tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_get_row_path_default(self):
)
self.assertEqual(row_path, None)

def test_update_row_filled_panel(self):
def test_update_row_panel(self):
"""Test update_row() with filled panel name"""
# Update unset values
self.assay_table['table_data'][0][15]['value'] = PANEL_NAME
Expand All @@ -69,7 +69,7 @@ def test_update_row_filled_panel(self):
)
self.assertEqual(row, row_ex)

def test_update_row_filled_report(self):
def test_update_row_report(self):
"""Test update_row() with filled report file"""
self.assay_table['table_data'][0][16]['value'] = REPORT_NAME
self.assay_table['table_data'][0][20]['value'] = ASSAY_NAME
Expand All @@ -89,7 +89,7 @@ def test_update_row_filled_report(self):
)
self.assertEqual(row, row_ex)

def test_update_row_filled_barcode(self):
def test_update_row_barcode(self):
"""Test update_row() with filled barcode key"""
# Rename header
self.assay_table['field_header'][15]['value'] = 'Barcode Key'
Expand Down
13 changes: 2 additions & 11 deletions samplesheets/assayapps/microarray/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def get_row_path(self, row, table, assay, assay_path):
[assay_path, RAW_DATA_COLL, hybrid_name, scan_name]
)
return row_path

return None

def update_row(self, row, table, assay, index):
Expand All @@ -114,11 +113,7 @@ def update_row(self, row, table, assay, index):
:return: List of dicts
"""
assay_path = self.get_assay_path(assay)
if (
not settings.IRODS_WEBDAV_ENABLED
or not assay.study.investigation.irods_status
or not assay_path
):
if not settings.IRODS_WEBDAV_ENABLED or not assay_path:
return row
row_path = self.get_row_path(row, table, assay, assay_path)
if not row_path:
Expand All @@ -132,12 +127,8 @@ def update_row(self, row, table, assay, index):
and row[i]['value']
):
top_header = get_top_header(table, i)
if (
top_header['value'].lower() in LINKED_FILES
and row[i]['value']
):
if top_header['value'].lower() in LINKED_FILES:
row[i]['link'] = base_url + '/' + row[i]['value']

return row

def update_cache(self, name=None, project=None, user=None):
Expand Down
Empty file.
86 changes: 86 additions & 0 deletions samplesheets/assayapps/microarray/tests/test_plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"""Plugin tests for the the microarray assay plugin"""

import os

from copy import deepcopy

from django.conf import settings

from samplesheets.assayapps.tests.base import AssayPluginTestBase


# Local constants
RAW_DATA_COLL = 'RawData'
HYBRID_SCAN_NAME = 'alpha-S1-E1-H1'
SCAN_NAME_UPDATE = 'alpha-S1-E1-scan-name'
IMAGE_FILE = 'image.tiff'
ARRAY_DATA_FILE = 'data.dat'
MATRIX_FILE = "mat.rix"


class TestMicroarrayAssayPlugin(AssayPluginTestBase):
"""Tests for microarray assay plugin"""

plugin_name = 'samplesheets_assay_microarray'
template_name = 'microarray'

def test_get_row_path(self):
"""Test get_row_path()"""
row_path = self.plugin.get_row_path(
self.assay_table['table_data'][0],
self.assay_table,
self.assay,
self.assay_path,
)
expected = os.path.join(
self.assay_path, RAW_DATA_COLL, HYBRID_SCAN_NAME, HYBRID_SCAN_NAME
)
self.assertEqual(row_path, expected)

def test_get_row_path_rename_scan(self):
"""Test get_row_path() with renamed scan name"""
self.assay_table['table_data'][0][24]['value'] = SCAN_NAME_UPDATE
row_path = self.plugin.get_row_path(
self.assay_table['table_data'][0],
self.assay_table,
self.assay,
self.assay_path,
)
expected = os.path.join(
self.assay_path, RAW_DATA_COLL, HYBRID_SCAN_NAME, SCAN_NAME_UPDATE
)
self.assertEqual(row_path, expected)

def test_update_row_default(self):
"""Test update_row() with default template values"""
row_ex = deepcopy(self.assay_table['table_data'][0])
row = self.plugin.update_row(
self.assay_table['table_data'][0], self.assay_table, self.assay, 0
)
self.assertEqual(row, row_ex)

def test_update_row_files(self):
"""Test update_row() with filled file values"""
row_path = self.plugin.get_row_path(
self.assay_table['table_data'][0],
self.assay_table,
self.assay,
self.assay_path,
)
self.assay_table['table_data'][0][25]['value'] = IMAGE_FILE
self.assay_table['table_data'][0][26]['value'] = ARRAY_DATA_FILE
self.assay_table['table_data'][0][27]['value'] = MATRIX_FILE
row_ex = deepcopy(self.assay_table['table_data'][0])
row_ex[25]['link'] = settings.IRODS_WEBDAV_URL + os.path.join(
row_path, IMAGE_FILE
)
row_ex[26]['link'] = settings.IRODS_WEBDAV_URL + os.path.join(
row_path, ARRAY_DATA_FILE
)
row_ex[27]['link'] = settings.IRODS_WEBDAV_URL + os.path.join(
row_path, MATRIX_FILE
)
row = self.plugin.update_row(
self.assay_table['table_data'][0], self.assay_table, self.assay, 0
)
self.assertEqual(row, row_ex)

0 comments on commit 2e12832

Please sign in to comment.