def test_correctTime2(self): a = fixParams(d='Movie-Before', s=4, e=-4, m=3600) r = correctTime(a, '00:00:00,000') self.assertEqual(r, '00:00:04,000', '4, -4, start') r = correctTime(a, '00:30:00,000') self.assertEqual(r, '00:30:00,000', '4, -4, middle') r = correctTime(a, '01:00:00,000') self.assertEqual(r, '00:59:56,000', '4, -4, end')
def test_correctTime3(self): a = fixParams(d='Movie-After', s=-4, e=4, m=3600) r = correctTime(a, '00:00:00,000') self.assertEqual(r, '00:00:00,000', '-4, 4, start') r = correctTime(a, '00:00:10,000') self.assertEqual(r, '00:00:06,022', '-4, 4, start') r = correctTime(a, '00:30:00,000') self.assertEqual(r, '00:30:00,000', '-4, 4, middle') r = correctTime(a, '01:00:00,000') self.assertEqual(r, '01:00:04,000', '-4, 4, end')
def test_calculateOffset(self): srtFix.main.getMovieLenFromFile = MagicMock(return_value=3) args = fixParams() args.direction, args.endDiff, args.startDiff = 'movie-before', 2, 3.3 res = calculateOffset(args) self.assertTrue( res.direction == args.direction and res.endDiff == -2 and res.startDiff == -3.3 and res.movieLen == 3, 'Movie-Before, with end-diff') args.direction, args.startDiff, args.endDiff = 'movie-after', 4.2, None res = calculateOffset(args) self.assertTupleEqual((res.direction, res.endDiff, res.startDiff), (args.direction, 4.2, 4.2), 'Movie-after, without end-diff')
def go(self): try: print ("startDiff:{0},endDiff:{1},dir:{2},file:{3}".format(self.startDiff.get(),self.endDiff.get(),self.dirVal,self.filename)) #pack paramaters and process file sd=float(self.startDiff.get()) #r=parse('{n:d}',self.endDiff.get()) ed= None if None == self.endDiff.get() else float(self.endDiff.get()) params=fixParams(f=self.filename,s=sd,e=ed, d=self.dirVal) self.toScreenLog("startDiff:{0},endDiff:{1},dir:{2},file:{3}".format(params.startDiff,params.endDiff,params.direction,params.fname)) calculateOffset(params) #self.toScreenLog("movie len:{0},out file name:{1}".format(params.movieLen,params.outfname)) processFile(params) self.toScreenLog("Done. Output file:%s" % params.outfname) except ValueError: self.toScreenLog('Enter a number in the Diff fields') except IOError: e=sys.exc_info()[0] self.toScreenLog(e) print('Try again') except: e=sys.exc_info()[0] print("Unexpected error:", e) raise