def test_generate_hash_code(self): """ Tests that generate_hash_code generates a correct hash code. """ server = OpenSubtitlesServer() video_filepath = os.path.join(get_exe_dir(), 'Tests', 'Fixtures', 'hashcode.txt') expected_hash = "13fb1d63375cf197" result_hash = server.hashcode(video_filepath) self.assertEqual(result_hash, expected_hash) # Test exception file too small video_filepath = os.path.join(get_exe_dir(), 'Tests', 'Fixtures', 'hashcode_small.txt') with self.assertRaises(VideoSizeError) as error: server.hashcode(video_filepath) self.assertEqual(error.exception.video_filepath, video_filepath) # Test exception file does not exist video_filepath = os.path.join(get_exe_dir(), 'Tests', 'Fixtures', 'DUMMY') with self.assertRaises(VideoHashCodeError) as error: server.hashcode(video_filepath) self.assertEqual(error.exception.video_filepath, video_filepath) self.assertIsNotNone(error.exception.error)
def test_FileMagic_get_video_signature(self): """ Tests if FileMagic get a Video file signature. """ file_magic = FileMagic(Video.EXTENSIONS) video_filename = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'submarine.avi') not_a_video_filename = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'not_a_movie.avi') video_filename_with_bad_extension = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'submarine.mp4') # Tests if a Video file self.assertIsNotNone(file_magic.get_video_signature(video_filename)) # Tests a fake video file that raises an Exception with self.assertRaises(FileUnknownError) as error: file_magic.get_video_signature(not_a_video_filename) self.assertEqual( error.exception.filepath, not_a_video_filename) # Tests a video file with bad extensions that raises an Exception expected_signature = Signature( (82, 73, 70, 70), "Resource Interchange File Format") expected_signature.extensions.add(".avi") with self.assertRaises(FileExtensionMismatchError) as error: file_magic.get_video_signature(video_filename_with_bad_extension) self.assertEqual( error.exception.filepath, video_filename_with_bad_extension) self.assertEqual( error.exception.file_signature, expected_signature)
def test_generate_hash_code(self): """ Tests that generate_hash_code generates a correct hash code. """ server = OpenSubtitlesServer() video_filepath = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'hashcode.txt') expected_hash = "13fb1d63375cf197" result_hash = server.hashcode(video_filepath) self.assertEqual(result_hash, expected_hash) # Test exception file too small video_filepath = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'hashcode_small.txt') with self.assertRaises(VideoSizeError) as error: server.hashcode(video_filepath) self.assertEqual(error.exception.video_filepath, video_filepath) # Test exception file does not exist video_filepath = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'DUMMY') with self.assertRaises(VideoHashCodeError) as error: server.hashcode(video_filepath) self.assertEqual(error.exception.video_filepath, video_filepath) self.assertIsNotNone(error.exception.error)
def setUp(self): self.video_filename = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'movie.avi') self.expected_renamed_video_filename = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'Twin_Peaks_S01E01_Pilot.avi') self.expected_renamed_new_pattern_video_filename = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'Twin_Peaks_1x01_Pilot.avi') self.expected_renamed_video_filename_without_underscore = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'Twin Peaks S01E01 Pilot.avi')
def setUp(self): self.video_filename = os.path.join(get_exe_dir(), 'Tests', 'Fixtures', 'movie.avi') self.expected_renamed_video_filename = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'Twin_Peaks_S01E01_Pilot.avi') self.expected_renamed_new_pattern_video_filename = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'Twin_Peaks_1x01_Pilot.avi') self.expected_renamed_video_filename_without_underscore = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'Twin Peaks S01E01 Pilot.avi')
def setUp(self): self.languages = ['eng', 'fra'] self.babel_languages = [ babelfish.Language(code) for code in self.languages ] self.mock_hashcode = lambda filepath: "8fcf0167e19c41be" self.video_filename = os.path.join(get_exe_dir(), 'Tests', 'Fixtures', 'movie.avi') self.video2_filename = os.path.join(get_exe_dir(), 'Tests', 'Fixtures', 'small.mp4') self.expected_french_subtitle_filename = \ os.path.join(get_exe_dir(), 'Tests', 'Fixtures', 'movie.fr.srt') self.expected_english_subtitle_filename = \ os.path.join(get_exe_dir(), 'Tests', 'Fixtures', 'movie.en.srt') self.expected_renamed_video_filename = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'Louie_S01E01_Pilot.avi') self.expected_renamed_french_subtitle_filename = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'Louie_S01E01_Pilot.fr.srt') self.expected_renamed_english_subtitle_filename = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'Louie_S01E01_Pilot.en.srt')
def setUp(self): self.languages = ['eng', 'fra'] self.babel_languages = [ babelfish.Language(code) for code in self.languages ] self.mock_hashcode = lambda filepath: "8fcf0167e19c41be" self.video_filename = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'movie.avi') self.video2_filename = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'small.mp4') self.expected_french_subtitle_filename = \ os.path.join(get_exe_dir(), 'Tests', 'Fixtures', 'movie.fr.srt') self.expected_english_subtitle_filename = \ os.path.join(get_exe_dir(), 'Tests', 'Fixtures', 'movie.en.srt') self.expected_renamed_video_filename = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'Louie_S01E01_Pilot.avi') self.expected_renamed_french_subtitle_filename = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'Louie_S01E01_Pilot.fr.srt') self.expected_renamed_english_subtitle_filename = os.path.join( get_exe_dir(), 'Tests', 'Fixtures', 'Louie_S01E01_Pilot.en.srt')
import sys import os import argparse import babelfish from sublime import util from sublime.server import SubtitleProvider from sublime.core import Episode from sublime.core import VideoFactory __version__ = util.get_version_from_git() # Gets execution directory exe_dir = util.get_exe_dir() # Sets environment variable for the application os.environ['SUBLIME_HOME'] = exe_dir # Gets a logger LOG = util.init_logging() def execute(args): """ Executes SubLime with given arguments. """ videos = [] selected_languages = [ babelfish.Language(selected_lang) for selected_lang in args.selected_languages ]