]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Lib/test/test_aifc.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / test / test_aifc.py
CommitLineData
4710c53d 1from test.test_support import findfile, run_unittest, TESTFN\r
2import unittest\r
3import os\r
4\r
5import aifc\r
6\r
7\r
8class AIFCTest(unittest.TestCase):\r
9\r
10 def setUp(self):\r
11 self.f = self.fout = None\r
12 self.sndfilepath = findfile('Sine-1000Hz-300ms.aif')\r
13\r
14 def tearDown(self):\r
15 if self.f is not None:\r
16 self.f.close()\r
17 if self.fout is not None:\r
18 try:\r
19 self.fout.close()\r
20 except (aifc.Error, AttributeError):\r
21 pass\r
22 try:\r
23 os.remove(TESTFN)\r
24 except OSError:\r
25 pass\r
26\r
27 def test_skipunknown(self):\r
28 #Issue 2245\r
29 #This file contains chunk types aifc doesn't recognize.\r
30 self.f = aifc.open(self.sndfilepath)\r
31\r
32 def test_params(self):\r
33 f = self.f = aifc.open(self.sndfilepath)\r
34 self.assertEqual(f.getnchannels(), 2)\r
35 self.assertEqual(f.getsampwidth(), 2)\r
36 self.assertEqual(f.getframerate(), 48000)\r
37 self.assertEqual(f.getnframes(), 14400)\r
38 self.assertEqual(f.getcomptype(), 'NONE')\r
39 self.assertEqual(f.getcompname(), 'not compressed')\r
40 self.assertEqual(f.getparams(), (2, 2, 48000, 14400, 'NONE', 'not compressed'))\r
41\r
42 def test_read(self):\r
43 f = self.f = aifc.open(self.sndfilepath)\r
44 self.assertEqual(f.tell(), 0)\r
45 self.assertEqual(f.readframes(2), '\x00\x00\x00\x00\x0b\xd4\x0b\xd4')\r
46 f.rewind()\r
47 pos0 = f.tell()\r
48 self.assertEqual(pos0, 0)\r
49 self.assertEqual(f.readframes(2), '\x00\x00\x00\x00\x0b\xd4\x0b\xd4')\r
50 pos2 = f.tell()\r
51 self.assertEqual(pos2, 2)\r
52 self.assertEqual(f.readframes(2), '\x17t\x17t"\xad"\xad')\r
53 f.setpos(pos2)\r
54 self.assertEqual(f.readframes(2), '\x17t\x17t"\xad"\xad')\r
55 f.setpos(pos0)\r
56 self.assertEqual(f.readframes(2), '\x00\x00\x00\x00\x0b\xd4\x0b\xd4')\r
57\r
58 def test_write(self):\r
59 f = self.f = aifc.open(self.sndfilepath)\r
60 fout = self.fout = aifc.open(TESTFN, 'wb')\r
61 fout.aifc()\r
62 fout.setparams(f.getparams())\r
63 for frame in range(f.getnframes()):\r
64 fout.writeframes(f.readframes(1))\r
65 fout.close()\r
66 fout = self.fout = aifc.open(TESTFN, 'rb')\r
67 f.rewind()\r
68 self.assertEqual(f.getparams(), fout.getparams())\r
69 self.assertEqual(f.readframes(5), fout.readframes(5))\r
70\r
71 def test_compress(self):\r
72 f = self.f = aifc.open(self.sndfilepath)\r
73 fout = self.fout = aifc.open(TESTFN, 'wb')\r
74 fout.aifc()\r
75 fout.setnchannels(f.getnchannels())\r
76 fout.setsampwidth(f.getsampwidth())\r
77 fout.setframerate(f.getframerate())\r
78 fout.setcomptype('ULAW', 'foo')\r
79 for frame in range(f.getnframes()):\r
80 fout.writeframes(f.readframes(1))\r
81 fout.close()\r
82 self.assertLess(\r
83 os.stat(TESTFN).st_size,\r
84 os.stat(self.sndfilepath).st_size*0.75,\r
85 )\r
86 fout = self.fout = aifc.open(TESTFN, 'rb')\r
87 f.rewind()\r
88 self.assertEqual(f.getparams()[0:3], fout.getparams()[0:3])\r
89 self.assertEqual(fout.getcomptype(), 'ULAW')\r
90 self.assertEqual(fout.getcompname(), 'foo')\r
91 # XXX: this test fails, not sure if it should succeed or not\r
92 # self.assertEqual(f.readframes(5), fout.readframes(5))\r
93\r
94 def test_close(self):\r
95 class Wrapfile(object):\r
96 def __init__(self, file):\r
97 self.file = open(file, 'rb')\r
98 self.closed = False\r
99 def close(self):\r
100 self.file.close()\r
101 self.closed = True\r
102 def __getattr__(self, attr): return getattr(self.file, attr)\r
103 testfile = Wrapfile(self.sndfilepath)\r
104 f = self.f = aifc.open(testfile)\r
105 self.assertEqual(testfile.closed, False)\r
106 f.close()\r
107 self.assertEqual(testfile.closed, True)\r
108\r
109\r
110def test_main():\r
111 run_unittest(AIFCTest)\r
112\r
113\r
114if __name__ == "__main__":\r
115 unittest.main()\r