File size: 4,021 Bytes
c7e47b2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | """Tests for medleydb.download
"""
import os
import shutil
import unittest
from pydrive.auth import AuthenticationError
from medleydb import download
from medleydb import MultiTrack
def touch(fname, times=None):
with open(fname, 'a'):
os.utime(fname, times)
class TestAuthorizeGoogleDrive(unittest.TestCase):
def test_failed_authorize(self):
pass
class TestPurgeDownloadedFiles(unittest.TestCase):
def test_purge(self):
tempfile1 = 'tempfile1.wav'
tempfile2 = 'tempfile2.wav'
touch(tempfile1)
touch(tempfile2)
download.DOWNLOADED_FILEPATHS = [tempfile1, tempfile2]
self.assertTrue(os.path.exists(tempfile1))
self.assertTrue(os.path.exists(tempfile2))
download.purge_downloaded_files()
self.assertFalse(os.path.exists(tempfile1))
self.assertFalse(os.path.exists(tempfile2))
class TestCheckBaseDirWriteable(unittest.TestCase):
def test_writeable(self):
actual = download.check_basedir_writeable()
expected = True
self.assertEqual(expected, actual)
self.assertTrue(download.BASEDIR_WRITEABLE)
class TestMakeMtrackBasedir(unittest.TestCase):
def test_make_mtrack_basedir(self):
mtrack = MultiTrack('MusicDelta_Rock')
if os.path.exists(mtrack.audio_path):
shutil.rmtree(mtrack.audio_path)
self.assertFalse(os.path.exists(mtrack.audio_path))
self.assertFalse(os.path.exists(mtrack._stem_dir_path))
self.assertFalse(os.path.exists(mtrack._raw_dir_path))
download.make_mtrack_basedir(mtrack)
self.assertTrue(os.path.exists(mtrack.audio_path))
self.assertTrue(os.path.exists(mtrack._stem_dir_path))
self.assertTrue(os.path.exists(mtrack._raw_dir_path))
class TestDownloadMetadata(unittest.TestCase):
def test_existing(self):
mtrack = MultiTrack('LizNelson_Rainfall')
download._download_metadata(mtrack.track_id, mtrack.dataset_version)
self.assertTrue(os.path.exists(mtrack.mix_path))
def test_not_in_tracklist(self):
with self.assertRaises(IOError):
download._download_metadata('Artist_Title', 'asdf')
def test_failed_download(self):
pass
class TestDownloadMix(unittest.TestCase):
def test_existing(self):
mtrack = MultiTrack('LizNelson_Rainfall')
download.download_mix(mtrack)
self.assertTrue(os.path.exists(mtrack.mix_path))
def test_not_in_tracklist(self):
mtrack = MultiTrack('MusicDelta_Beethoven')
mtrack.dataset_version = 'asdf'
with self.assertRaises(IOError):
download.download_mix(mtrack)
def test_failed_download(self):
pass
class TestDownloadStem(unittest.TestCase):
def test_existing(self):
mtrack = MultiTrack('LizNelson_Rainfall')
download.download_stem(mtrack, 1)
self.assertTrue(os.path.exists(mtrack.stems[1].audio_path))
def test_not_in_tracklist(self):
mtrack = MultiTrack('MusicDelta_Beethoven')
mtrack.dataset_version = 'asdf'
with self.assertRaises(IOError):
download.download_stem(mtrack, 1)
def test_failed_download(self):
pass
class TestDownloadRaw(unittest.TestCase):
def test_existing(self):
mtrack = MultiTrack('LizNelson_Rainfall')
download.download_raw(mtrack, 1, 1)
self.assertTrue(os.path.exists(mtrack.raw_audio[1][1].audio_path))
def test_not_in_tracklist(self):
mtrack = MultiTrack('MusicDelta_Beethoven')
mtrack.dataset_version = 'asdf'
with self.assertRaises(IOError):
download.download_raw(mtrack, 1, 1)
def test_failed_download(self):
pass
class TestGetNamedChild(unittest.TestCase):
def test_auth_failure(self):
pass
class TestGetFilesInFolder(unittest.TestCase):
def test_auth_failure(self):
pass
class TestDownloadFile(unittest.TestCase):
def test_auth_failure(self):
pass
|