Skip to content

Commit b94e9ba

Browse files
committed
Skip model integration test without native assets
1 parent 916cbbd commit b94e9ba

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

src/MLXSharp.Tests/ModelIntegrationTests.cs

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using System.Threading;
34
using System.Threading.Tasks;
45
using Microsoft.Extensions.AI;
@@ -10,11 +11,10 @@ namespace MLXSharp.Tests;
1011

1112
public sealed class ModelIntegrationTests
1213
{
13-
[Fact]
14+
[RequiresNativeModelFact]
1415
public async Task NativeBackendAnswersSimpleMathAsync()
1516
{
1617
TestEnvironment.EnsureInitialized();
17-
EnsureAssets();
1818

1919
var options = CreateOptions();
2020
using var backend = MlxNativeBackend.Create(options);
@@ -59,14 +59,44 @@ private static MlxClientOptions CreateOptions()
5959
return options;
6060
}
6161

62-
private static void EnsureAssets()
62+
}
63+
64+
internal sealed class RequiresNativeModelFactAttribute : FactAttribute
65+
{
66+
public RequiresNativeModelFactAttribute()
6367
{
68+
TestEnvironment.EnsureInitialized();
69+
70+
if (!NativeLibraryLocator.TryEnsure(out var skipReason))
71+
{
72+
Skip = skipReason ?? "Native MLX library is not available.";
73+
return;
74+
}
75+
6476
var modelPath = Environment.GetEnvironmentVariable("MLXSHARP_MODEL_PATH");
65-
Assert.False(string.IsNullOrWhiteSpace(modelPath), "Native model bundle path is not configured. Set MLXSHARP_MODEL_PATH to a valid directory.");
66-
Assert.True(System.IO.Directory.Exists(modelPath), $"Native model bundle not found at '{modelPath}'.");
77+
if (string.IsNullOrWhiteSpace(modelPath))
78+
{
79+
Skip = "Native model bundle path is not configured. Set MLXSHARP_MODEL_PATH to a valid directory.";
80+
return;
81+
}
82+
83+
if (!Directory.Exists(modelPath))
84+
{
85+
Skip = $"Native model bundle not found at '{modelPath}'.";
86+
return;
87+
}
6788

6889
var library = Environment.GetEnvironmentVariable("MLXSHARP_LIBRARY");
69-
Assert.False(string.IsNullOrWhiteSpace(library), "Native libmlxsharp library is not configured. Set MLXSHARP_LIBRARY to the staged native library that ships with the official MLXSharp release.");
70-
Assert.True(System.IO.File.Exists(library), $"Native libmlxsharp library not found at '{library}'.");
90+
if (string.IsNullOrWhiteSpace(library) || !File.Exists(library))
91+
{
92+
Skip = "Native libmlxsharp library is not configured. Set MLXSHARP_LIBRARY to the staged native library that ships with the official MLXSharp release.";
93+
return;
94+
}
95+
96+
var tokenizerPath = Environment.GetEnvironmentVariable("MLXSHARP_TOKENIZER_PATH");
97+
if (!string.IsNullOrWhiteSpace(tokenizerPath) && !File.Exists(tokenizerPath))
98+
{
99+
Skip = $"Native tokenizer file not found at '{tokenizerPath}'.";
100+
}
71101
}
72102
}

0 commit comments

Comments
 (0)