From b4425f04fe4e8e8d0ae903d58567059d463727bb Mon Sep 17 00:00:00 2001 From: Jazz Mack Smith Date: Tue, 9 Jan 2024 17:24:22 +0000 Subject: [PATCH] adding regression test for sample summary report --- Tests/test_regression.py | 58 ++++++++++++++++++++++++++++++++++++++++ nPYc/reports/__init__.py | 8 ++++-- 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 Tests/test_regression.py diff --git a/Tests/test_regression.py b/Tests/test_regression.py new file mode 100644 index 00000000..c43bb36a --- /dev/null +++ b/Tests/test_regression.py @@ -0,0 +1,58 @@ +import os +import sys +import unittest + +sys.path.append("..") +import nPYc + +""" +Tests for checking specific data values remain the same after report functionality changes +""" +class test_sample_summary_regression(unittest.TestCase): + + def setUp(self): + # load test data specific for this purpose: we know the correct numbers + self.data = nPYc.MSDataset(os.path.join('..', '..', + 'npc-standard-project', + 'Regression_Testing_Data', + 'DEVSET U RPOS xcms_regressionTesting.csv'), + fileType='XCMS', + sop='GenericMS', + noFeatureParams=9) + + self.data.addSampleInfo(descriptionFormat='Basic CSV', + filePath=os.path.join('..', '..', + 'npc-standard-project', + 'Regression_Testing_Data', + 'DEVSET U RPOS Basic CSV_regressionTesting.csv')) + + def test_report_samplesummary(self): + + sampleSummary = nPYc.reports._generateSampleReport(self.data, returnOutput=True) + + # Check returns against expected + + # Acquired - Totals + assert sampleSummary['Acquired'].loc['All', 'Total'] == 115 + assert sampleSummary['Acquired'].loc['Study Sample', 'Total'] == 8 + assert sampleSummary['Acquired'].loc['Study Reference', 'Total'] == 11 + assert sampleSummary['Acquired'].loc['Long-Term Reference', 'Total'] == 1 + assert sampleSummary['Acquired'].loc['Serial Dilution', 'Total'] == 92 + assert sampleSummary['Acquired'].loc['Blank', 'Total'] == 2 + assert sampleSummary['Acquired'].loc['Unknown', 'Total'] == 1 + + # Acquired - Marked for exclusion + assert sampleSummary['Acquired'].loc['All', 'Marked for Exclusion'] == 1 + assert sampleSummary['Acquired'].loc['Study Sample', 'Marked for Exclusion'] == 1 + assert sampleSummary['Acquired'].loc['Study Reference', 'Marked for Exclusion'] == 0 + assert sampleSummary['Acquired'].loc['Long-Term Reference', 'Marked for Exclusion'] == 0 + assert sampleSummary['Acquired'].loc['Serial Dilution', 'Marked for Exclusion'] == 0 + assert sampleSummary['Acquired'].loc['Blank', 'Marked for Exclusion'] == 0 + assert sampleSummary['Acquired'].loc['Unknown', 'Marked for Exclusion'] == 0 + + # Check details tables + assert sampleSummary['MarkedToExclude Details'].shape == (1, 2) + assert sampleSummary['UnknownType Details'].shape == (1, 1) + +if __name__ == '__main__': + unittest.main() diff --git a/nPYc/reports/__init__.py b/nPYc/reports/__init__.py index ded85492..bc345720 100644 --- a/nPYc/reports/__init__.py +++ b/nPYc/reports/__init__.py @@ -1,5 +1,8 @@ """ -The :py:mod:`~nPYc.reports` submodule provides functions to generate a variety of automated reports on :py:class:`~nPYc.objects.Dataset` objects. Most reports can be displayed inline (i.e. in a Jupyter notebook), or saved to disk as an HTML file with images. +The :py:mod:`~nPYc.reports` submodule provides functions to generate a variety of +automated reports on :py:class:`~nPYc.objects.Dataset` objects. +Most reports can be displayed inline (i.e. in a Jupyter notebook), +or saved to disk as an HTML file with images. """ from .featureID import generateMSIDrequests from .generateReport import generateReport @@ -9,4 +12,5 @@ from ._generateSampleReport import _generateSampleReport from .multivariateReport import multivariateReport -__all__ = ['generateMSIDrequests', 'generateReport', '_generateSampleReport', '_generateReportMS', '_generateReportNMR', '_generateReportTargeted', 'multivariateReport'] +__all__ = ['generateMSIDrequests', 'generateReport', '_generateSampleReport', '_generateReportMS', + '_generateReportNMR', '_generateReportTargeted', 'multivariateReport']