Files
llm-pii-poc/tests/TestSupport.Shared/RealNerModelFixture.cs

47 lines
1.3 KiB
C#
Raw Normal View History

using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using PiiRedaction.Core.Configuration;
using PiiRedaction.Infrastructure.Onnx;
namespace PiiRedaction.Tests.Shared;
/// <summary>
/// Reuses a single <see cref="EnglishOnnxNerRunner"/> per fixture for performance.
/// Skips all tests in the class when the ONNX model is missing or cannot be loaded.
/// </summary>
public abstract class RealNerModelFixture
{
protected EnglishOnnxNerRunner Runner { get; private set; } = null!;
protected string ModelPath { get; private set; } = null!;
[OneTimeSetUp]
public void OneTimeSetUpRealModel()
{
ModelPath = RealNerModelPaths.ResolveRepoModelPath();
if (!File.Exists(ModelPath))
{
Assert.Ignore(RealNerModelPaths.ModelMissingMessage);
}
var options = Options.Create(new PiiRedactionOptions
{
EnglishOnnxModelPath = ModelPath,
OnnxModelPath = ModelPath
});
Runner = new EnglishOnnxNerRunner(options, NullLogger<EnglishOnnxNerRunner>.Instance);
if (!Runner.IsModelAvailable)
{
Runner.Dispose();
Assert.Ignore(RealNerModelPaths.ModelMissingMessage);
}
}
[OneTimeTearDown]
public void OneTimeTearDownRealModel()
{
Runner?.Dispose();
}
}