File: test_formats_aac.py

package info (click to toggle)
quodlibet 4.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,228 kB
  • sloc: python: 89,728; sh: 381; xml: 110; makefile: 91
file content (87 lines) | stat: -rw-r--r-- 2,405 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
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
# Copyright 2014 Christoph Reiter
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

import os

from mutagen.aac import AAC

from quodlibet.formats.aac import AACFile

from . import TestCase, get_data_path, skipUnless
from .helper import get_temp_copy


class _TAACFile(TestCase):
    NAME = None

    def setUp(self):
        self.f = get_temp_copy(get_data_path(self.NAME))
        self.song = AACFile(self.f)

    def tearDown(self):
        os.unlink(self.f)


class _TAACFileMixin:
    def test_basic(self):
        self.song["title"] = "SomeTestValue"
        self.song.write()
        self.song.reload()
        self.assertEqual(self.song("title"), "SomeTestValue")

    def test_write(self):
        self.song.write()

    def test_can_change(self):
        assert self.song.can_change("title")
        assert not self.song.can_change("foobar")
        assert "title" in self.song.can_change()

    def test_can_multiple_values(self):
        self.assertEqual(self.song.can_multiple_values(), True)
        assert self.song.can_multiple_values("title")

    def test_invalid(self):
        path = get_data_path("empty.xm")
        assert os.path.exists(path)
        self.assertRaises(Exception, AACFile, path)

    def test_format_codec(self):
        self.assertEqual(self.song("~format"), "AAC")
        self.assertEqual(self.song("~codec"), "AAC")
        self.assertEqual(self.song("~encoding"), "")

    def test_channels(self):
        assert self.song("~#channels") == 2


@skipUnless(AAC, "too old mutagen")
class TADTSFile(_TAACFile, _TAACFileMixin):
    NAME = "empty.aac"

    def test_length(self):
        self.assertAlmostEqual(self.song("~#length"), 3.7, 2)

    def test_bitrate(self):
        self.assertEqual(self.song("~#bitrate"), 3)

    def test_samplerate(self):
        assert self.song("~#samplerate") == 44100


@skipUnless(AAC, "too old mutagen")
class TADIFFile(_TAACFile, _TAACFileMixin):
    NAME = "adif.aac"

    def test_length(self):
        self.assertAlmostEqual(self.song("~#length"), 0.25, 2)

    def test_bitrate(self):
        self.assertEqual(self.song("~#bitrate"), 128)

    def test_samplerate(self):
        assert self.song("~#samplerate") == 48000