Skip to content

Commit

Permalink
.Net: Removed unneeded use of RedirectOutput (#5634)
Browse files Browse the repository at this point in the history
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [ ] The code builds clean without any errors or warnings
- [ ] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄

Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>
  • Loading branch information
markwallace-microsoft and SergeyMenshykh committed Mar 26, 2024
1 parent 9bac78e commit 9aed71f
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 69 deletions.
14 changes: 10 additions & 4 deletions dotnet/src/IntegrationTests/Connectors/OpenAI/ChatHistoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ public sealed class ChatHistoryTests : IDisposable
{
private readonly IKernelBuilder _kernelBuilder;
private readonly XunitLogger<Kernel> _logger;
private readonly RedirectOutput _testOutputHelper;
private readonly IConfigurationRoot _configuration;
private static readonly JsonSerializerOptions s_jsonOptionsCache = new() { WriteIndented = true };
public ChatHistoryTests(ITestOutputHelper output)
{
this._logger = new XunitLogger<Kernel>(output);
this._testOutputHelper = new RedirectOutput(output);

// Load configuration
this._configuration = new ConfigurationBuilder()
Expand Down Expand Up @@ -146,7 +144,15 @@ public string CreateSpecialPoem()

public void Dispose()
{
this._logger.Dispose();
this._testOutputHelper.Dispose();
this.Dispose(true);
GC.SuppressFinalize(this);
}

private void Dispose(bool disposing)
{
if (disposing)
{
this._logger.Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@

namespace SemanticKernel.IntegrationTests.Connectors.OpenAI;

public sealed class OpenAIAudioToTextTests : IDisposable
public sealed class OpenAIAudioToTextTests
{
private readonly RedirectOutput _testOutputHelper;
private readonly IConfigurationRoot _configuration;

public OpenAIAudioToTextTests(ITestOutputHelper output)
{
this._testOutputHelper = new RedirectOutput(output);

// Load configuration
this._configuration = new ConfigurationBuilder()
.AddJsonFile(path: "testsettings.json", optional: false, reloadOnChange: true)
Expand Down Expand Up @@ -83,9 +80,4 @@ public async Task AzureOpenAIAudioToTextTestAsync()
// Assert
Assert.Contains("The sun rises in the east and sets in the west.", result.Text, StringComparison.OrdinalIgnoreCase);
}

public void Dispose()
{
this._testOutputHelper.Dispose();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
Expand All @@ -12,15 +11,13 @@

namespace SemanticKernel.IntegrationTests.Connectors.OpenAI;

public sealed class OpenAITextEmbeddingTests : IDisposable
public sealed class OpenAITextEmbeddingTests
{
private const int AdaVectorLength = 1536;
private readonly IConfigurationRoot _configuration;

public OpenAITextEmbeddingTests(ITestOutputHelper output)
{
this._testOutputHelper = new RedirectOutput(output);

// Load configuration
this._configuration = new ConfigurationBuilder()
.AddJsonFile(path: "testsettings.json", optional: false, reloadOnChange: true)
Expand Down Expand Up @@ -69,15 +66,4 @@ public async Task AzureOpenAITestAsync(string testInputString)
Assert.Equal(AdaVectorLength, singleResult.Length);
Assert.Equal(3, batchResult.Count);
}

#region internals

private readonly RedirectOutput _testOutputHelper;

public void Dispose()
{
this._testOutputHelper.Dispose();
}

#endregion
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.SemanticKernel;
Expand All @@ -11,15 +10,12 @@

namespace SemanticKernel.IntegrationTests.Connectors.OpenAI;

public sealed class OpenAITextToAudioTests : IDisposable
public sealed class OpenAITextToAudioTests
{
private readonly RedirectOutput _testOutputHelper;
private readonly IConfigurationRoot _configuration;

public OpenAITextToAudioTests(ITestOutputHelper output)
{
this._testOutputHelper = new RedirectOutput(output);

// Load configuration
this._configuration = new ConfigurationBuilder()
.AddJsonFile(path: "testsettings.json", optional: false, reloadOnChange: true)
Expand Down Expand Up @@ -73,9 +69,4 @@ public async Task AzureOpenAITextToAudioTestAsync()
Assert.NotNull(result.Data);
Assert.False(result.Data!.Value.IsEmpty);
}

public void Dispose()
{
this._testOutputHelper.Dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@

namespace SemanticKernel.IntegrationTests.Connectors.OpenAI;

public sealed class OpenAIToolsTests : BaseIntegrationTest, IDisposable
public sealed class OpenAIToolsTests : BaseIntegrationTest
{
public OpenAIToolsTests(ITestOutputHelper output)
{
this._testOutputHelper = new RedirectOutput(output);

// Load configuration
this._configuration = new ConfigurationBuilder()
.AddJsonFile(path: "testsettings.json", optional: false, reloadOnChange: true)
Expand Down Expand Up @@ -198,11 +196,8 @@ private Kernel InitializeKernel()
return kernel;
}

private readonly RedirectOutput _testOutputHelper;
private readonly IConfigurationRoot _configuration;

public void Dispose() => this._testOutputHelper.Dispose();

/// <summary>
/// A plugin that returns the current time.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@

namespace SemanticKernel.IntegrationTests.Planners.Handlebars;

public sealed class HandlebarsPlannerTests : IDisposable
public sealed class HandlebarsPlannerTests
{
public HandlebarsPlannerTests(ITestOutputHelper output)
{
this._testOutputHelper = new RedirectOutput(output);

// Load configuration
this._configuration = new ConfigurationBuilder()
.AddJsonFile(path: "testsettings.json", optional: false, reloadOnChange: true)
Expand Down Expand Up @@ -154,7 +152,6 @@ private Kernel InitializeKernel(bool useEmbeddings = false, bool useChatModel =
return builder.Build();
}

private readonly RedirectOutput _testOutputHelper;
private readonly IConfigurationRoot _configuration;

private static readonly HandlebarsPlannerOptions s_defaultPlannerOptions = new()
Expand Down Expand Up @@ -183,9 +180,4 @@ public Qux(string bar, int baz)
[KernelFunction, Description("Returns default Qux object.")]
public Qux GetDefaultQux() => new("bar", 42);
}

public void Dispose()
{
this._testOutputHelper.Dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public sealed class FunctionCallingStepwisePlannerTests : BaseIntegrationTest, I
public FunctionCallingStepwisePlannerTests(ITestOutputHelper output)
{
this._logger = new XunitLogger<Kernel>(output);
this._testOutputHelper = new RedirectOutput(output);

// Load configuration
this._configuration = new ConfigurationBuilder()
Expand Down Expand Up @@ -173,13 +172,11 @@ private Kernel InitializeKernel()
return kernel;
}

private readonly RedirectOutput _testOutputHelper;
private readonly IConfigurationRoot _configuration;
private readonly XunitLogger<Kernel> _logger;

public void Dispose()
{
this._logger.Dispose();
this._testOutputHelper.Dispose();
}
}
3 changes: 0 additions & 3 deletions dotnet/src/IntegrationTests/PromptTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public sealed class PromptTests : IDisposable
public PromptTests(ITestOutputHelper output)
{
this._logger = new XunitLogger<Kernel>(output);
this._testOutputHelper = new RedirectOutput(output);

// Load configuration
this._configuration = new ConfigurationBuilder()
Expand Down Expand Up @@ -66,12 +65,10 @@ public async Task GenerateStoryTestAsync(string resourceName, bool isHandlebars)
private readonly IKernelBuilder _kernelBuilder;
private readonly IConfigurationRoot _configuration;
private readonly XunitLogger<Kernel> _logger;
private readonly RedirectOutput _testOutputHelper;

public void Dispose()
{
this._logger.Dispose();
this._testOutputHelper.Dispose();
}

private void ConfigureAzureOpenAI(IKernelBuilder kernelBuilder)
Expand Down
11 changes: 1 addition & 10 deletions dotnet/src/IntegrationTests/WebPlugin/WebPluginTests.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using Microsoft.Extensions.Configuration;
using Xunit;
using Xunit.Abstractions;

namespace SemanticKernel.IntegrationTests.WebPlugin;

public sealed class WebPluginTests : IDisposable
public sealed class WebPluginTests
{
private readonly string _bingApiKey;

public WebPluginTests(ITestOutputHelper output)
{
this._output = output;

this._testOutputHelper = new RedirectOutput(output);

// Load configuration
IConfigurationRoot configuration = new ConfigurationBuilder()
.AddJsonFile(path: "testsettings.json", optional: false, reloadOnChange: true)
Expand All @@ -33,12 +30,6 @@ public WebPluginTests(ITestOutputHelper output)
#region internals

private readonly ITestOutputHelper _output;
private readonly RedirectOutput _testOutputHelper;

public void Dispose()
{
this._testOutputHelper.Dispose();
}

#endregion
}

0 comments on commit 9aed71f

Please sign in to comment.