From 0fe6b454fabad59c8d49918a5cc945c152b48c16 Mon Sep 17 00:00:00 2001 From: John Lambert Date: Fri, 11 Oct 2024 15:11:22 -0400 Subject: [PATCH] Add integration test --- .../TranslationEngineTests.cs | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs b/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs index 6d0b2df2..cdf1bcf3 100644 --- a/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs +++ b/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs @@ -1660,6 +1660,105 @@ public async Task StartBuildAsync_ParallelCorpus() Assert.That(build, Is.Not.Null); } + [Test] + public async Task StartBuildAsync_Corpus_NoFilter() + { + TranslationEnginesClient client = _env.CreateTranslationEnginesClient(); + TranslationCorpus addedCorpus = await client.AddCorpusAsync(NMT_ENGINE1_ID, TestCorpusConfig); + PretranslateCorpusConfig ptcc = + new() { CorpusId = addedCorpus.Id, SourceFilters = [new() { CorpusId = SOURCE_CORPUS_ID }] }; + TrainingCorpusConfig tcc = + new() + { + CorpusId = addedCorpus.Id, + SourceFilters = [new() { CorpusId = SOURCE_CORPUS_ID }], + TargetFilters = [new() { CorpusId = TARGET_CORPUS_ID }] + }; + ; + TranslationBuildConfig tbc = new TranslationBuildConfig + { + Pretranslate = [ptcc], + TrainOn = [tcc], + Options = """ + {"max_steps":10, + "use_key_terms":false, + "some_double":10.5, + "some_nested": {"more_nested": {"other_double":10.5}}, + "some_string":"string"} + """ + }; + TranslationBuild resultAfterStart; + Assert.ThrowsAsync(async () => + { + resultAfterStart = await client.GetCurrentBuildAsync(NMT_ENGINE1_ID); + }); + + TranslationBuild build = await client.StartBuildAsync(NMT_ENGINE1_ID, tbc); + Assert.That(build, Is.Not.Null); + Assert.That(build.TrainOn, Is.Not.Null); + Assert.That(build.TrainOn.Count, Is.EqualTo(1)); + Assert.That(build.TrainOn[0].TextIds, Is.Null); + Assert.That(build.TrainOn[0].ScriptureRange, Is.Null); + Assert.That(build.Pretranslate, Is.Not.Null); + Assert.That(build.Pretranslate.Count, Is.EqualTo(1)); + Assert.That(build.Pretranslate[0].TextIds, Is.Null); + Assert.That(build.Pretranslate[0].ScriptureRange, Is.Null); + + build = await client.GetCurrentBuildAsync(NMT_ENGINE1_ID); + Assert.That(build, Is.Not.Null); + } + + [Test] + public async Task StartBuildAsync_ParallelCorpus_NoFilter() + { + TranslationEnginesClient client = _env.CreateTranslationEnginesClient(); + TranslationParallelCorpus addedCorpus = await client.AddParallelCorpusAsync( + NMT_ENGINE1_ID, + TestParallelCorpusConfig + ); + PretranslateCorpusConfig ptcc = + new() { ParallelCorpusId = addedCorpus.Id, SourceFilters = [new() { CorpusId = SOURCE_CORPUS_ID }] }; + TrainingCorpusConfig tcc = + new() + { + ParallelCorpusId = addedCorpus.Id, + SourceFilters = [new() { CorpusId = SOURCE_CORPUS_ID }], + TargetFilters = [new() { CorpusId = TARGET_CORPUS_ID }] + }; + ; + TranslationBuildConfig tbc = new TranslationBuildConfig + { + Pretranslate = [ptcc], + TrainOn = [tcc], + Options = """ + {"max_steps":10, + "use_key_terms":false, + "some_double":10.5, + "some_nested": {"more_nested": {"other_double":10.5}}, + "some_string":"string"} + """ + }; + TranslationBuild resultAfterStart; + Assert.ThrowsAsync(async () => + { + resultAfterStart = await client.GetCurrentBuildAsync(NMT_ENGINE1_ID); + }); + + TranslationBuild build = await client.StartBuildAsync(NMT_ENGINE1_ID, tbc); + Assert.That(build, Is.Not.Null); + Assert.That(build.TrainOn, Is.Not.Null); + Assert.That(build.TrainOn.Count, Is.EqualTo(1)); + Assert.That(build.TrainOn[0].TextIds, Is.Null); + Assert.That(build.TrainOn[0].ScriptureRange, Is.Null); + Assert.That(build.Pretranslate, Is.Not.Null); + Assert.That(build.Pretranslate.Count, Is.EqualTo(1)); + Assert.That(build.Pretranslate[0].TextIds, Is.Null); + Assert.That(build.Pretranslate[0].ScriptureRange, Is.Null); + + build = await client.GetCurrentBuildAsync(NMT_ENGINE1_ID); + Assert.That(build, Is.Not.Null); + } + [Test] public async Task StartBuildAsync_ParallelCorpus_PretranslateParallelAndNormalCorpus() {