1# Copyright 2015 Christoph Reiter
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7
8from tests import TestCase, get_data_path
9from quodlibet.formats.mp3 import MP3File
10
11
12class TMP3File(TestCase):
13
14    def setUp(self):
15        self.song = MP3File(get_data_path('silence-44-s.mp3'))
16        self.song2 = MP3File(get_data_path('test.mp2'))
17        self.song3 = MP3File(get_data_path('lame.mp3'))
18
19    def test_channels(self):
20        assert self.song("~#channels") == 2
21        assert self.song2("~#channels") == 1
22        assert self.song3("~#channels") == 2
23
24    def test_samplerate(self):
25        assert self.song("~#samplerate") == 44100
26        assert self.song2("~#samplerate") == 32000
27        assert self.song3("~#samplerate") == 44100
28
29    def test_length(self):
30        self.assertAlmostEqual(self.song("~#length"), 3.77, 2)
31        self.assertAlmostEqual(self.song2("~#length"), 1.764, 3)
32        self.assertAlmostEqual(self.song3("~#length"), 0.0616, 3)
33
34    def test_bitrate(self):
35        self.failUnlessEqual(self.song("~#bitrate"), 32)
36        self.failUnlessEqual(self.song2("~#bitrate"), 32)
37        # 127 with mutagen 1.39+
38        assert self.song3("~#bitrate") in [127, 270]
39
40    def test_format(self):
41        self.assertEqual(self.song("~format"), "MP3")
42        self.assertEqual(self.song2("~format"), "MP2")
43        self.assertEqual(self.song3("~format"), "MP3")
44
45    def test_codec(self):
46        self.assertEqual(self.song("~codec"), "MP3")
47        self.assertEqual(self.song2("~codec"), "MP2")
48        self.assertEqual(self.song3("~codec"), "MP3")
49
50    def test_encoding(self):
51        self.assertEqual(self.song("~encoding"), "")
52        self.assertEqual(self.song2("~encoding"), "")
53        assert self.song3("~encoding") in [
54            "LAME 3.99.1+\nVBR", "LAME 3.99.1+\nVBR\n-V 2"]
55