Skip to content

Commit 49191ab

Browse files
authored
add tests for tables with fixed and variable rows with empty cells (Azure#20627)
1 parent 262eede commit 49191ab

11 files changed

+3967
-1
lines changed
Binary file not shown.
Binary file not shown.

sdk/formrecognizer/Azure.AI.FormRecognizer/tests/FormRecognizerClient/FormRecognizerClientLiveTests.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,6 +2763,60 @@ public async Task StartRecognizeCustomFormsWithMultiplePageArgument(string page1
27632763
Assert.AreEqual(expected, forms.Count);
27642764
}
27652765

2766+
[RecordedTest]
2767+
public async Task StartRecognizeCustomFormsWithTableVariableRows()
2768+
{
2769+
var client = CreateFormRecognizerClient();
2770+
RecognizeCustomFormsOperation operation;
2771+
2772+
await using var trainedModel = await CreateDisposableTrainedModelAsync(useTrainingLabels: true, ContainerType.TableVariableRows);
2773+
2774+
using var stream = FormRecognizerTestEnvironment.CreateStream(TestFile.FormTableVariableRows);
2775+
using (Recording.DisableRequestBodyRecording())
2776+
{
2777+
operation = await client.StartRecognizeCustomFormsAsync(trainedModel.ModelId, stream);
2778+
}
2779+
2780+
RecognizedFormCollection forms = await operation.WaitForCompletionAsync();
2781+
2782+
RecognizedForm form = forms.Single();
2783+
2784+
ValidateModelWithLabelsForm(
2785+
form,
2786+
trainedModel.ModelId,
2787+
includeFieldElements: false,
2788+
expectedFirstPageNumber: 1,
2789+
expectedLastPageNumber: 1,
2790+
isComposedModel: false);
2791+
}
2792+
2793+
[RecordedTest]
2794+
public async Task StartRecognizeCustomFormsWithTableFixedRows()
2795+
{
2796+
var client = CreateFormRecognizerClient();
2797+
RecognizeCustomFormsOperation operation;
2798+
2799+
await using var trainedModel = await CreateDisposableTrainedModelAsync(useTrainingLabels: true, ContainerType.TableFixedRows);
2800+
2801+
using var stream = FormRecognizerTestEnvironment.CreateStream(TestFile.FormTableFixedRows);
2802+
using (Recording.DisableRequestBodyRecording())
2803+
{
2804+
operation = await client.StartRecognizeCustomFormsAsync(trainedModel.ModelId, stream);
2805+
}
2806+
2807+
RecognizedFormCollection forms = await operation.WaitForCompletionAsync();
2808+
2809+
RecognizedForm form = forms.Single();
2810+
2811+
ValidateModelWithLabelsForm(
2812+
form,
2813+
trainedModel.ModelId,
2814+
includeFieldElements: false,
2815+
expectedFirstPageNumber: 1,
2816+
expectedLastPageNumber: 1,
2817+
isComposedModel: false);
2818+
}
2819+
27662820
#endregion
27672821

27682822
private void ValidateFormPage(FormPage formPage, bool includeFieldElements, int expectedPageNumber)

sdk/formrecognizer/Azure.AI.FormRecognizer/tests/Infrastructure/FormRecognizerLiveTestBase.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ protected async Task<DisposableTrainedModel> CreateDisposableTrainedModelAsync(b
109109
ContainerType.Singleforms => TestEnvironment.BlobContainerSasUrl,
110110
ContainerType.MultipageFiles => TestEnvironment.MultipageBlobContainerSasUrl,
111111
ContainerType.SelectionMarks => TestEnvironment.SelectionMarkBlobContainerSasUrl,
112+
ContainerType.TableVariableRows => TestEnvironment.TableVariableRowsContainerSasUrl,
113+
ContainerType.TableFixedRows => TestEnvironment.TableFixedRowsContainerSasUrl,
112114
_ => TestEnvironment.BlobContainerSasUrl,
113115
};
114116
var trainingFilesUri = new Uri(trainingFiles);
@@ -120,7 +122,9 @@ protected enum ContainerType
120122
{
121123
Singleforms,
122124
MultipageFiles,
123-
SelectionMarks
125+
SelectionMarks,
126+
TableVariableRows,
127+
TableFixedRows
124128
}
125129
}
126130
}

sdk/formrecognizer/Azure.AI.FormRecognizer/tests/Infrastructure/FormRecognizerTestEnvironment.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public FormRecognizerTestEnvironment()
3232
/// <summary>The name of the environment variable for the Blob Container SAS URL to use for storing documents that have selection marks used for live tests.</summary>
3333
internal const string SelectionMarkBlobContainerSasUrlEnvironmentVariableName = "FORM_RECOGNIZER_SELECTION_MARK_BLOB_CONTAINER_SAS_URL";
3434

35+
/// <summary>The name of the environment variable for the Blob Container SAS URL to use for storing documents that have tables with variable rows used for live tests.</summary>
36+
internal const string TableVariableRowsBlobContainerSasUrlEnvironmentVariableName = "FORM_RECOGNIZER_TABLE_VARIABLE_ROWS_BLOB_CONTAINER_SAS_URL";
37+
38+
/// <summary>The name of the environment variable for the Blob Container SAS URL to use for storing documents that have tables with fixed rows used for live tests.</summary>
39+
internal const string TableFixedRowsBlobContainerSasUrlEnvironmentVariableName = "FORM_RECOGNIZER_TABLE_FIXED_ROWS_BLOB_CONTAINER_SAS_URL";
40+
3541
/// <summary>The name of the environment variable for the target resource identifier to use for copying custom models live tests.</summary>
3642
internal const string TargetResourceIdEnvironmentVariableName = "FORM_RECOGNIZER_TARGET_RESOURCE_ID";
3743

@@ -49,6 +55,8 @@ public FormRecognizerTestEnvironment()
4955
public string BlobContainerSasUrl => GetRecordedVariable(BlobContainerSasUrlEnvironmentVariableName, options => options.IsSecret("https://sanitized.blob.core.windows.net"));
5056
public string SelectionMarkBlobContainerSasUrl => GetRecordedVariable(SelectionMarkBlobContainerSasUrlEnvironmentVariableName, options => options.IsSecret("https://sanitized.blob.core.windows.net"));
5157
public string MultipageBlobContainerSasUrl => GetRecordedVariable(MultipageBlobContainerSasUrlEnvironmentVariableName, options => options.IsSecret("https://sanitized.blob.core.windows.net"));
58+
public string TableVariableRowsContainerSasUrl => GetRecordedVariable(TableVariableRowsBlobContainerSasUrlEnvironmentVariableName, options => options.IsSecret("https://sanitized.blob.core.windows.net"));
59+
public string TableFixedRowsContainerSasUrl => GetRecordedVariable(TableFixedRowsBlobContainerSasUrlEnvironmentVariableName, options => options.IsSecret("https://sanitized.blob.core.windows.net"));
5260
public string TargetResourceId => GetRecordedVariable(TargetResourceIdEnvironmentVariableName);
5361
public string TargetResourceRegion => GetRecordedVariable(TargetResourceRegionEnvironmentVariableName);
5462

sdk/formrecognizer/Azure.AI.FormRecognizer/tests/Infrastructure/TestFile.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,11 @@ public static class TestFile
5454

5555
/// <summary>A three-page invoice file in which the second page is blank.</summary>
5656
public const string InvoiceMultipageBlank = "multipage_invoice1.pdf";
57+
58+
/// <summary>A form with a table that has variable rows and empty cells.</summary>
59+
public const string FormTableVariableRows = "label_table_variable_rows1.pdf";
60+
61+
/// <summary>A form with a table that has fixed rows and empty cells.</summary>
62+
public const string FormTableFixedRows = "label_table_fixed_rows1.pdf";
5763
}
5864
}

0 commit comments

Comments
 (0)