Skip to content

Commit 8444a5a

Browse files
mareklinkaAnipik
authored andcommitted
Replace ConditionalFact usages with custom facts (#2402)
* Replace ConditionalFact usages with custom facts * Refactor ConditionalTheory usages Add AttributeUsage attributes * Make LessThanNetCore30OrNotNetCoreFactAttribute require an explicit skip message * Use correct target framework moniker for netcoreapp3.0 * Remove CORECLR constant * Remove an unused fact attribute
1 parent b863ac2 commit 8444a5a

32 files changed

+403
-221
lines changed

test/Microsoft.ML.Benchmarks.Tests/BenchmarksTest.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
using BenchmarkDotNet.Loggers;
1313
using BenchmarkDotNet.Running;
1414
using Microsoft.ML.Benchmarks.Harness;
15-
using Microsoft.ML.Internal.CpuMath;
15+
using Microsoft.ML.TestFramework.Attributes;
1616
using Xunit;
1717
using Xunit.Abstractions;
1818

@@ -29,15 +29,6 @@ public class BenchmarksTest
2929

3030
private ITestOutputHelper Output { get; }
3131

32-
public static bool CanExecute =>
33-
#if DEBUG
34-
false; // BenchmarkDotNet does not allow running the benchmarks in Debug, so this test is disabled for DEBUG
35-
#elif NET461
36-
false; // We are currently not running Benchmarks for FullFramework
37-
#else
38-
Environment.Is64BitProcess; // we don't support 32 bit yet
39-
#endif
40-
4132
public static TheoryData<Type> GetBenchmarks()
4233
{
4334
TheoryData<Type> benchmarks = new TheoryData<Type>();
@@ -54,7 +45,7 @@ where Attribute.IsDefined(type, typeof(CIBenchmark))
5445
return benchmarks;
5546
}
5647

57-
[ConditionalTheory(typeof(BenchmarksTest), nameof(CanExecute))]
48+
[BenchmarkTheory]
5849
[MemberData(nameof(GetBenchmarks))]
5950
public void BenchmarksProjectIsNotBroken(Type type)
6051
{

test/Microsoft.ML.Benchmarks/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ you can debug this test locally by:
9494
build.cmd -release -buildNative
9595

9696
2- Changing the configuration in Visual Studio from Debug -> Release
97-
3- Changing the annotation in the `BenchmarksProjectIsNotBroken` to replace `ConditionalTheory` with `Theory`, as below.
97+
3- Changing the annotation in the `BenchmarksProjectIsNotBroken` to replace `BenchmarkTheory` with `Theory`, as below.
9898

9999
```cs
100100
[Theory]

test/Microsoft.ML.Core.Tests/UnitTests/TestEntryPoints.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using Microsoft.ML.Internal.Utilities;
2323
using Microsoft.ML.LightGBM;
2424
using Microsoft.ML.Model.Onnx;
25+
using Microsoft.ML.TestFramework.Attributes;
2526
using Microsoft.ML.TimeSeriesProcessing;
2627
using Microsoft.ML.Trainers;
2728
using Microsoft.ML.Trainers.FastTree;
@@ -1312,7 +1313,7 @@ public void EntryPointMulticlassPipelineEnsemble()
13121313
}
13131314
}
13141315

1315-
[ConditionalFact(typeof(BaseTestBaseline), nameof(BaseTestBaseline.LessThanNetCore30OrNotNetCore))]
1316+
[LessThanNetCore30OrNotNetCoreFact("netcoreapp3.0 output differs from Baseline")]
13161317
public void EntryPointPipelineEnsembleGetSummary()
13171318
{
13181319
var dataPath = GetDataPath("breast-cancer-withheader.txt");
@@ -1916,14 +1917,14 @@ public void EntryPointEvaluateRanking()
19161917
}
19171918
}
19181919

1919-
[ConditionalFact(typeof(Environment), nameof(Environment.Is64BitProcess))] // LightGBM is 64-bit only
1920+
[LightGBMFact]
19201921
public void EntryPointLightGbmBinary()
19211922
{
19221923
Env.ComponentCatalog.RegisterAssembly(typeof(LightGbmBinaryModelParameters).Assembly);
19231924
TestEntryPointRoutine("breast-cancer.txt", "Trainers.LightGbmBinaryClassifier");
19241925
}
19251926

1926-
[ConditionalFact(typeof(Environment), nameof(Environment.Is64BitProcess))] // LightGBM is 64-bit only
1927+
[LightGBMFact]
19271928
public void EntryPointLightGbmMultiClass()
19281929
{
19291930
Env.ComponentCatalog.RegisterAssembly(typeof(LightGbmBinaryModelParameters).Assembly);
@@ -3649,7 +3650,7 @@ public void EntryPointWordEmbeddings()
36493650
}
36503651
}
36513652

3652-
[ConditionalFact(typeof(Environment), nameof(Environment.Is64BitProcess))] // TensorFlow is 64-bit only
3653+
[TensorFlowFact]
36533654
public void EntryPointTensorFlowTransform()
36543655
{
36553656
Env.ComponentCatalog.RegisterAssembly(typeof(TensorFlowTransformer).Assembly);
@@ -4069,7 +4070,7 @@ public void TestSimpleTrainExperiment()
40694070
}
40704071
}
40714072

4072-
[ConditionalFact(typeof(BaseTestBaseline), nameof(BaseTestBaseline.LessThanNetCore30OrNotNetCore))] // netcore3.0 output differs from Baseline
4073+
[LessThanNetCore30OrNotNetCoreFact("netcoreapp3.0 output differs from Baseline")]
40734074
public void TestCrossValidationMacro()
40744075
{
40754076
var dataPath = GetDataPath(TestDatasets.generatedRegressionDatasetmacro.trainFilename);
@@ -5537,7 +5538,7 @@ public void TestOvaMacroWithUncalibratedLearner()
55375538
}
55385539
}
55395540

5540-
[ConditionalFact(typeof(Environment), nameof(Environment.Is64BitProcess))] // TensorFlow is 64-bit only
5541+
[TensorFlowFact]
55415542
public void TestTensorFlowEntryPoint()
55425543
{
55435544
var dataPath = GetDataPath("Train-Tiny-28x28.txt");

test/Microsoft.ML.OnnxTransformTest/DnnImageFeaturizerTest.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Microsoft.ML.Model;
1414
using Microsoft.ML.RunTests;
1515
using Microsoft.ML.StaticPipe;
16+
using Microsoft.ML.TestFramework.Attributes;
1617
using Microsoft.ML.Transforms;
1718
using Microsoft.ML.Transforms.StaticPipe;
1819
using Xunit;
@@ -57,16 +58,9 @@ public DnnImageFeaturizerTests(ITestOutputHelper helper) : base(helper)
5758
{
5859
}
5960

60-
// Onnx is only supported on x64 Windows
61-
[ConditionalFact(typeof(Environment), nameof(Environment.Is64BitProcess))]
61+
[OnnxFact]
6262
void TestDnnImageFeaturizer()
6363
{
64-
// Onnxruntime supports Ubuntu 16.04, but not CentOS
65-
// Do not execute on CentOS image
66-
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
67-
return;
68-
69-
7064
var samplevector = GetSampleArrayData();
7165

7266
var dataView = DataViewConstructionUtils.CreateFromList(Env,
@@ -97,13 +91,9 @@ void TestDnnImageFeaturizer()
9791
catch (InvalidOperationException) { }
9892
}
9993

100-
// Onnx is only supported on x64 Windows
101-
[ConditionalFact(typeof(Environment), nameof(Environment.Is64BitProcess))]
94+
[OnnxFact]
10295
public void OnnxStatic()
10396
{
104-
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
105-
return;
106-
10797
var env = new MLContext(null, 1);
10898
var imageHeight = 224;
10999
var imageWidth = 224;
@@ -141,13 +131,9 @@ public void OnnxStatic()
141131
}
142132

143133
// Onnx is only supported on x64 Windows
144-
[ConditionalFact(typeof(Environment), nameof(Environment.Is64BitProcess))]
134+
[OnnxFact]
145135
public void TestOldSavingAndLoading()
146136
{
147-
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
148-
return;
149-
150-
151137
var samplevector = GetSampleArrayData();
152138

153139
var dataView = ML.Data.ReadFromEnumerable(

test/Microsoft.ML.OnnxTransformTest/OnnxTransformTests.cs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Microsoft.ML.Model;
1414
using Microsoft.ML.RunTests;
1515
using Microsoft.ML.StaticPipe;
16+
using Microsoft.ML.TestFramework.Attributes;
1617
using Microsoft.ML.Tools;
1718
using Microsoft.ML.Transforms;
1819
using Microsoft.ML.Transforms.StaticPipe;
@@ -21,24 +22,6 @@
2122

2223
namespace Microsoft.ML.Tests
2324
{
24-
25-
/// <summary>
26-
/// A Fact attribute for Onnx unit tests. Onnxruntime only supported
27-
/// on Windows, Linux (Ubuntu 16.04) and 64-bit platforms.
28-
/// </summary>
29-
public class OnnxFact : FactAttribute
30-
{
31-
public OnnxFact()
32-
{
33-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
34-
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ||
35-
!Environment.Is64BitProcess)
36-
{
37-
Skip = "Require 64 bit and Windows or Linux (Ubuntu 16.04).";
38-
}
39-
}
40-
}
41-
4225
public class OnnxTransformTests : TestDataPipeBase
4326
{
4427
private const int inputSize = 150528;
@@ -137,16 +120,12 @@ void TestSimpleCase()
137120
catch (ArgumentOutOfRangeException) { }
138121
catch (InvalidOperationException) { }
139122
}
140-
141-
// x86 not supported
142-
[ConditionalTheory(typeof(Environment), nameof(Environment.Is64BitProcess))]
123+
124+
[OnnxTheory]
143125
[InlineData(null, false)]
144126
[InlineData(null, true)]
145127
void TestOldSavingAndLoading(int? gpuDeviceId, bool fallbackToCpu)
146128
{
147-
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
148-
return;
149-
150129
var modelFile = "squeezenet/00000001/model.onnx";
151130
var samplevector = GetSampleArrayData();
152131

0 commit comments

Comments
 (0)