Skip to content

Commit

Permalink
[FormRecognizer] Cleaning up tests (1/?) (#37705)
Browse files Browse the repository at this point in the history
  • Loading branch information
kinelski authored Jul 21, 2023
1 parent b9a4d4b commit 5f94685
Show file tree
Hide file tree
Showing 19 changed files with 1,087 additions and 902 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -443,54 +443,6 @@ public async Task AnalyzeDocumentWithCustomModelCanParseDifferentTypeOfForm()
field.FieldType == DocumentFieldType.Unknown && field.ExpectedFieldType == DocumentFieldType.String));
}

[RecordedTest]
public async Task AnalyzeDocumentWithCustomModelWithTableDynamicRows()
{
var client = CreateDocumentAnalysisClient();
var modelId = Recording.GenerateId();
AnalyzeDocumentOperation operation;

await using var customModel = await BuildDisposableDocumentModelAsync(modelId, ContainerType.TableVariableRows);

using var stream = DocumentAnalysisTestEnvironment.CreateStream(TestFile.FormTableDynamicRows);
using (Recording.DisableRequestBodyRecording())
{
operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, customModel.ModelId, stream);
}

AnalyzeResult result = operation.Value;

ValidateAnalyzeResult(
result,
customModel.ModelId,
expectedFirstPageNumber: 1,
expectedLastPageNumber: 1);
}

[RecordedTest]
public async Task AnalyzeDocumentWithCustomModelWithTableFixedRows()
{
var client = CreateDocumentAnalysisClient();
var modelId = Recording.GenerateId();
AnalyzeDocumentOperation operation;

await using var customModel = await BuildDisposableDocumentModelAsync(modelId, ContainerType.TableFixedRows);

using var stream = DocumentAnalysisTestEnvironment.CreateStream(TestFile.FormTableFixedRows);
using (Recording.DisableRequestBodyRecording())
{
operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, customModel.ModelId, stream);
}

AnalyzeResult result = operation.Value;

ValidateAnalyzeResult(
result,
customModel.ModelId,
expectedFirstPageNumber: 1,
expectedLastPageNumber: 1);
}

[RecordedTest]
[Ignore("Service error. Issue https://github.com/Azure/azure-sdk-for-net/issues/24995")]
public async Task AnalyzeDocumentWithCustomModelCanParseBlankPage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using Azure.Core.TestFramework;
using NUnit.Framework;

using TestFile = Azure.AI.FormRecognizer.Tests.TestFile;

namespace Azure.AI.FormRecognizer.DocumentAnalysis.Tests
{
/// <summary>
Expand All @@ -30,39 +28,6 @@ public OperationsLiveTests(bool isAsync, DocumentAnalysisClientOptions.ServiceVe
{
}

[RecordedTest]
public async Task AnalyzeDocumentOperationCanPollFromNewObject()
{
var client = CreateDocumentAnalysisClient(out var nonInstrumentedClient);

var uri = DocumentAnalysisTestEnvironment.CreateUri(TestFile.ReceiptJpg);
var operation = await client.AnalyzeDocumentFromUriAsync(WaitUntil.Started, "prebuilt-receipt", uri);
Assert.IsNotNull(operation.GetRawResponse());

var sameOperation = InstrumentOperation(new AnalyzeDocumentOperation(operation.Id, nonInstrumentedClient));
await sameOperation.WaitForCompletionAsync();

Assert.IsTrue(sameOperation.HasValue);
Assert.AreEqual(1, sameOperation.Value.Pages.Count);
}

[RecordedTest]
public async Task BuildModelOperationCanPollFromNewObject()
{
var client = CreateDocumentModelAdministrationClient(out var nonInstrumentedClient);
var trainingFilesUri = new Uri(TestEnvironment.BlobContainerSasUrl);
var modelId = Recording.GenerateId();

var operation = await client.BuildDocumentModelAsync(WaitUntil.Started, trainingFilesUri, DocumentBuildMode.Template, modelId);
Assert.IsNotNull(operation.GetRawResponse());

var sameOperation = InstrumentOperation(new BuildDocumentModelOperation(operation.Id, nonInstrumentedClient));
await sameOperation.WaitForCompletionAsync();

Assert.IsTrue(sameOperation.HasValue);
Assert.AreEqual(modelId, sameOperation.Value.ModelId);
}

[RecordedTest]
public async Task BuildModelOperationPercentageCompletedValue()
{
Expand All @@ -79,27 +44,6 @@ public async Task BuildModelOperationPercentageCompletedValue()
Assert.AreEqual(100, operation.PercentCompleted);
}

[RecordedTest]
public async Task CopyModelToOperationCanPollFromNewObject()
{
var client = CreateDocumentModelAdministrationClient(out var nonInstrumentedClient);
var modelId = Recording.GenerateId();

await using var trainedModel = await BuildDisposableDocumentModelAsync(modelId);

var targetModelId = Recording.GenerateId();
DocumentModelCopyAuthorization targetAuth = await client.GetCopyAuthorizationAsync(targetModelId);

var operation = await client.CopyDocumentModelToAsync(WaitUntil.Started, trainedModel.ModelId, targetAuth);
Assert.IsNotNull(operation.GetRawResponse());

var sameOperation = InstrumentOperation(new CopyDocumentModelToOperation(operation.Id, nonInstrumentedClient));
await sameOperation.WaitForCompletionAsync();

Assert.IsTrue(sameOperation.HasValue);
Assert.AreEqual(targetModelId, sameOperation.Value.ModelId);
}

[RecordedTest]
public async Task CopyModelToOperationPercentageCompletedValue()
{
Expand All @@ -120,62 +64,6 @@ public async Task CopyModelToOperationPercentageCompletedValue()
Assert.AreEqual(100, operation.PercentCompleted);
}

[RecordedTest]
[ServiceVersion(Min = DocumentAnalysisClientOptions.ServiceVersion.V2023_02_28_Preview)]
public async Task ClassifyDocumentOperationCanPollFromNewObject()
{
var client = CreateDocumentAnalysisClient(out var nonInstrumentedClient);
var classifierId = Recording.GenerateId();
await using var disposableClassifier = await BuildDisposableDocumentClassifierAsync(classifierId);
var uri = DocumentAnalysisTestEnvironment.CreateUri(TestFile.Irs1040);

var operation = await client.ClassifyDocumentFromUriAsync(WaitUntil.Started, classifierId, uri);
var sameOperation = InstrumentOperation(new ClassifyDocumentOperation(operation.Id, nonInstrumentedClient));

await sameOperation.WaitForCompletionAsync();

Assert.IsTrue(sameOperation.HasValue);
Assert.AreEqual(4, sameOperation.Value.Pages.Count);
}

[RecordedTest]
[ServiceVersion(Min = DocumentAnalysisClientOptions.ServiceVersion.V2023_02_28_Preview)]
public async Task BuildClassifierOperationCanPollFromNewObject()
{
var client = CreateDocumentModelAdministrationClient(out var nonInstrumentedClient);
var classifierId = Recording.GenerateId();

var trainingFilesUri = new Uri(TestEnvironment.ClassifierTrainingSasUrl);
var sourceA = new AzureBlobContentSource(trainingFilesUri) { Prefix = "IRS-1040-A/train" };
var sourceB = new AzureBlobContentSource(trainingFilesUri) { Prefix = "IRS-1040-B/train" };

var documentTypes = new Dictionary<string, ClassifierDocumentTypeDetails>()
{
{ "IRS-1040-A", new ClassifierDocumentTypeDetails(sourceA) },
{ "IRS-1040-B", new ClassifierDocumentTypeDetails(sourceB) }
};

BuildDocumentClassifierOperation sameOperation = null;

try
{
var operation = await client.BuildDocumentClassifierAsync(WaitUntil.Started, documentTypes, classifierId);

sameOperation = InstrumentOperation(new BuildDocumentClassifierOperation(operation.Id, nonInstrumentedClient));
await sameOperation.WaitForCompletionAsync();
}
finally
{
if (sameOperation != null && sameOperation.HasValue)
{
await client.DeleteDocumentClassifierAsync(classifierId);
}
}

Assert.IsTrue(sameOperation.HasValue);
Assert.AreEqual(classifierId, sameOperation.Value.ClassifierId);
}

[RecordedTest]
[ServiceVersion(Min = DocumentAnalysisClientOptions.ServiceVersion.V2023_02_28_Preview)]
public async Task BuildClassifierOperationPercentageCompletedValue()
Expand Down
Loading

0 comments on commit 5f94685

Please sign in to comment.