Skip to content
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

Add unit tests for AutoSampler functionality #416

Closed
wants to merge 11 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/tunny_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
- name: Install dependencies
run: |
dotnet restore
pip install optuna find-libpython
pip install find-libpython optuna optunahub cmaes scipy torch

- name: Set Python DLL path and PYTHONHOME
run: |
Expand Down
2 changes: 1 addition & 1 deletion Optuna/Optuna.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="pythonnet" Version="3.0.5" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="9.0.0" />
<PackageReference Include="pythonnet" Version="3.1.0-preview2024-09-06" />
<PackageReference Include="Stub.System.Data.SQLite.Core.NetFramework" Version="1.0.119" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
</ItemGroup>
Expand Down
19 changes: 0 additions & 19 deletions OptunaTests/PythonSetup.cs

This file was deleted.

35 changes: 35 additions & 0 deletions OptunaTests/Sampler/OptunaHub/AutoSamplerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Optuna.Util;

using Python.Runtime;

using Xunit;

namespace Optuna.Sampler.OptunaHub.Tests
{
public class AutoSamplerTests
{
[Fact]
public void ConstructorTest()
{
var sampler = new AutoSampler();
Assert.Equal(ObjectiveNumberSupport.Any, sampler.ObjectiveNumberSupport);
Assert.False(sampler.ForceReload);
}

[Fact]
public void ToPythonTest()
{
PythonEngine.Initialize();
PythonEngine.BeginAllowThreads();
using(Py.GIL())
{
var sampler = new AutoSampler();
dynamic pyObj = sampler.ToPython(false);
Assert.Equal("AutoSampler", pyObj.ToString());
dynamic pyObj2 = sampler.ToPython(true);
Assert.Equal("AutoSampler", pyObj2.ToString());
}
PythonEngine.Shutdown();
}
}
}
14 changes: 4 additions & 10 deletions OptunaTests/Study/StudyWrapperTests.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
using System;

using OptunaTests;

using Python.Runtime;

using Xunit;

namespace Optuna.Study.Tests
{
public class StudyWrapperTests : IClassFixture<TestFixture>
public class StudyWrapperTests
{
private readonly TestFixture _fixture;

public StudyWrapperTests(TestFixture fixture)
{
_fixture = fixture;
}

[Fact]
public void ConstructorArgTypeTest()
{
PythonEngine.Initialize();
PythonEngine.BeginAllowThreads();
using (Py.GIL())
{
var pyInt = new PyInt(1);
Assert.Throws<ArgumentException>(() => new StudyWrapper(pyInt));
}
PythonEngine.Shutdown();
}
}
}
Loading