コード例 #1
0
ファイル: test_module.py プロジェクト: dem214/xspf-lib
def test_playlist_init():
    pl = Playlist(
        title="That playlist",
        creator="myself",
        annotation="additional user info",
        info="https://path_to_more.info",
        location="file:///playlist.xspf",
        identifier="this.playlist",
        image="file:///default_cover.png",
        license="CC",
        attribution=[
            Playlist(identifier="previous.playlist",
                     location="file:///last.playlist.xspf")
        ],
        link=[Link("link_type", "link_uri")],
        meta=[
            Meta("meta_type1", "metadata1"),
            Meta("meta_type1", "metadata2")
        ],
        extension=[Extension("appl", content=[Element('a', {'attr': "1"})])],
        trackList=[Track(title="tr1"), Track(title="tr2")])
    pl.date = datetime(2020, 4, 20, 12, 30, 1, 123456)
    response = '<playlist version="1" xmlns="http://xspf.org/ns/0/">'\
               '<title>That playlist</title>'\
               '<creator>myself</creator>'\
               '<annotation>additional user info</annotation>'\
               '<info>https://path_to_more.info</info>'\
               '<location>file:///playlist.xspf</location>'\
               '<identifier>this.playlist</identifier>'\
               '<image>file:///default_cover.png</image>'\
               '<date>2020-04-20T12:30:01.123456</date>'\
               '<license>CC</license>'\
               '<attribution>'\
               '<location>file:///last.playlist.xspf</location>'\
               '<identifier>previous.playlist</identifier>'\
               '</attribution>'\
               '<link rel="link_type">link_uri</link>'\
               '<meta rel="meta_type1">metadata1</meta>'\
               '<meta rel="meta_type1">metadata2</meta>'\
               '<extension application="appl">''<a attr="1" /></extension>'\
               '<trackList>'\
               '<track><title>tr1</title></track>'\
               '<track><title>tr2</title></track>'\
               '</trackList>'\
               '</playlist>'
    assert pl.xml_string() == response
コード例 #2
0
ファイル: test_module.py プロジェクト: dem214/xspf-lib
def test_playlist_writing():
    import xspf_lib as xspf
    killer_queen = Track(location="file:///home/music/killer_queen.mp3",
                         title="Killer Queen",
                         creator="Queen",
                         album="Sheer Heart Attack",
                         trackNum=2,
                         duration=177000,
                         annotation="#2 in GB 1975",
                         info="https://ru.wikipedia.org/wiki/Killer_Queen",
                         image="file:///home/images/killer_queen_cover.png")
    anbtd = Track()
    anbtd.location = [
        "https://freemusic.example.com/loc.ogg", "file:///home/music/anbtd.mp3"
    ]
    anbtd.title = "Another One Bites the Dust"
    anbtd.creator = "Queen"
    anbtd.identifier = ["id1.group"]
    anbtd.link = [Link("link.namespace", "link.uri.info")]
    anbtd.meta = [Meta("meta.namespace", "METADATA_INFO")]
    playlist = Playlist(title="Some Tracks",
                        creator="myself",
                        annotation="I did this only for examples!.",
                        trackList=[killer_queen, anbtd])
    playlist.date = datetime(2020, 4, 20, 12, 30, 1, 123456)
    playlist.write("some_tracks.xspf")
    with open('some_tracks.xspf', 'r') as file:
        playlist_xml = file.read()
    assert playlist_xml == '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n'\
        '<playlist version="1" xmlns="http://xspf.org/ns/0/"><title>Some'\
        ' Tracks</title><creator>myself</creator><annotation>I did this '\
        'only for examples!.</annotation><date>2020-04-20T12:30:01.123456'\
        '</date><trackList><track><location>'\
        'file:///home/music/killer_queen.mp3</location><title>Killer Queen'\
        '</title><creator>Queen</creator><annotation>#2 in GB 1975'\
        '</annotation><info>https://ru.wikipedia.org/wiki/Killer_Queen'\
        '</info><image>file:///home/images/killer_queen_cover.png</image>'\
        '<album>Sheer Heart Attack</album><trackNum>2</trackNum><duration>'\
        '177000</duration></track><track><location>'\
        'https://freemusic.example.com/loc.ogg</location><location>'\
        'file:///home/music/anbtd.mp3</location><identifier>id1.group'\
        '</identifier><title>Another One Bites the Dust</title><creator>'\
        'Queen</creator><link rel="link.namespace">link.uri.info</link>'\
        '<meta rel="meta.namespace">METADATA_INFO</meta></track></trackList>'\
        '</playlist>'
    os.remove('some_tracks.xspf')