bindings.ruby : fix warnings in tests

This commit fixes the following warnings in the Ruby tests:
```console
/whisper/bindings/ruby/tests/test_segment.rb:52:
warning: ambiguity between regexp and two divisions:
wrap regexp in parentheses or add a space after `/' operator
```
And also adds a '_' prefix to some unused variables to avoid warnings.
This commit is contained in:
Daniel Bevenius 2025-03-27 06:36:14 +01:00
parent 41c6e25bca
commit fa28968800
5 changed files with 27 additions and 27 deletions

View File

@ -25,7 +25,7 @@ class TestCallback < TestBase
assert start_time >= 0 assert start_time >= 0
assert_kind_of Integer, end_time assert_kind_of Integer, end_time
assert end_time > 0 assert end_time > 0
assert_match /ask not what your country can do for you, ask what you can do for your country/, text if i_segment == 0 assert_match(/ask not what your country can do for you, ask what you can do for your country/, text) if i_segment == 0
end end
} }
@ -145,9 +145,9 @@ class TestCallback < TestBase
def test_abort_on def test_abort_on
do_abort = false do_abort = false
aborted_from_callback = false _aborted_from_callback = false
@params.on_new_segment do |segment| @params.on_new_segment do |segment|
do_abort = true if segment.text.match? /ask/ do_abort = true if segment.text.match?(/ask/)
end end
i = 0 i = 0
@params.abort_on do @params.abort_on do

View File

@ -4,7 +4,7 @@ class TestError < TestBase
def test_error def test_error
error = Whisper::Error.new(-2) error = Whisper::Error.new(-2)
assert_equal "failed to compute log mel spectrogram", error.message assert_equal "failed to compute log mel spectrogram", error.message
assert_equal -2, error.code assert_equal(-2, error.code)
end end
def test_unknown_error def test_unknown_error
@ -14,7 +14,7 @@ class TestError < TestBase
def test_non_int_code def test_non_int_code
assert_raise TypeError do assert_raise TypeError do
error = Whisper::Error.new("non int") _error = Whisper::Error.new("non int")
end end
end end
end end

View File

@ -162,7 +162,7 @@ class TestParams < TestBase
end end
def test_length_penalty def test_length_penalty
assert_equal -1.0, @params.length_penalty assert_equal(-1.0, @params.length_penalty)
@params.length_penalty = 0.5 @params.length_penalty = 0.5
assert_equal 0.5, @params.length_penalty assert_equal 0.5, @params.length_penalty
end end
@ -180,9 +180,9 @@ class TestParams < TestBase
end end
def test_logprob_thold def test_logprob_thold
assert_in_delta -1.0, @params.logprob_thold assert_in_delta(-1.0, @params.logprob_thold)
@params.logprob_thold = -0.5 @params.logprob_thold = -0.5
assert_in_delta -0.5, @params.logprob_thold assert_in_delta(-0.5, @params.logprob_thold)
end end
def test_no_speech_thold def test_no_speech_thold

View File

@ -49,13 +49,13 @@ class TestSegment < TestBase
if index == 0 if index == 0
seg = segment seg = segment
assert_equal 0, segment.start_time assert_equal 0, segment.start_time
assert_match /ask not what your country can do for you, ask what you can do for your country/, segment.text assert_match(/ask not what your country can do for you, ask what you can do for your country/, segment.text)
end end
index += 1 index += 1
end end
whisper.transcribe(AUDIO, params) whisper.transcribe(AUDIO, params)
assert_equal 0, seg.start_time assert_equal 0, seg.start_time
assert_match /ask not what your country can do for you, ask what you can do for your country/, seg.text assert_match(/ask not what your country can do for you, ask what you can do for your country/, seg.text)
end end
def test_on_new_segment_twice def test_on_new_segment_twice

View File

@ -18,7 +18,7 @@ class TestWhisper < TestBase
params.print_timestamps = false params.print_timestamps = false
@whisper.transcribe(AUDIO, params) {|text| @whisper.transcribe(AUDIO, params) {|text|
assert_match /ask not what your country can do for you, ask what you can do for your country/, text assert_match(/ask not what your country can do for you, ask what you can do for your country/, text)
} }
end end
@ -34,7 +34,7 @@ class TestWhisper < TestBase
def test_full_get_segment def test_full_get_segment
segment = whisper.full_get_segment(0) segment = whisper.full_get_segment(0)
assert_equal 0, segment.start_time assert_equal 0, segment.start_time
assert_match /ask not what your country can do for you, ask what you can do for your country/, segment.text assert_match(/ask not what your country can do for you, ask what you can do for your country/, segment.text)
end end
def test_full_get_segment_t0 def test_full_get_segment_t0
@ -61,7 +61,7 @@ class TestWhisper < TestBase
end end
def test_full_get_segment_text def test_full_get_segment_text
assert_match /ask not what your country can do for you, ask what you can do for your country/, whisper.full_get_segment_text(0) assert_match(/ask not what your country can do for you, ask what you can do for your country/, whisper.full_get_segment_text(0))
end end
def test_full_get_segment_no_speech_prob def test_full_get_segment_no_speech_prob
@ -136,14 +136,14 @@ class TestWhisper < TestBase
@whisper.full(@params, @samples, @samples.length) @whisper.full(@params, @samples, @samples.length)
assert_equal 1, @whisper.full_n_segments assert_equal 1, @whisper.full_n_segments
assert_match /ask not what your country can do for you, ask what you can do for your country/, @whisper.each_segment.first.text assert_match(/ask not what your country can do for you, ask what you can do for your country/, @whisper.each_segment.first.text)
end end
def test_full_without_length def test_full_without_length
@whisper.full(@params, @samples) @whisper.full(@params, @samples)
assert_equal 1, @whisper.full_n_segments assert_equal 1, @whisper.full_n_segments
assert_match /ask not what your country can do for you, ask what you can do for your country/, @whisper.each_segment.first.text assert_match(/ask not what your country can do for you, ask what you can do for your country/, @whisper.each_segment.first.text)
end end
def test_full_enumerator def test_full_enumerator
@ -151,7 +151,7 @@ class TestWhisper < TestBase
@whisper.full(@params, samples, @samples.length) @whisper.full(@params, samples, @samples.length)
assert_equal 1, @whisper.full_n_segments assert_equal 1, @whisper.full_n_segments
assert_match /ask not what your country can do for you, ask what you can do for your country/, @whisper.each_segment.first.text assert_match(/ask not what your country can do for you, ask what you can do for your country/, @whisper.each_segment.first.text)
end end
def test_full_enumerator_without_length def test_full_enumerator_without_length
@ -173,7 +173,7 @@ class TestWhisper < TestBase
@whisper.full(@params, samples) @whisper.full(@params, samples)
assert_equal 1, @whisper.full_n_segments assert_equal 1, @whisper.full_n_segments
assert_match /ask not what your country can do for you, ask what you can do for your country/, @whisper.each_segment.first.text assert_match(/ask not what your country can do for you, ask what you can do for your country/, @whisper.each_segment.first.text)
end end
def test_full_parallel def test_full_parallel
@ -182,8 +182,8 @@ class TestWhisper < TestBase
assert_equal nprocessors, @whisper.full_n_segments assert_equal nprocessors, @whisper.full_n_segments
text = @whisper.each_segment.collect(&:text).join text = @whisper.each_segment.collect(&:text).join
assert_match /ask what you can do/i, text assert_match(/ask what you can do/i, text)
assert_match /for your country/i, text assert_match(/for your country/i, text)
end end
def test_full_parallel_with_memory_view def test_full_parallel_with_memory_view
@ -193,8 +193,8 @@ class TestWhisper < TestBase
assert_equal nprocessors, @whisper.full_n_segments assert_equal nprocessors, @whisper.full_n_segments
text = @whisper.each_segment.collect(&:text).join text = @whisper.each_segment.collect(&:text).join
assert_match /ask what you can do/i, text assert_match(/ask what you can do/i, text)
assert_match /for your country/i, text assert_match(/for your country/i, text)
end end
def test_full_parallel_without_length_and_n_processors def test_full_parallel_without_length_and_n_processors
@ -202,8 +202,8 @@ class TestWhisper < TestBase
assert_equal 1, @whisper.full_n_segments assert_equal 1, @whisper.full_n_segments
text = @whisper.each_segment.collect(&:text).join text = @whisper.each_segment.collect(&:text).join
assert_match /ask what you can do/i, text assert_match(/ask what you can do/i, text)
assert_match /for your country/i, text assert_match(/for your country/i, text)
end end
def test_full_parallel_without_length def test_full_parallel_without_length
@ -212,8 +212,8 @@ class TestWhisper < TestBase
assert_equal nprocessors, @whisper.full_n_segments assert_equal nprocessors, @whisper.full_n_segments
text = @whisper.each_segment.collect(&:text).join text = @whisper.each_segment.collect(&:text).join
assert_match /ask what you can do/i, text assert_match(/ask what you can do/i, text)
assert_match /for your country/i, text assert_match(/for your country/i, text)
end end
def test_full_parallel_without_n_processors def test_full_parallel_without_n_processors
@ -221,8 +221,8 @@ class TestWhisper < TestBase
assert_equal 1, @whisper.full_n_segments assert_equal 1, @whisper.full_n_segments
text = @whisper.each_segment.collect(&:text).join text = @whisper.each_segment.collect(&:text).join
assert_match /ask what you can do/i, text assert_match(/ask what you can do/i, text)
assert_match /for your country/i, text assert_match(/for your country/i, text)
end end
end end
end end