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
8import os
9
10from tests import TestCase, get_data_path
11from quodlibet.formats.mpc import MPCFile
12
13
14class TMPCFile(TestCase):
15
16    def setUp(self):
17        self.song = MPCFile(get_data_path('silence-44-s.mpc'))
18        self.song2 = MPCFile(get_data_path('silence-44-s.sv8.mpc'))
19
20    def test_length(self):
21        self.assertAlmostEqual(self.song("~#length"), 0.065306, 3)
22        self.assertAlmostEqual(self.song2("~#length"), 3.684716, 3)
23
24    def test_channels(self):
25        assert self.song("~#channels") == 2
26        assert self.song2("~#channels") == 2
27
28    def test_samplerate(self):
29        assert self.song("~#samplerate") == 44100
30        assert self.song2("~#samplerate") == 44100
31
32    def test_bitrate(self):
33        self.failUnlessEqual(self.song("~#bitrate"), 239)
34        self.failUnlessEqual(self.song2("~#bitrate"), 1)
35
36    def test_invalid(self):
37        path = get_data_path('empty.xm')
38        self.failUnless(os.path.exists(path))
39        self.failUnlessRaises(Exception, MPCFile, path)
40
41    def test_format(self):
42        self.assertEqual(self.song("~format"), "Musepack")
43        self.assertEqual(self.song2("~format"), "Musepack")
44
45    def test_codec(self):
46        self.assertEqual(self.song("~codec"), "Musepack SV7")
47        self.assertEqual(self.song2("~codec"), "Musepack SV8")
48
49    def test_encoding(self):
50        self.assertEqual(self.song("~encoding"), "")
51        self.assertEqual(self.song2("~encoding"), "")
52