File: test_aac.py

package info (click to toggle)
picard 2.13.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,012 kB
  • sloc: python: 68,818; ansic: 89; makefile: 14
file content (98 lines) | stat: -rw-r--r-- 3,278 bytes parent folder | download | duplicates (3)
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
# -*- coding: utf-8 -*-
#
# Picard, the next-generation MusicBrainz tagger
#
# Copyright (C) 2019 Philipp Wolfer
# Copyright (C) 2020-2021 Laurent Monin
#
# 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.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


import os

from picard import config
from picard.formats.apev2 import AACFile
from picard.metadata import Metadata

from .common import (
    CommonTests,
    load_metadata,
    save_and_load_metadata,
)
from .test_apev2 import CommonApeTests


class AACTest(CommonTests.SimpleFormatsTestCase):
    testfile = 'test.aac'
    expected_info = {
        'length': 120,
        '~channels': '2',
        '~sample_rate': '44100',
        '~bitrate': '123.824',
    }
    unexpected_info = ['~video']


class AACWithAPETest(CommonApeTests.ApeTestCase):
    testfile = 'test-apev2.aac'
    supports_ratings = False
    expected_info = {
        'length': 119,
        '~channels': '2',
        '~sample_rate': '44100',
        '~bitrate': '123.824',
    }
    unexpected_info = ['~video']


class AACNoTagsTest(CommonTests.BaseFileTestCase):
    testfile = 'test-apev2.aac'

    def setUp(self):
        super().setUp()
        config.setting['aac_save_ape'] = False
        config.setting['remove_ape_from_aac'] = False

    def test_load_but_do_not_save_tags(self):
        metadata = load_metadata(self.filename)
        self.assertEqual('Test AAC with APEv2 tags', metadata['title'])
        self.assertEqual('The Artist', metadata['artist'])
        metadata['artist'] = 'Foo'
        metadata['title'] = 'Bar'
        metadata = save_and_load_metadata(self.filename, metadata)
        self.assertEqual('Test AAC with APEv2 tags', metadata['title'])
        self.assertEqual('The Artist', metadata['artist'])

    def test_remove_ape_tags(self):
        config.setting['remove_ape_from_aac'] = True
        metadata = Metadata({
            'artist': 'Foo'
        })
        metadata = save_and_load_metadata(self.filename, metadata)
        self.assertEqual('AAC', metadata['~format'])
        self.assertNotIn('title', metadata)
        self.assertNotIn('artist', metadata)

    def test_info_format(self):
        metadata = load_metadata(os.path.join('test', 'data', 'test.aac'))
        self.assertEqual('AAC', metadata['~format'])
        metadata = load_metadata(os.path.join('test', 'data', 'test-apev2.aac'))
        self.assertEqual('AAC (APEv2)', metadata['~format'])

    def test_supports_tag(self):
        config.setting['aac_save_ape'] = True
        self.assertTrue(AACFile.supports_tag('title'))
        config.setting['aac_save_ape'] = False
        self.assertFalse(AACFile.supports_tag('title'))