Skip to content

Commit

Permalink
fix object control
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcantor22 committed Aug 8, 2024
1 parent 21174d5 commit c51eb0e
Showing 1 changed file with 34 additions and 24 deletions.
58 changes: 34 additions & 24 deletions mmeds/tests/unit/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@
class AnalysisTests(TestCase):
""" Test running analyses """
@classmethod
def setUpClass(cls):
def setUpClass(self):
""" Set up tests """
# path to an example study, created from a MMEDs upload of existing test files
# definied in config.py
cls.test_study = fig.TEST_STUDY
cls.watcher = Watcher()
cls.watcher.connect()
cls.queue = cls.watcher.get_queue()
cls.config = load_config(fig.DEFAULT_CONFIG, fig.TEST_MIXED_METADATA, 'standard_pipeline')
self.test_study = fig.TEST_STUDY
self.watcher = Watcher()
self.watcher.connect()
self.queue = self.watcher.get_queue()
self.config = load_config(fig.DEFAULT_CONFIG, fig.TEST_MIXED_METADATA, 'standard_pipeline')
self.analysis = []
with Database(owner=fig.TEST_USER_0, testing=True) as db:
cls.analysis_code = db.create_access_code()
cls.runs = db.get_sequencing_run_locations(fig.TEST_MIXED_METADATA, fig.TEST_USER_0)
cls.analysis = Analysis(cls.queue, fig.TEST_USER_0, cls.analysis_code, fig.TEST_CODE_MIXED,
'standard_pipeline', 'default', 'test_init', cls.config, True, cls.runs, False, threads=2)
self.analysis_code = db.create_access_code()

def test_a_upload_sequencing_run(self):
""" Upload sequencing run for analysis """
Expand All @@ -39,6 +37,13 @@ def test_a_upload_sequencing_run(self):
sleep(5)
self.assertEquals(result, 0)

def test_b_analysis_init(self):
""" Test analysis object """
with Database(owner=fig.TEST_USER_0, testing=True) as db:
self.runs = db.get_sequencing_run_locations(fig.TEST_MIXED_METADATA, fig.TEST_USER_0)
self.analysis += [Analysis(self.queue, fig.TEST_USER_0, self.analysis_code, fig.TEST_CODE_MIXED,
'standard_pipeline', 'default', 'test_init', self.config, True, self.runs, False, threads=2)]


def test_b_standard_pipeline(self):
""" Test running a standard analysis """
Expand All @@ -54,21 +59,24 @@ def test_b_standard_pipeline(self):

def test_c_analysis_class(self):
""" Test the analysis object """
self.analysis.run()
analysis = self.analysis[0]
analysis.run()

info = self.analysis.get_info()
info = analysis.get_info()
self.assertEquals(info['owner'], fig.TEST_USER_0)
self.assertEquals(info['analysis_code'], self.analysis_code)

def test_d_analysis_utils(self):
""" Test that adding files to the tool object works properly """
Logger.info(str(self.analysis))
assert 'testfile' not in self.analysis.doc.files.keys()
self.analysis.add_path('testfile', '.txt')
assert 'testfile' in self.analysis.doc.files.keys()
analysis = self.analysis[0]
Logger.info(str(analysis))
assert 'testfile' not in analysis.doc.files.keys()
analysis.add_path('testfile', '.txt')
assert 'testfile' in analysis.doc.files.keys()

def test_e_get_job_params(self):
params = self.analysis.get_job_params()
analysis = self.analysis[0]
params = analysis.get_job_params()
assert params['nodes'] == 2

def test_f_get_files(self):
Expand All @@ -77,17 +85,19 @@ def test_f_get_files(self):

def test_g_missing_file(self):
""" Test that an appropriate error will be raised if a file doesn't exist on disk """
files = self.analysis.doc.files
analysis = self.analysis[0]
files = analysis.doc.files
# Add a nonexistent file
files['fakefile'] = '/fake/dir'
self.analysis.update_doc(files=files)
analysis.update_doc(files=files)
with self.assertRaises(err.MissingFileError):
self.analysis.get_file('fakefile', check=True)
analysis.get_file('fakefile', check=True)
del files['fakefile']
self.analysis.update_doc(files=files)
analysis.update_doc(files=files)

def test_h_update_doc(self):
self.assertEqual(self.analysis.doc.study_name, 'TEST_MIXED_17')
self.analysis.update_doc(study_name='Test_Update')
self.assertEqual(self.analysis.doc.study_name, 'Test_Update')
analysis = self.analysis[0]
self.assertEqual(analysis.doc.study_name, 'TEST_MIXED_17')
analysis.update_doc(study_name='Test_Update')
self.assertEqual(analysis.doc.study_name, 'Test_Update')

0 comments on commit c51eb0e

Please sign in to comment.