Skip to content

poc implementing test framework #578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Custom/VectorStores/CreateVectorStoreOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ namespace OpenAI.VectorStores;
[Experimental("OPENAI001")]
public partial class CreateVectorStoreOperation : OperationResult
{
protected CreateVectorStoreOperation() : base(default!)
{
_parentClient = default!;
_endpoint = default!;
_vectorStoreId = default!;
}

internal CreateVectorStoreOperation(
VectorStoreClient parentClient,
Uri endpoint,
Expand Down
33 changes: 17 additions & 16 deletions tests/Assistants/Assistants.VectorStoresTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using NUnit.Framework;
using Microsoft.ClientModel.TestFramework;

Check failure on line 1 in tests/Assistants/Assistants.VectorStoresTests.cs

View workflow job for this annotation

GitHub Actions / Build

The type or namespace name 'ClientModel' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
using Microsoft.Extensions.Logging;
using NUnit.Framework;
using OpenAI.Files;
using OpenAI.Tests.Utility;
using OpenAI.VectorStores;
using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -16,10 +18,9 @@

#pragma warning disable OPENAI001

[TestFixture(true)]
[TestFixture(false)]
[ClientTestFixture]
[Category("Assistants")]
public class VectorStoresTests : SyncAsyncTestBase
public class VectorStoresTests : RecordedTestBase<OpenAITestEnvironment>
{
private readonly List<CreateBatchFileJobOperation> _jobsToCancel = [];
private readonly List<VectorStoreFileAssociation> _associationsToRemove = [];
Expand All @@ -28,10 +29,10 @@

private static readonly DateTimeOffset s_2024 = new(2024, 1, 1, 0, 0, 0, TimeSpan.Zero);

private static VectorStoreClient GetTestClient() => GetTestClient<VectorStoreClient>(TestScenario.VectorStores);
private VectorStoreClient GetTestClient() => CreateProxyFromClient(GetTestClient<VectorStoreClient>(TestScenario.VectorStores), null);

public VectorStoresTests(bool isAsync)
: base(isAsync)
: base(isAsync, RecordedTestMode.Record)
{
}

Expand Down Expand Up @@ -118,11 +119,10 @@
});
}

[SyncOnly]
[Test]
public void CanEnumerateVectorStores()
{
AssertSyncOnly();

VectorStoreClient client = GetTestClient();
for (int i = 0; i < 10; i++)
{
Expand Down Expand Up @@ -158,11 +158,10 @@
Assert.That(lastIdSeen, Is.EqualTo(0));
}

[AsyncOnly]
[Test]
public async Task CanEnumerateVectorStoresAsync()
{
AssertAsyncOnly();

VectorStoreClient client = GetTestClient();
for (int i = 0; i < 5; i++)
{
Expand Down Expand Up @@ -264,11 +263,10 @@
Assert.That(count, Is.EqualTo(2));
}

[AsyncOnly]
[Test]
public async Task Pagination_CanRehydrateFileAssociationCollectionAsync()
{
AssertAsyncOnly();

VectorStoreClient client = GetTestClient();
CreateVectorStoreOperation createOperation = await client.CreateVectorStoreAsync(waitUntilCompleted: false);
VectorStore vectorStore = createOperation.Value;
Expand Down Expand Up @@ -301,7 +299,7 @@

// We added 6 files and will get pages with 2 items, so expect three pages in the collection.

// Use enumerators instead of enumerables to faciliate advancing the collections
// Use enumerators instead of enumerables to facilitate advancing the collections
// at the same time.
AsyncCollectionResult<VectorStoreFileAssociation> fileAssociations = client.GetFileAssociationsAsync(vectorStore.Id, new VectorStoreFileAssociationCollectionOptions() { PageSizeLimit = 2 });
IAsyncEnumerable<ClientResult> pages = fileAssociations.GetRawPagesAsync();
Expand Down Expand Up @@ -346,11 +344,10 @@
Assert.That(pageCount, Is.EqualTo(2));
}

[SyncOnly]
[Test]
public void Pagination_CanRehydrateFileAssociationCollection()
{
AssertSyncOnly();

VectorStoreClient client = GetTestClient();
CreateVectorStoreOperation createOperation = client.CreateVectorStore(waitUntilCompleted: true);
VectorStore vectorStore = createOperation.Value;
Expand Down Expand Up @@ -674,6 +671,10 @@
/// <exception cref="NotImplementedException"> The provided instance type isn't supported. </exception>
private void Validate<T>(T target)
{
if (target is IProxiedOperationResult result)
{
target = (T)result.Original;
}
if (target is CreateBatchFileJobOperation job)
{
Assert.That(job.BatchId, Is.Not.Null);
Expand Down
58 changes: 20 additions & 38 deletions tests/Assistants/AssistantsTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using NUnit.Framework;
using Microsoft.ClientModel.TestFramework;

Check failure on line 1 in tests/Assistants/AssistantsTests.cs

View workflow job for this annotation

GitHub Actions / Build

The type or namespace name 'ClientModel' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
using NUnit.Framework;
using OpenAI.Assistants;
using OpenAI.Files;
using OpenAI.Tests.Utility;
using OpenAI.VectorStores;
using System;
using System.ClientModel;
Expand Down Expand Up @@ -598,11 +598,10 @@
Assert.That(messages[0].Content[0].Text.ToLowerInvariant(), Does.Contain("tacos"));
}

[AsyncOnly]
[Test]
public async Task StreamingRunWorksAsync()
{
AssertAsyncOnly();

AssistantClient client = GetTestClient();
Assistant assistant = await client.CreateAssistantAsync("gpt-4o-mini");
Validate(assistant);
Expand Down Expand Up @@ -648,11 +647,10 @@
Print(">>> Done <<<");
}

[SyncOnly]
[Test]
public void StreamingRunWorks()
{
AssertSyncOnly();

AssistantClient client = GetTestClient();
Assistant assistant = client.CreateAssistant("gpt-4o-mini");
Validate(assistant);
Expand Down Expand Up @@ -698,11 +696,10 @@
Print(">>> Done <<<");
}

[AsyncOnly]
[TestCase]
public async Task StreamingToolCallAsync()
{
AssertAsyncOnly();

AssistantClient client = GetTestClient();
FunctionToolDefinition getWeatherTool = new("get_current_weather")
{
Expand Down Expand Up @@ -761,11 +758,10 @@
} while (run?.Status.IsTerminal == false);
}

[SyncOnly]
[TestCase]
public void StreamingToolCall()
{
AssertSyncOnly();

AssistantClient client = GetTestClient();
FunctionToolDefinition getWeatherTool = new("get_current_weather")
{
Expand Down Expand Up @@ -1027,11 +1023,10 @@
});
}

[SyncOnly]
[Test]
public void FileSearchStreamingWorksSync()
{
AssertSyncOnly();

const string fileContent = """
The favorite food of several people:
- Summanus Ferdinand: tacos
Expand Down Expand Up @@ -1118,11 +1113,10 @@
Assert.That(message, Does.Contain("cake"));
}

[AsyncOnly]
[Test]
public async Task FileSearchStreamingWorksAsync()
{
AssertAsyncOnly();

const string fileContent = """
The favorite food of several people:
- Summanus Ferdinand: tacos
Expand Down Expand Up @@ -1211,11 +1205,10 @@
Assert.That(message, Does.Contain("cake"));
}

[AsyncOnly]
[Test]
public async Task Pagination_CanEnumerateAssistantsAsync()
{
AssertAsyncOnly();

const int TestAssistantCount = 10;

AssistantClient client = GetTestClient();
Expand Down Expand Up @@ -1256,11 +1249,10 @@
Assert.That(count, Is.GreaterThanOrEqualTo(TestAssistantCount));
}

[SyncOnly]
[Test]
public void Pagination_CanEnumerateAssistants()
{
AssertSyncOnly();

const int TestAssistantCount = 10;

AssistantClient client = GetTestClient();
Expand Down Expand Up @@ -1301,11 +1293,10 @@
Assert.That(count, Is.GreaterThanOrEqualTo(TestAssistantCount));
}

[AsyncOnly]
[Test]
public async Task Pagination_CanPageThroughAssistantCollectionAsync()
{
AssertAsyncOnly();

const int TestAssistantCount = 10;
const int TestPageSizeLimit = 2;

Expand Down Expand Up @@ -1359,11 +1350,10 @@
Assert.That(pageCount, Is.GreaterThanOrEqualTo(TestAssistantCount / TestPageSizeLimit));
}

[SyncOnly]
[Test]
public void Pagination_CanPageThroughAssistantCollection()
{
AssertSyncOnly();

const int TestAssistantCount = 10;
const int TestPageSizeLimit = 2;

Expand Down Expand Up @@ -1427,11 +1417,10 @@
return els.Select(el => ModelReaderWriter.Read<Assistant>(BinaryData.FromString(el.GetRawText())));
}

[AsyncOnly]
[Test]
public async Task Pagination_CanRehydrateAssistantPageCollectionFromBytesAsync()
{
AssertAsyncOnly();

const int TestAssistantCount = 10;
const int TestPageSizeLimit = 2;

Expand Down Expand Up @@ -1495,11 +1484,10 @@
Assert.That(pageCount, Is.GreaterThanOrEqualTo(TestAssistantCount / TestPageSizeLimit));
}

[SyncOnly]
[Test]
public void Pagination_CanRehydrateAssistantPageCollectionFromBytes()
{
AssertSyncOnly();

const int TestAssistantCount = 10;
const int TestPageSizeLimit = 2;

Expand Down Expand Up @@ -1564,11 +1552,10 @@
Assert.That(pageCount, Is.GreaterThanOrEqualTo(TestAssistantCount / TestPageSizeLimit));
}

[AsyncOnly]
[Test]
public async Task Pagination_CanRehydrateAssistantPageCollectionFromPageTokenAsync()
{
AssertAsyncOnly();

const int TestAssistantCount = 10;
const int TestPageSizeLimit = 2;

Expand Down Expand Up @@ -1643,11 +1630,10 @@
Assert.That(pageCount, Is.GreaterThanOrEqualTo(TestAssistantCount / TestPageSizeLimit));
}

[SyncOnly]
[Test]
public void Pagination_CanRehydrateAssistantPageCollectionFromPageToken()
{
AssertSyncOnly();

const int TestAssistantCount = 10;
const int TestPageSizeLimit = 2;

Expand Down Expand Up @@ -1721,11 +1707,10 @@
Assert.That(pageCount, Is.GreaterThanOrEqualTo(TestAssistantCount / TestPageSizeLimit));
}

[AsyncOnly]
[Test]
public async Task Pagination_CanCastAssistantPageCollectionToConvenienceFromProtocolAsync()
{
AssertAsyncOnly();

const int TestAssistantCount = 10;
const int TestPageSizeLimit = 2;

Expand Down Expand Up @@ -1771,11 +1756,10 @@
Assert.That(count, Is.GreaterThanOrEqualTo(TestAssistantCount));
}

[SyncOnly]
[Test]
public void Pagination_CanCastAssistantPageCollectionToConvenienceFromProtocol()
{
AssertSyncOnly();

const int TestAssistantCount = 10;
const int TestPageSizeLimit = 2;

Expand Down Expand Up @@ -1821,11 +1805,10 @@
Assert.That(count, Is.GreaterThanOrEqualTo(TestAssistantCount));
}

[AsyncOnly]
[Test]
public async Task Pagination_CanRehydrateRunStepPageCollectionFromBytesAsync()
{
AssertAsyncOnly();

AssistantClient client = GetTestClient();
Assistant assistant = client.CreateAssistant("gpt-4o", new AssistantCreationOptions()
{
Expand Down Expand Up @@ -1896,11 +1879,10 @@
CollectionAssert.AreEqual(runSteps, rehydratedRunSteps);
}

[SyncOnly]
[Test]
public void Pagination_CanRehydrateRunStepPageCollectionFromBytes()
{
AssertSyncOnly();

AssistantClient client = GetTestClient();
Assistant assistant = client.CreateAssistant("gpt-4o", new AssistantCreationOptions()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Audio/GenerateSpeechMockTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.ClientModel;
using System.Threading;
using Microsoft.ClientModel.TestFramework;

Check failure on line 4 in tests/Audio/GenerateSpeechMockTests.cs

View workflow job for this annotation

GitHub Actions / Build

The type or namespace name 'ClientModel' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
using NUnit.Framework;
using OpenAI.Audio;
using OpenAI.Tests.Utility;

namespace OpenAI.Tests.Audio;

Expand Down
4 changes: 2 additions & 2 deletions tests/Audio/GenerateSpeechTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NUnit.Framework;
using Microsoft.ClientModel.TestFramework;

Check failure on line 1 in tests/Audio/GenerateSpeechTests.cs

View workflow job for this annotation

GitHub Actions / Build

The type or namespace name 'ClientModel' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
using NUnit.Framework;
using OpenAI.Audio;
using OpenAI.Tests.Utility;
using System;
using System.Text;
using System.Threading.Tasks;
Expand Down
Loading