Skip to content

Commit 574d29c

Browse files
committed
test(speech to text): Add & adjust tests for speech to test to increase coverage
1 parent 8933632 commit 574d29c

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

test/integration/test_speech_to_text_v1.rb

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def initialize(atomic_boolean: nil)
1313
@atomic_boolean = atomic_boolean
1414
end
1515

16-
def on_error(error:)
17-
puts "Error received: #{error}"
16+
def on_error(*)
17+
@atomic_boolean.make_true
1818
end
1919

2020
def on_inactivity_timeout(*)
@@ -86,6 +86,7 @@ def test_recognitions
8686
end
8787

8888
def test_custom_corpora
89+
skip "Skip to allow for concurrent travis jobs"
8990
model = @service.create_language_model(
9091
name: "integration_test_model",
9192
base_model_name: "en-US_BroadbandModel"
@@ -106,6 +107,7 @@ def test_acoustic_model
106107
list_models = @service.list_acoustic_models.result
107108
refute_nil(list_models)
108109

110+
skip "Skip to allow for concurrent travis jobs"
109111
create_acoustic_model = @service.create_acoustic_model(
110112
name: "integration_test_model_ruby",
111113
base_model_name: "en-US_BroadbandModel"
@@ -184,5 +186,51 @@ def test_inactivity_timeout_with_websocket
184186
thr.join
185187
assert(atomic_boolean.true?)
186188
end
189+
190+
def test_broken_audio_with_websocket
191+
audio_file = File.open(Dir.getwd + "/resources/car.jpg")
192+
atomic_boolean = Concurrent::AtomicBoolean.new
193+
mycallback = MyRecognizeCallback.new(atomic_boolean: atomic_boolean)
194+
speech = @service.recognize_with_websocket(
195+
audio: audio_file,
196+
recognize_callback: mycallback,
197+
interim_results: true,
198+
timestamps: true,
199+
max_alternatives: 2,
200+
word_alternatives_threshold: 0.5,
201+
model: "en-US_BroadbandModel"
202+
)
203+
thr = Thread.new { speech.start }
204+
thr.join
205+
assert(atomic_boolean.true?)
206+
end
207+
208+
def test_invalid_auth_with_websocket
209+
audio_file = File.open(Dir.getwd + "/resources/speech.wav")
210+
atomic_boolean = Concurrent::AtomicBoolean.new
211+
mycallback = MyRecognizeCallback.new(atomic_boolean: atomic_boolean)
212+
temp_service = IBMWatson::SpeechToTextV1.new(
213+
username: "username",
214+
password: "password"
215+
)
216+
temp_service.add_default_headers(
217+
headers: {
218+
"X-Watson-Learning-Opt-Out" => "1",
219+
"X-Watson-Test" => "1"
220+
}
221+
)
222+
speech = temp_service.recognize_with_websocket(
223+
audio: audio_file,
224+
recognize_callback: mycallback,
225+
interim_results: true,
226+
timestamps: true,
227+
max_alternatives: 2,
228+
word_alternatives_threshold: 0.5,
229+
model: "en-US_BroadbandModel"
230+
)
231+
thr = Thread.new { speech.start }
232+
thr.join
233+
assert(atomic_boolean.true?)
234+
end
187235
end
188236
end

test/unit/test_speech_to_text_v1.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,4 +752,21 @@ def test_upgrade_acoustic_model
752752
service_response = service.upgrade_acoustic_model(customization_id: "customization_id")
753753
assert_nil(service_response)
754754
end
755+
756+
def test_reset_acoustic_model
757+
service = IBMWatson::SpeechToTextV1.new(
758+
username: "username",
759+
password: "password"
760+
)
761+
stub_request(:post, "https://stream.watsonplatform.net/speech-to-text/api/v1/acoustic_customizations/customization_id/reset")
762+
.with(
763+
headers: {
764+
"Accept" => "application/json",
765+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
766+
"Host" => "stream.watsonplatform.net"
767+
}
768+
).to_return(status: 200, body: "", headers: {})
769+
service_response = service.reset_acoustic_model(customization_id: "customization_id")
770+
assert_nil(service_response)
771+
end
755772
end

0 commit comments

Comments
 (0)