-
Notifications
You must be signed in to change notification settings - Fork 60
/
test.py
executable file
·59 lines (42 loc) · 1.72 KB
/
test.py
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
#!/usr/bin/env python
import sys
if sys.version_info < (2, 3):
raise RuntimeError('Python 2.3+ is required.')
import logging
import os
import shutil
import subprocess
import unittest
import tests
TEST_FILE_NAME = 'test.mkv'
BASE_PATH = os.path.dirname(__file__)
WORK_PATH = os.path.join(BASE_PATH, 'work')
TEST_FILE = os.path.join(BASE_PATH, TEST_FILE_NAME)
def main():
if os.path.exists(WORK_PATH):
shutil.rmtree(WORK_PATH)
os.mkdir(WORK_PATH)
if not os.path.exists(TEST_FILE):
raise ValueError('Could not locate test file.')
unittest.TextTestRunner(verbosity=2).run(unittest.TestSuite([
unittest.defaultTestLoader.loadTestsFromModule(tests)
]))
shutil.rmtree(WORK_PATH)
if __name__ == '__main__':
main()
class Base(unittest.TestCase):
def setUp(self):
self.work_path = os.path.join(WORK_PATH, self.__class__.__name__)
self.test_file = os.path.join(self.work_path, TEST_FILE_NAME)
if os.path.exists(self.work_path):
raise ValueError('Work path "%s" already exists.' % self.work_path)
os.mkdir(self.work_path)
shutil.copyfile(TEST_FILE, self.test_file)
def test_file_exists(self):
self.assertTrue(os.path.exists(self.test_file))
def test_file_valid(self):
output = subprocess.Popen(['mkvmerge', '-i', TEST_FILE_NAME], cwd=self.work_path, stdout=subprocess.PIPE).communicate()[0]
output = output.replace('\r', '').strip()
self.assertEquals(output, '''File 'test.mkv': container: Matroska\nTrack ID 1: video (V_MPEG4/ISO/AVC)\nTrack ID 2: audio (A_DTS)\nTrack ID 3: subtitles (S_TEXT/UTF8)\nTrack ID 4: subtitles (S_TEXT/UTF8)''')
def tearDown(self):
shutil.rmtree(self.work_path)