Skip to content

Commit d2f6f68

Browse files
committed
Share commont constance in test suites
1 parent 8fc9a1d commit d2f6f68

File tree

5 files changed

+23
-26
lines changed

5 files changed

+23
-26
lines changed

bindings/ruby/tests/helper.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require "test/unit"
2+
require "whisper"
3+
4+
class TestBase < Test::Unit::TestCase
5+
MODEL = File.join(__dir__, "..", "..", "..", "models", "ggml-base.en.bin")
6+
AUDIO = File.join(__dir__, "..", "..", "..", "samples", "jfk.wav")
7+
end

bindings/ruby/tests/test_package.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
require 'test/unit'
1+
require_relative "helper"
22
require 'tempfile'
33
require 'tmpdir'
44
require 'shellwords'
55

6-
class TestPackage < Test::Unit::TestCase
6+
class TestPackage < TestBase
77
def test_build
88
Tempfile.create do |file|
99
assert system("gem", "build", "whispercpp.gemspec", "--output", file.to_path.shellescape, exception: true)

bindings/ruby/tests/test_params.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
require 'test/unit'
2-
require 'whisper'
1+
require_relative "helper"
32

4-
class TestParams < Test::Unit::TestCase
3+
class TestParams < TestBase
54
def setup
65
@params = Whisper::Params.new
76
end

bindings/ruby/tests/test_segment.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
require "test/unit"
2-
require "whisper"
3-
4-
class TestSegment < Test::Unit::TestCase
5-
TOPDIR = File.expand_path(File.join(File.dirname(__FILE__), '..'))
1+
require_relative "helper"
62

3+
class TestSegment < TestBase
74
class << self
85
attr_reader :whisper
96

107
def startup
11-
@whisper = Whisper::Context.new(File.join(TOPDIR, '..', '..', 'models', 'ggml-base.en.bin'))
8+
@whisper = Whisper::Context.new(TestBase::MODEL)
129
params = Whisper::Params.new
1310
params.print_timestamps = false
14-
jfk = File.join(TOPDIR, '..', '..', 'samples', 'jfk.wav')
15-
@whisper.transcribe(jfk, params)
11+
@whisper.transcribe(TestBase::AUDIO, params)
1612
end
1713
end
1814

@@ -60,7 +56,7 @@ def test_on_new_segment
6056
end
6157
index += 1
6258
end
63-
whisper.transcribe(File.join(TOPDIR, '..', '..', 'samples', 'jfk.wav'), params)
59+
whisper.transcribe(AUDIO, params)
6460
assert_equal 0, seg.start_time
6561
assert_match /ask not what your country can do for you, ask what you can do for your country/, seg.text
6662
end
@@ -76,7 +72,7 @@ def test_on_new_segment_twice
7672
assert_same seg, segment
7773
return
7874
end
79-
whisper.transcribe(File.join(TOPDIR, '..', '..', 'samples', 'jfk.wav'), params)
75+
whisper.transcribe(AUDIO, params)
8076
end
8177

8278
private

bindings/ruby/tests/test_whisper.rb

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
require 'whisper'
2-
require 'test/unit'
3-
4-
class TestWhisper < Test::Unit::TestCase
5-
TOPDIR = File.expand_path(File.join(File.dirname(__FILE__), '..'))
1+
require_relative "helper"
62

3+
class TestWhisper < TestBase
74
def setup
85
@params = Whisper::Params.new
96
end
107

118
def test_whisper
12-
@whisper = Whisper::Context.new(File.join(TOPDIR, '..', '..', 'models', 'ggml-base.en.bin'))
9+
@whisper = Whisper::Context.new(MODEL)
1310
params = Whisper::Params.new
1411
params.print_timestamps = false
1512

16-
jfk = File.join(TOPDIR, '..', '..', 'samples', 'jfk.wav')
17-
@whisper.transcribe(jfk, params) {|text|
13+
@whisper.transcribe(AUDIO, params) {|text|
1814
assert_match /ask not what your country can do for you, ask what you can do for your country/, text
1915
}
2016
end
@@ -24,11 +20,10 @@ class << self
2420
attr_reader :whisper
2521

2622
def startup
27-
@whisper = Whisper::Context.new(File.join(TOPDIR, '..', '..', 'models', 'ggml-base.en.bin'))
23+
@whisper = Whisper::Context.new(TestBase::MODEL)
2824
params = Whisper::Params.new
2925
params.print_timestamps = false
30-
jfk = File.join(TOPDIR, '..', '..', 'samples', 'jfk.wav')
31-
@whisper.transcribe(jfk, params)
26+
@whisper.transcribe(TestBase::AUDIO, params)
3227
end
3328
end
3429

0 commit comments

Comments
 (0)