File: test_types.py

package info (click to toggle)
beets 2.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,988 kB
  • sloc: python: 46,429; javascript: 8,018; xml: 334; sh: 261; makefile: 125
file content (58 lines) | stat: -rw-r--r-- 1,525 bytes parent folder | download
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
import time

import beets
from beets.dbcore import types
from beets.util import normpath


def test_datetype():
    t = types.DATE

    # format
    time_format = beets.config["time_format"].as_str()
    time_local = time.strftime(time_format, time.localtime(123456789))
    assert time_local == t.format(123456789)
    # parse
    assert 123456789.0 == t.parse(time_local)
    assert 123456789.0 == t.parse("123456789.0")
    assert t.null == t.parse("not123456789.0")
    assert t.null == t.parse("1973-11-29")


def test_pathtype():
    t = types.PathType()

    # format
    assert "/tmp" == t.format("/tmp")
    assert "/tmp/\xe4lbum" == t.format("/tmp/\u00e4lbum")
    # parse
    assert normpath(b"/tmp") == t.parse("/tmp")
    assert normpath(b"/tmp/\xc3\xa4lbum") == t.parse("/tmp/\u00e4lbum/")


def test_musicalkey():
    t = types.MusicalKey()

    # parse
    assert "C#m" == t.parse("c#m")
    assert "Gm" == t.parse("g   minor")
    assert "Not c#m" == t.parse("not C#m")


def test_durationtype():
    t = types.DurationType()

    # format
    assert "1:01" == t.format(61.23)
    assert "60:01" == t.format(3601.23)
    assert "0:00" == t.format(None)
    # parse
    assert 61.0 == t.parse("1:01")
    assert 61.23 == t.parse("61.23")
    assert 3601.0 == t.parse("60:01")
    assert t.null == t.parse("1:00:01")
    assert t.null == t.parse("not61.23")
    # config format_raw_length
    beets.config["format_raw_length"] = True
    assert 61.23 == t.format(61.23)
    assert 3601.23 == t.format(3601.23)