Browse Source

调整测试代码,提高效率

Signed-off-by: allan716 <[email protected]>
allan716 3 years ago
parent
commit
348aa89a76
2 changed files with 32 additions and 16 deletions
  1. 10 14
      TestCode/test_statistics_subs_score.go
  2. 22 2
      TestCode/test_statistics_subs_score_test.go

+ 10 - 14
TestCode/test_statistics_subs_score.go

@@ -5,6 +5,9 @@ import (
 	"os"
 	"path/filepath"
 
+	"github.com/allanpk716/ChineseSubFinder/pkg/ffmpeg_helper"
+	"github.com/prometheus/common/log"
+
 	"github.com/allanpk716/ChineseSubFinder/pkg/types/subparser"
 	"github.com/huandu/go-clone"
 
@@ -206,20 +209,13 @@ func statistics_subs_score(baseAudioFileFPath, baseSubFileFPath, subSearchRootPa
 	}
 }
 
-func statistics_subs_score_is_match(videoFPath, subSearchRootPath string) {
-
-	log := log_helper.GetLogger4Tester()
-	s := sub_timeline_fixer.NewSubTimelineFixerHelperEx(log, *settings.NewTimelineFixerSettings())
-	bok, ffmpegInfo, audioVADInfos, infoBase, err := s.IsVideoCanExportSubtitleAndAudio(videoFPath)
-	if err != nil {
-		log.Errorln("IsVideoCanExportSubtitleAndAudio", err)
-		return
-	}
-	if bok == false {
-		log.Errorln("IsVideoCanExportSubtitleAndAudio", "bok == false")
-		return
-	}
+func statistics_subs_score_is_match(
+	s *sub_timeline_fixer.SubTimelineFixerHelperEx,
+	ffmpegInfo *ffmpeg_helper.FFMPEGInfo,
+	audioVADInfos []vad.VADInfo, infoBase *subparser.FileInfo,
+	subSearchRootPath, excelFileName string) {
 
+	var err error
 	f := excelize.NewFile()
 	// Create a new sheet.
 	sheetName := filepath.Base(subSearchRootPath)
@@ -349,7 +345,7 @@ func statistics_subs_score_is_match(videoFPath, subSearchRootPath string) {
 	}
 
 	f.SetActiveSheet(newSheet)
-	err = f.SaveAs(fmt.Sprintf("%s.xlsx", filepath.Base(videoFPath)))
+	err = f.SaveAs(fmt.Sprintf("%s.xlsx", excelFileName))
 	if err != nil {
 		log.Errorln("SaveAs", err)
 		return

+ 22 - 2
TestCode/test_statistics_subs_score_test.go

@@ -1,6 +1,13 @@
 package TestCode
 
-import "testing"
+import (
+	"github.com/allanpk716/ChineseSubFinder/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/pkg/logic/sub_timeline_fixer"
+	"github.com/allanpk716/ChineseSubFinder/pkg/settings"
+	"github.com/prometheus/common/log"
+	"path/filepath"
+	"testing"
+)
 
 func Test_statistics_subs_score(t *testing.T) {
 	type args struct {
@@ -81,7 +88,20 @@ func Test_statistics_subs_score_is_match(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			statistics_subs_score_is_match(tt.args.videoFPath, tt.args.subSearchRootPath)
+
+			logger := log_helper.GetLogger4Tester()
+			s := sub_timeline_fixer.NewSubTimelineFixerHelperEx(logger, *settings.NewTimelineFixerSettings())
+			bok, ffmpegInfo, audioVADInfos, infoBase, err := s.IsVideoCanExportSubtitleAndAudio(tt.args.videoFPath)
+			if err != nil {
+				log.Errorln("IsVideoCanExportSubtitleAndAudio", err)
+				return
+			}
+			if bok == false {
+				log.Errorln("IsVideoCanExportSubtitleAndAudio", "bok == false")
+				return
+			}
+
+			statistics_subs_score_is_match(s, ffmpegInfo, audioVADInfos, infoBase, tt.args.subSearchRootPath, filepath.Base(tt.args.videoFPath))
 		})
 	}
 }