Skip to content

Commit

Permalink
[FormRecognizer] Updated tests after recent service deployment (#37618)
Browse files Browse the repository at this point in the history
  • Loading branch information
kinelski authored Jul 17, 2023
1 parent aa9b7e6 commit e54ec3a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,14 @@ public async Task AnalyzeDocumentPopulatesDocumentPageJpg(bool useStream)

Assert.True(style.IsHandwritten);

Assert.AreEqual(38, result.Paragraphs.Count);
if (_serviceVersion >= DocumentAnalysisClientOptions.ServiceVersion.V2023_02_28_Preview)
{
Assert.AreEqual(52, result.Paragraphs.Count);
}
else
{
Assert.AreEqual(38, result.Paragraphs.Count);
}

DocumentParagraph sampleParagraph = result.Paragraphs[1];

Expand Down Expand Up @@ -918,9 +925,9 @@ public async Task AnalyzeDocumentPopulatesExtractedInvoiceJpg(bool useStream)

var expectedItems = new List<(double Amount, DateTimeOffset Date, string Description, string ProductCode, double Quantity, string Unit, double UnitPrice)>()
{
(60f, DateTimeOffset.Parse("2021-04-03 00:00:00+00:00"), "Consulting Services", "A123", 2, "hours", 30),
(30f, DateTimeOffset.Parse("2021-05-03 00:00:00+00:00"), "Document Fee", "B456", 3, null, 10),
(10f, DateTimeOffset.Parse("2021-06-03 00:00:00+00:00"), "Printing Fee", "C789", 10, "pages", 1)
(60f, DateTimeOffset.Parse("2021-03-04 00:00:00+00:00"), "Consulting Services", "A123", 2, "hours", 30),
(30f, DateTimeOffset.Parse("2021-03-05 00:00:00+00:00"), "Document Fee", "B456", 3, null, 10),
(10f, DateTimeOffset.Parse("2021-03-06 00:00:00+00:00"), "Printing Fee", "C789", 10, "pages", 1)
};

// Include a bit of tolerance when comparing double types.
Expand Down Expand Up @@ -1432,7 +1439,7 @@ public async Task AnalyzeDocumentCanParseMultipageReceipt(bool useStream)

if (documentIndex == 0)
{
Assert.AreEqual("$14,50", sampleField.Content);
Assert.AreEqual("$14.50", sampleField.Content);
}
else if (documentIndex == 1)
{
Expand Down Expand Up @@ -1474,7 +1481,7 @@ public async Task AnalyzeDocumentCanParseMultipageReceiptWithBlankPage()

if (pageIndex == 0 || pageIndex == 2)
{
var expectedContent = pageIndex == 0 ? "$14,50" : "1203.39";
var expectedContent = pageIndex == 0 ? "$14.50" : "1203.39";

Assert.True(page.Words.Any(w => w.Content == expectedContent));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ public async Task BuildDocumentModel(DocumentBuildMode buildMode)
if (buildMode == DocumentBuildMode.Neural && Recording.Mode == RecordedTestMode.Live)
{
// Test takes too long to finish running, and seems to cause multiple failures in our
// live test pipeline. Until we find a way to run it without flakiness, this test will
// be ignored when running in Live mode.
Assert.Ignore("https://github.com/Azure/azure-sdk-for-net/issues/27042");
// live test pipeline. For this reason, this test is ignored when running in Live mode.
Assert.Ignore();
}

var client = CreateDocumentModelAdministrationClient();
Expand Down Expand Up @@ -118,14 +117,7 @@ public async Task BuildDocumentModel(DocumentBuildMode buildMode)
}
else
{
// We have changed the following validation because of a service bug. This needs to be updated once the bug is fixed.
// More information: https://github.com/Azure/azure-sdk-for-net/issues/35809

// The expected behavior. This must be added back once the service bug is fixed.
// Assert.IsNull(model.ExpiresOn);

// The current behavior. This assertion must be removed once the service bug is fixed.
Assert.Greater(model.ExpiresOn, model.CreatedOn);
Assert.IsNull(model.ExpiresOn);
}

CollectionAssert.AreEquivalent(options.Tags, model.Tags);
Expand Down Expand Up @@ -272,7 +264,15 @@ public async Task ComposeDocumentModel(bool useTokenCredential)
Assert.AreEqual(description, model.Description);
Assert.AreEqual(ServiceVersionString, model.ApiVersion);
Assert.Greater(model.CreatedOn, startTime);
Assert.Greater(model.ExpiresOn, model.CreatedOn);

if (_serviceVersion >= DocumentAnalysisClientOptions.ServiceVersion.V2023_02_28_Preview)
{
Assert.Greater(model.ExpiresOn, model.CreatedOn);
}
else
{
Assert.IsNull(model.ExpiresOn);
}

CollectionAssert.AreEquivalent(tags, model.Tags);

Expand Down Expand Up @@ -323,13 +323,7 @@ public async Task GetDocumentModel(bool useTokenCredential)
Assert.AreEqual(expected.Description, model.Description);
Assert.AreEqual(expected.ApiVersion, model.ApiVersion);
Assert.AreEqual(expected.CreatedOn, model.CreatedOn);

// (TODO) This assertion should not need a conditional block but we need it because of a service issue.
// Remove the condition once this issue is fixed: https://github.com/Azure/azure-sdk-for-net/issues/35809
if (_serviceVersion > DocumentAnalysisClientOptions.ServiceVersion.V2022_08_31)
{
Assert.AreEqual(expected.ExpiresOn, model.ExpiresOn);
}
Assert.AreEqual(expected.ExpiresOn, model.ExpiresOn);

CollectionAssert.AreEquivalent(expected.Tags, model.Tags);

Expand Down Expand Up @@ -397,13 +391,7 @@ public async Task GetDocumentModels(bool useTokenCredential)
Assert.AreEqual(expected.Description, model.Description);
Assert.AreEqual(expected.ApiVersion, model.ApiVersion);
Assert.AreEqual(expected.CreatedOn, model.CreatedOn);

// (TODO) This assertion should not need a conditional block but we need it because of a service issue.
// Remove the condition once this issue is fixed: https://github.com/Azure/azure-sdk-for-net/issues/35809
if (_serviceVersion > DocumentAnalysisClientOptions.ServiceVersion.V2022_08_31)
{
Assert.AreEqual(expected.ExpiresOn, model.ExpiresOn);
}
Assert.AreEqual(expected.ExpiresOn, model.ExpiresOn);

CollectionAssert.AreEquivalent(expected.Tags, model.Tags);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,7 @@ private void ValidateDocumentModelDetails(DocumentModelDetails model, string des
}
else
{
// We have changed the following validation because of a service bug. This needs to be updated once the bug is fixed.
// More information: https://github.com/Azure/azure-sdk-for-net/issues/35809

/* The expected behavior. This must be added back once the service bug is fixed.
Assert.Null(model.ExpiresOn);
*/

// The current behavior. This 'if' block must be completely removed once the service bug is fixed.
if (model.ExpiresOn.HasValue)
{
Assert.Greater(model.ExpiresOn, model.CreatedOn);
}
}

// TODO add validation for Doctypes https://github.com/Azure/azure-sdk-for-net-pr/issues/1432
Expand Down
2 changes: 1 addition & 1 deletion sdk/formrecognizer/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/formrecognizer",
"Tag": "net/formrecognizer_3c6efa38b9"
"Tag": "net/formrecognizer_2475157f2c"
}

0 comments on commit e54ec3a

Please sign in to comment.