-
Notifications
You must be signed in to change notification settings - Fork 4.4k
.Net: Integration tests for the python code interpreter plugin #11817
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
Merged
SergeyMenshykh
merged 8 commits into
microsoft:main
from
SergeyMenshykh:integration-tests-for-python-code-interpreter
May 1, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b25830a
add integration tests fot the python code interpreter plugin
SergeyMenshykh bd9c472
rename secret and update readme
SergeyMenshykh f5e352d
Merge branch 'main' into integration-tests-for-python-code-interpreter
SergeyMenshykh 6a2ea3f
fix typo
SergeyMenshykh 1ce746b
Merge branch 'integration-tests-for-python-code-interpreter' of https…
SergeyMenshykh 2b4d0b5
address pr review comments
SergeyMenshykh 7b0d274
Merge branch 'main' into integration-tests-for-python-code-interpreter
SergeyMenshykh f241a23
Merge branch 'main' into integration-tests-for-python-code-interpreter
SergeyMenshykh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
dotnet/src/IntegrationTests/Plugins/Core/SessionsPythonPluginTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
| using Microsoft.SemanticKernel.Plugins.Core.CodeInterpreter; | ||
| using Microsoft.Extensions.Configuration; | ||
| using SemanticKernel.IntegrationTests.TestSettings; | ||
| using System.Net.Http; | ||
| using Azure.Identity; | ||
| using Azure.Core; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace SemanticKernel.IntegrationTests.Plugins.Core; | ||
|
|
||
| public sealed class SessionsPythonPluginTests : IDisposable | ||
| { | ||
| private const string SkipReason = "For manual verification only"; | ||
|
|
||
| private readonly SessionsPythonSettings _settings; | ||
| private readonly HttpClientFactory _httpClientFactory; | ||
| private readonly SessionsPythonPlugin _sut; | ||
|
|
||
| public SessionsPythonPluginTests() | ||
| { | ||
| var configurationRoot = new ConfigurationBuilder() | ||
| .AddJsonFile(path: "testsettings.json", optional: true, reloadOnChange: true) | ||
| .AddJsonFile(path: "testsettings.development.json", optional: true, reloadOnChange: true) | ||
| .AddEnvironmentVariables() | ||
| .AddUserSecrets<SessionsPythonPluginTests>() | ||
| .Build(); | ||
|
|
||
| var _configuration = configurationRoot | ||
| .GetSection("AzureContainerAppSessionPool") | ||
| .Get<AzureContainerAppSessionPoolConfiguration>()!; | ||
|
|
||
| this._settings = new(sessionId: Guid.NewGuid().ToString(), endpoint: new Uri(_configuration.Endpoint)) | ||
| { | ||
| CodeExecutionType = SessionsPythonSettings.CodeExecutionTypeSetting.Synchronous, | ||
| CodeInputType = SessionsPythonSettings.CodeInputTypeSetting.Inline | ||
| }; | ||
|
|
||
| this._httpClientFactory = new HttpClientFactory(); | ||
|
|
||
| this._sut = new SessionsPythonPlugin(this._settings, this._httpClientFactory, GetAuthTokenAsync); | ||
| } | ||
|
|
||
| [Fact(Skip = SkipReason)] | ||
| public async Task ItShouldUploadFileAsync() | ||
| { | ||
| // Act | ||
| var result = await this._sut.UploadFileAsync("test_file.txt", @"TestData\SessionsPythonPlugin\file_to_upload_1.txt"); | ||
|
|
||
| // Assert | ||
| Assert.Equal("test_file.txt", result.Filename); | ||
| Assert.Equal(322, result.Size); | ||
| Assert.NotNull(result.LastModifiedTime); | ||
| Assert.Equal("/mnt/data/test_file.txt", result.FullPath); | ||
| } | ||
|
|
||
| [Fact(Skip = SkipReason)] | ||
| public async Task ItShouldDownloadFileAsync() | ||
| { | ||
| // Arrange | ||
| await this._sut.UploadFileAsync("test_file.txt", @"TestData\SessionsPythonPlugin\file_to_upload_1.txt"); | ||
|
|
||
| // Act | ||
| var fileContent = await this._sut.DownloadFileAsync("test_file.txt"); | ||
|
|
||
| // Assert | ||
| Assert.Equal(322, fileContent.Length); | ||
| } | ||
|
|
||
| [Fact(Skip = SkipReason)] | ||
| public async Task ItShouldListFilesAsync() | ||
| { | ||
| // Arrange | ||
| await this._sut.UploadFileAsync("test_file_1.txt", @"TestData\SessionsPythonPlugin\file_to_upload_1.txt"); | ||
| await this._sut.UploadFileAsync("test_file_2.txt", @"TestData\SessionsPythonPlugin\file_to_upload_2.txt"); | ||
|
|
||
| // Act | ||
| var files = await this._sut.ListFilesAsync(); | ||
|
|
||
| // Assert | ||
| Assert.Equal(2, files.Count); | ||
|
|
||
| var firstFile = files[0]; | ||
| Assert.Equal("test_file_1.txt", firstFile.Filename); | ||
| Assert.Equal(322, firstFile.Size); | ||
| Assert.NotNull(firstFile.LastModifiedTime); | ||
| Assert.Equal("/mnt/data/test_file_1.txt", firstFile.FullPath); | ||
|
|
||
| var secondFile = files[1]; | ||
| Assert.Equal("test_file_2.txt", secondFile.Filename); | ||
| Assert.Equal(336, secondFile.Size); | ||
| Assert.NotNull(secondFile.LastModifiedTime); | ||
| Assert.Equal("/mnt/data/test_file_2.txt", secondFile.FullPath); | ||
| } | ||
|
|
||
| [Fact(Skip = SkipReason)] | ||
| public async Task ItShouldExecutePythonCodeAsync() | ||
| { | ||
| // Arrange | ||
| string code = "result = 5 + 3\nprint(result)"; | ||
|
|
||
| // Act | ||
| var result = await this._sut.ExecuteCodeAsync(code); | ||
|
|
||
| // Assert | ||
| Assert.Contains("8", result); | ||
| Assert.Contains("Success", result); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Acquires authentication token for the Azure Container App Session pool. | ||
| /// </summary> | ||
| private static async Task<string> GetAuthTokenAsync() | ||
| { | ||
| string resource = "https://acasessions.io/.default"; | ||
|
|
||
| var credential = new AzureCliCredential(); | ||
|
|
||
| AccessToken token = await credential.GetTokenAsync(new Azure.Core.TokenRequestContext([resource])).ConfigureAwait(false); | ||
|
|
||
| return token.Token; | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| this._httpClientFactory.Dispose(); | ||
| } | ||
|
|
||
| private sealed class HttpClientFactory : IHttpClientFactory, IDisposable | ||
| { | ||
| private readonly List<HttpClient> _httpClients = []; | ||
|
|
||
| public HttpClient CreateClient(string name) | ||
| { | ||
| var client = new HttpClient(); | ||
| this._httpClients.Add(client); | ||
| return client; | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| this._httpClients.ForEach(client => client.Dispose()); | ||
| } | ||
| } | ||
| } |
3 changes: 3 additions & 0 deletions
3
dotnet/src/IntegrationTests/TestData/SessionsPythonPlugin/file_to_upload_1.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Semantic Kernel | ||
|
|
||
| Semantic Kernel is an SDK that integrates Large Language Models (LLMs) like OpenAI, Azure OpenAI, and Hugging Face with conventional programming languages like C#, Python, and Java. Semantic Kernel achieves this by allowing you to define plugins that can be chained together in just a few lines of code. |
1 change: 1 addition & 0 deletions
1
dotnet/src/IntegrationTests/TestData/SessionsPythonPlugin/file_to_upload_2.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Semantic Kernel is a software development kit (SDK) that seamlessly combines Large Language Models (LLMs) such as OpenAI, Azure OpenAI, and Hugging Face with traditional programming languages like C#, Python, and Java. It enables the creation of plugins that can be linked together with minimal code, facilitating efficient integration. |
12 changes: 12 additions & 0 deletions
12
dotnet/src/IntegrationTests/TestSettings/AzureContainerAppSessionPoolConfiguration.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
|
|
||
| namespace SemanticKernel.IntegrationTests.TestSettings; | ||
|
|
||
| [SuppressMessage("Performance", "CA1812:Internal class that is apparently never instantiated", | ||
| Justification = "Configuration classes are instantiated through IConfiguration.")] | ||
| internal sealed class AzureContainerAppSessionPoolConfiguration(string endpoint) | ||
| { | ||
| public string Endpoint { get; set; } = endpoint; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.