def test__get_project_analysis_dir(self): """Test that getting the project analysis folder behaves as expected """ # Assert that none is returned when no folder exists proj = td.generate_project() self.assertIsNone(sq.get_project_analysis_dir(self.rootdir,proj), "Did not return empty result for non-existing folders") # Assert that none is still returned when some mismatching folders exist for n in range(5): os.mkdir(os.path.join(self.rootdir,td.generate_project())) self.assertIsNone(sq.get_project_analysis_dir(self.rootdir,proj), "Did not return empty result for mismatching folders") # Assert that a file with the same name as the project is not returned projdir = os.path.join(self.rootdir,proj) utils.touch_file(projdir) self.assertIsNone(sq.get_project_analysis_dir(self.rootdir,proj), "Returned a file with matching name. Should only return folders") os.unlink(projdir) # Assert that the corrct folder is returned when it exists os.mkdir(projdir) self.assertEqual(projdir,sq.get_project_analysis_dir(self.rootdir,proj), "The expected project folder was not returned")
def test_get_project_samples(self): """Test that getting the project samples from a samplesheet behaves as expected """ # Generate artificial samplesheet data data = td.generate_samplesheet_data() fh, ssheet = tempfile.mkstemp(dir=self.rootdir, suffix=".csv") os.close(fh) td._write_samplesheet(data,ssheet) # Assert that getting samples for a non-existing project returns an empty list self.assertListEqual([],sq.get_project_samples(ssheet,td.generate_project()), "Getting samples for a non-existing project returned unexpected output") # Iterate over the projects and assert that the returned samples are correct samples = {} for row in data: if row[9] not in samples: samples[row[9]] = [] samples[row[9]].append(row[2]) for proj, sample in samples.items(): self.assertListEqual(sorted(sample),sorted(sq.get_project_samples(ssheet,proj)), "The returned list of samples did not match the original")