本文整理汇总了Python中ssyncer.strack.strack函数的典型用法代码示例。如果您正苦于以下问题:Python strack函数的具体用法?Python strack怎么用?Python strack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了strack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_metadata
def test_metadata(self):
"""
Test metadata has been loaded from json object
and get method return metadata value from a given key.
"""
client = Mock()
object = strack(json_data[0], client=client)
self.assertEquals(1337, object.get("id"))
self.assertEquals("Foo", object.get("title"))
self.assertEquals("foo", object.get("permalink"))
self.assertEquals("user1", object.get("username"))
self.assertTrue(object.get("downloadable"))
self.assertEquals("mp3", object.get("ext"))
object = strack(json_data[1], client=client)
self.assertEquals(1338, object.get("id"))
self.assertEquals("Bar", object.get("title"))
self.assertEquals("bar", object.get("permalink"))
self.assertEquals("user2", object.get("username"))
self.assertFalse(object.get("downloadable"))
self.assertEquals("mp3", object.get("ext"))
object = strack(json_data[2], client=client)
self.assertEquals(1339, object.get("id"))
self.assertEquals("Baz", object.get("title"))
self.assertEquals("baz", object.get("permalink"))
self.assertEquals("user3", object.get("username"))
self.assertTrue(object.get("downloadable"))
self.assertEquals("wav", object.get("ext"))
示例2: test_convert
def test_convert(self):
"""Test convert method."""
client = Mock()
object = strack(json_obj[2], client=client)
object.downloaded = True
object.filepath = self.tmpdir + "/user3/1339-baz.wav"
os.mkdir("%s/user3" % self.tmpdir)
f = open("%s/user3/1339-baz.wav" % self.tmpdir, "w+")
f.write("0" * 5)
f.close()
songmock = Mock()
with patch("ssyncer.strack.AudioSegment.from_file",
return_value=songmock) as asegment:
with patch("ssyncer.strack.magic.from_file",
return_value=b"audio/x-wav"):
object.convert()
self.assertTrue(os.path.exists(
"%s/backups/user3/1339-baz.wav" % self.tmpdir))
self.assertEquals(
"%s/user3/1339-baz.mp3" % self.tmpdir, object.filepath)
asegment.assert_called_once_with(
"%s/backups/user3/1339-baz.wav" % self.tmpdir)
songmock.export.assert_called_once_with(
"%s/user3/1339-baz.mp3" % self.tmpdir,
format="mp3")
示例3: test_load_id3
def test_load_id3(self):
""" Test load id3 tags """
tag = stag()
tag._process_artwork_tmpfile = Mock(return_value=False)
client = Mock()
track = strack(json_obj[0], client=client)
tag.load_id3(track)
self.assertEqual("Some text", tag.mapper._frames["TIT1"][0].text[0])
self.assertEqual("Foo", tag.mapper._frames["TIT2"][0].text[0])
self.assertEqual("dubstep bass", tag.mapper._frames["TIT3"][0].text[0])
self.assertEqual("1387373820", tag.mapper._frames["TDOR"][0].text[0])
self.assertEqual("247010", tag.mapper._frames["TLEN"][0].text[0])
self.assertEqual("foo", tag.mapper._frames["TOFN"][0].text[0])
self.assertEqual("Dubstep", tag.mapper._frames["TCON"][0].text[0])
self.assertEqual("free", tag.mapper._frames["TCOP"][0].text[0])
self.assertEqual("https://foobar.dev/1337",
tag.mapper._frames["WOAS"][0].url)
self.assertEqual("https://api.foobar.dev/1337",
tag.mapper._frames["WOAF"][0].url)
self.assertEqual("user1", tag.mapper._frames["TPUB"][0].text[0])
self.assertEqual("http://user1.dev",
tag.mapper._frames["WOAR"][0].url)
self.assertEqual("User 1", tag.mapper._frames["TPE1"][0].text[0])
self.assertEqual("User 1 Soundcloud tracks",
tag.mapper._frames["TALB"][0].text[0])
示例4: test_write_id3
def test_write_id3(self):
""" Test write id3 tags """
sandbox = os.path.dirname(os.path.realpath(__file__)) + "/sandbox/"
sample = os.path.dirname(os.path.realpath(__file__)) + "/samples/"
filename = "92583301-dem-beats-3.mp3"
if not os.path.exists(sandbox):
os.mkdir(sandbox)
shutil.copyfile(sample + filename, sandbox + filename)
tag = stag()
tag._process_artwork_tmpfile = Mock(return_value=False)
client = Mock()
track = strack(json_obj[0], client=client)
tag.load_id3(track)
tag.write_id3(sandbox + filename)
res = stagger.read_tag(sandbox + filename)
self.assertEqual("Some text", res[TIT1].text[0])
self.assertEqual("Foo", res[TIT2].text[0])
self.assertEqual("dubstep bass", res[TIT3].text[0])
self.assertEqual("247010", res[TLEN].text[0])
self.assertEqual("foo", res[TOFN].text[0])
self.assertEqual("Dubstep", res[TCON].text[0])
self.assertEqual("free", res[TCOP].text[0])
self.assertEqual("1387373820", res[TDOR].text[0])
self.assertEqual("https://foobar.dev/1337", res[WOAS].url)
self.assertEqual("https://api.foobar.dev/1337", res[WOAF].url)
self.assertEqual("user1", res[TPUB].text[0])
self.assertEqual("http://user1.dev", res[WOAR][0].url)
self.assertEqual("User 1", res[TPE1].text[0])
self.assertEqual("User 1 Soundcloud tracks", res[TALB].text[0])
shutil.rmtree(sandbox)
示例5: test_process_tags_raises_error_when_track_not_downloaded
def test_process_tags_raises_error_when_track_not_downloaded(self):
"""
Test process_tags method raises error when track is not downloaded.
"""
client = Mock()
object = strack(json_obj[0], client=client)
object.downloaded = False
self.assertRaises(serror, object.process_tags)
示例6: test_gen_filename
def test_gen_filename(self):
"""
Test generated local filename look like this:
{id}-{permalink}.
"""
client = Mock()
object = strack(json_obj[2], client=client)
self.assertEquals("1339-baz", object.gen_filename())
示例7: test_convert_return_false_when_file_already_mpeg_format
def test_convert_return_false_when_file_already_mpeg_format(self):
"""Test convert raises error if file is already in mpeg format."""
client = Mock()
object = strack(json_obj[0], client=client)
object.downloaded = True
object.filepath = "user1/1337-bar.mp3"
with patch("ssyncer.strack.magic.from_file",
return_value="audio/mpeg"):
self.assertFalse(object.convert())
示例8: test_get_file_extension_from_metadata
def test_get_file_extension_from_metadata(self):
"""Test get_file_extension return extension depending of metadata."""
client = Mock()
object = strack(json_obj[2], client=client)
with patch("ssyncer.strack.magic.from_file",
return_value="audio/unknown"):
self.assertEquals(".wav",
object.get_file_extension(
"user3/1339-baz"))
示例9: test_get_file_extension_with_bytes_mimetype
def test_get_file_extension_with_bytes_mimetype(self):
"""Test get_file_extension return extension when mtype is bytes."""
client = Mock()
object = strack(json_obj[2], client=client)
with patch("ssyncer.strack.magic.from_file",
return_value=b"audio/mpeg"):
self.assertEquals(".mp3",
object.get_file_extension(
"user3/1339-baz"))
示例10: _parse_tracks_response
def _parse_tracks_response(self, response):
""" Parse http response that contents tracks list. """
objects = json.loads(response.read().decode("utf-8"))
tracks = []
for track in objects:
tracks.append(strack(track, client=self.client))
return tracks
示例11: test_get_file_extension_from_mimetype_mp3
def test_get_file_extension_from_mimetype_mp3(self):
"""Test get_file_extension return extension depending of mimetype."""
client = Mock()
object = strack(json_obj[2], client=client)
with patch("ssyncer.strack.magic.from_file",
return_value="audio/mpeg"):
self.assertEquals(".mp3",
object.get_file_extension(
"user3/1339-baz"))
示例12: test_process_tags_raises_error_if_not_mpeg
def test_process_tags_raises_error_if_not_mpeg(self):
"""Test process_tags() raises error if file is not in mpeg format."""
client = Mock()
object = strack(json_obj[2], client=client)
object.downloaded = True
object.filepath = "user3/1339-baz.wav"
with patch("ssyncer.strack.magic.from_file",
return_value="audio/x-wav"):
self.assertRaises(serror, object.process_tags)
示例13: test_track_exists
def test_track_exists(self):
""" Test track exists. """
os.mkdir("%s/user1" % self.tmpdir)
f = open("%s/user1/1337-foo.mp3" % self.tmpdir, "w")
f.write("0" * 5)
f.close()
client = Mock()
object = strack(json_obj[0], client=client)
self.assertTrue(object.track_exists(self.tmpdir))
示例14: test_get_download_link_not_downloadable
def test_get_download_link_not_downloadable(self):
""" Test get download link from stream url. """
client = Mock()
client.DOWNLOAD_URL = "mock_download_url_%d"
client.STREAM_URL = "mock_stream_url_%d"
client.get_location.return_value = "http://lost.iya"
object = strack(json_obj[1], client=client)
self.assertEquals("http://lost.iya", object.get_download_link())
client.get_location.assert_called_with("mock_stream_url_1338")
self.assertEquals(1, client.get_location.call_count)
示例15: test_get_track_ignored
def test_get_track_ignored(self):
""" Test get track ignored list. """
f = open("%s/.ignore" % self.tmpdir, "w")
f.write("foo\nbar\nbaz")
f.close()
client = Mock()
object = strack(json_obj[0], client=client)
ignored = object.get_ignored_tracks(self.tmpdir)
self.assertIn("%s/foo" % self.tmpdir, ignored)
self.assertIn("%s/bar" % self.tmpdir, ignored)
self.assertIn("%s/baz" % self.tmpdir, ignored)