Mercurial > repos > guerler > springsuite
view planemo/lib/python3.7/site-packages/bioblend/_tests/TestGalaxyDatasets.py @ 0:d30785e31577 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:18:57 -0400 |
parents | |
children |
line wrap: on
line source
import shutil import tempfile from . import ( GalaxyTestBase, test_util ) class TestGalaxyDatasets(GalaxyTestBase.GalaxyTestBase): def setUp(self): super().setUp() self.history_id = self.gi.histories.create_history(name='TestShowDataset')['id'] self.dataset_contents = "line 1\nline 2\rline 3\r\nline 4" self.dataset_id = self._test_dataset(self.history_id, contents=self.dataset_contents) def tearDown(self): self.gi.histories.delete_history(self.history_id, purge=True) @test_util.skip_unless_galaxy('release_19.05') def test_show_nonexistent_dataset(self): with self.assertRaises(Exception): self.gi.datasets.show_dataset('nonexistent_id') def test_show_dataset(self): self.gi.datasets.show_dataset(self.dataset_id) def test_download_dataset(self): with self.assertRaises(Exception): self.gi.datasets.download_dataset(None) expected_contents = ("\n".join(self.dataset_contents.splitlines()) + "\n").encode() # download_dataset() with file_path=None is already tested in TestGalaxyTools.test_paste_content() # self._wait_and_verify_dataset(self.dataset_id, expected_contents) tempdir = tempfile.mkdtemp(prefix='bioblend_test_') try: downloaded_dataset = self.gi.datasets.download_dataset( self.dataset_id, file_path=tempdir, maxwait=GalaxyTestBase.BIOBLEND_TEST_JOB_TIMEOUT * 2) self.assertTrue(downloaded_dataset.startswith(tempdir)) with open(downloaded_dataset, 'rb') as f: self.assertEqual(f.read(), expected_contents) finally: shutil.rmtree(tempdir) with tempfile.NamedTemporaryFile(prefix='bioblend_test_') as f: download_filename = self.gi.datasets.download_dataset( self.dataset_id, file_path=f.name, use_default_filename=False, maxwait=GalaxyTestBase.BIOBLEND_TEST_JOB_TIMEOUT) self.assertEqual(download_filename, f.name) f.flush() self.assertEqual(f.read(), expected_contents) @test_util.skip_unless_galaxy('release_19.05') def test_get_datasets(self): datasets = self.gi.datasets.get_datasets() dataset_ids = [dataset['id'] for dataset in datasets] assert self.dataset_id in dataset_ids datasets = self.gi.datasets.get_datasets(limit=0) assert datasets == []