comparison env/lib/python3.9/site-packages/bioblend/_tests/TestGalaxyDatasets.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 import shutil
2 import tempfile
3
4 from . import (
5 GalaxyTestBase,
6 test_util
7 )
8
9
10 class TestGalaxyDatasets(GalaxyTestBase.GalaxyTestBase):
11
12 def setUp(self):
13 super().setUp()
14 self.history_id = self.gi.histories.create_history(name='TestShowDataset')['id']
15 self.dataset_contents = "line 1\nline 2\rline 3\r\nline 4"
16 self.dataset_id = self._test_dataset(self.history_id, contents=self.dataset_contents)
17
18 def tearDown(self):
19 self.gi.histories.delete_history(self.history_id, purge=True)
20
21 @test_util.skip_unless_galaxy('release_19.05')
22 def test_show_nonexistent_dataset(self):
23 with self.assertRaises(Exception):
24 self.gi.datasets.show_dataset('nonexistent_id')
25
26 def test_show_dataset(self):
27 self.gi.datasets.show_dataset(self.dataset_id)
28
29 def test_download_dataset(self):
30 with self.assertRaises(Exception):
31 self.gi.datasets.download_dataset(None)
32 expected_contents = ("\n".join(self.dataset_contents.splitlines()) + "\n").encode()
33 # download_dataset() with file_path=None is already tested in TestGalaxyTools.test_paste_content()
34 # self._wait_and_verify_dataset(self.dataset_id, expected_contents)
35 tempdir = tempfile.mkdtemp(prefix='bioblend_test_')
36 try:
37 downloaded_dataset = self.gi.datasets.download_dataset(
38 self.dataset_id, file_path=tempdir,
39 maxwait=GalaxyTestBase.BIOBLEND_TEST_JOB_TIMEOUT * 2)
40 self.assertTrue(downloaded_dataset.startswith(tempdir))
41 with open(downloaded_dataset, 'rb') as f:
42 self.assertEqual(f.read(), expected_contents)
43 finally:
44 shutil.rmtree(tempdir)
45 with tempfile.NamedTemporaryFile(prefix='bioblend_test_') as f:
46 download_filename = self.gi.datasets.download_dataset(
47 self.dataset_id, file_path=f.name, use_default_filename=False,
48 maxwait=GalaxyTestBase.BIOBLEND_TEST_JOB_TIMEOUT)
49 self.assertEqual(download_filename, f.name)
50 f.flush()
51 self.assertEqual(f.read(), expected_contents)
52
53 @test_util.skip_unless_galaxy('release_19.05')
54 def test_get_datasets(self):
55 datasets = self.gi.datasets.get_datasets()
56 dataset_ids = [dataset['id'] for dataset in datasets]
57 assert self.dataset_id in dataset_ids
58 datasets = self.gi.datasets.get_datasets(limit=0)
59 assert datasets == []