Skip to content

bindings.ruby : fix test failures in test_whisper #2955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bindings/ruby/tests/test_callback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_new_segment_callback
assert start_time >= 0
assert_kind_of Integer, end_time
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
}

Expand Down Expand Up @@ -145,9 +145,9 @@ def test_abort_callback_user_data

def test_abort_on
do_abort = false
aborted_from_callback = false
_aborted_from_callback = false
@params.on_new_segment do |segment|
do_abort = true if segment.text.match? /ask/
do_abort = true if segment.text.match?(/ask/)
end
i = 0
@params.abort_on do
Expand Down
4 changes: 2 additions & 2 deletions bindings/ruby/tests/test_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class TestError < TestBase
def test_error
error = Whisper::Error.new(-2)
assert_equal "failed to compute log mel spectrogram", error.message
assert_equal -2, error.code
assert_equal(-2, error.code)
end

def test_unknown_error
Expand All @@ -14,7 +14,7 @@ def test_unknown_error

def test_non_int_code
assert_raise TypeError do
error = Whisper::Error.new("non int")
_error = Whisper::Error.new("non int")
end
end
end
6 changes: 3 additions & 3 deletions bindings/ruby/tests/test_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def test_max_initial_ts
end

def test_length_penalty
assert_equal -1.0, @params.length_penalty
assert_equal(-1.0, @params.length_penalty)
@params.length_penalty = 0.5
assert_equal 0.5, @params.length_penalty
end
Expand All @@ -180,9 +180,9 @@ def test_entropy_thold
end

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
assert_in_delta -0.5, @params.logprob_thold
assert_in_delta(-0.5, @params.logprob_thold)
end

def test_no_speech_thold
Expand Down
4 changes: 2 additions & 2 deletions bindings/ruby/tests/test_segment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def test_on_new_segment
if index == 0
seg = segment
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
index += 1
end
whisper.transcribe(AUDIO, params)
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

def test_on_new_segment_twice
Expand Down
49 changes: 26 additions & 23 deletions bindings/ruby/tests/test_whisper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_whisper
params.print_timestamps = false

@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

Expand All @@ -32,7 +32,7 @@ def test_full_lang_id
def test_full_get_segment
segment = whisper.full_get_segment(0)
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

def test_full_get_segment_t0
Expand All @@ -59,7 +59,7 @@ def test_full_get_segment_speaker_turn_next
end

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

def test_full_get_segment_no_speech_prob
Expand Down Expand Up @@ -134,22 +134,22 @@ def test_full
@whisper.full(@params, @samples, @samples.length)

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

def test_full_without_length
@whisper.full(@params, @samples)

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

def test_full_enumerator
samples = @samples.each
@whisper.full(@params, samples, @samples.length)

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

def test_full_enumerator_without_length
Expand All @@ -171,53 +171,56 @@ def test_full_with_memory_view
@whisper.full(@params, samples)

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

def test_full_parallel
@whisper.full_parallel(@params, @samples, @samples.length, Etc.nprocessors)
nprocessors = 2
@whisper.full_parallel(@params, @samples, @samples.length, nprocessors)

assert_equal Etc.nprocessors, @whisper.full_n_segments
assert_equal nprocessors, @whisper.full_n_segments
text = @whisper.each_segment.collect(&:text).join
assert_match /ask what you can do/i, text
assert_match /for your country/i, text
assert_match(/ask what you can do/i, text)
assert_match(/for your country/i, text)
end

def test_full_parallel_with_memory_view
nprocessors = 2
samples = JFKReader.new(AUDIO)
@whisper.full_parallel(@params, samples, nil, Etc.nprocessors)
@whisper.full_parallel(@params, samples, nil, nprocessors)

assert_equal Etc.nprocessors, @whisper.full_n_segments
assert_equal nprocessors, @whisper.full_n_segments
text = @whisper.each_segment.collect(&:text).join
assert_match /ask what you can do/i, text
assert_match /for your country/i, text
assert_match(/ask what you can do/i, text)
assert_match(/for your country/i, text)
end

def test_full_parallel_without_length_and_n_processors
@whisper.full_parallel(@params, @samples)

assert_equal 1, @whisper.full_n_segments
text = @whisper.each_segment.collect(&:text).join
assert_match /ask what you can do/i, text
assert_match /for your country/i, text
assert_match(/ask what you can do/i, text)
assert_match(/for your country/i, text)
end

def test_full_parallel_without_length
@whisper.full_parallel(@params, @samples, nil, Etc.nprocessors)
nprocessors = 2
@whisper.full_parallel(@params, @samples, nil, nprocessors)

assert_equal Etc.nprocessors, @whisper.full_n_segments
assert_equal nprocessors, @whisper.full_n_segments
text = @whisper.each_segment.collect(&:text).join
assert_match /ask what you can do/i, text
assert_match /for your country/i, text
assert_match(/ask what you can do/i, text)
assert_match(/for your country/i, text)
end

def test_full_parallel_without_n_processors
@whisper.full_parallel(@params, @samples, @samples.length)

assert_equal 1, @whisper.full_n_segments
text = @whisper.each_segment.collect(&:text).join
assert_match /ask what you can do/i, text
assert_match /for your country/i, text
assert_match(/ask what you can do/i, text)
assert_match(/for your country/i, text)
end
end
end
Loading