-
Notifications
You must be signed in to change notification settings - Fork 674
Adding public API test coverage for Aspire.Hosting.Python #5110
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
Changes from 7 commits
c67cdf3
ad059e5
f3bd0d3
ec25311
96efb2e
90a67ac
386bd9c
baf09c4
d038841
0ad4c44
fc8f9b2
f75eb99
1179728
1961d80
a21b603
9fd8ab6
4466e5d
a54821a
be2c5c8
3616f3a
d2cd1b4
2420a46
0fa62c5
ae319dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,277 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Xunit; | ||
|
||
namespace Aspire.Hosting.Python.Tests; | ||
|
||
public class PythonPublicApiTests | ||
{ | ||
#region PythonProjectResource | ||
|
||
[Fact] | ||
public void CtorPythonProjectResourceShouldThrowWhenNameIsNull() | ||
{ | ||
string name = null!; | ||
const string executablePath = "/src/python"; | ||
const string projectDirectory = "/data/python"; | ||
|
||
var action = () => new PythonProjectResource(name, executablePath, projectDirectory); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(name), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void CtorPythonProjectResourceShouldThrowWhenExecutablePathIsNull() | ||
{ | ||
const string name = "Python"; | ||
string executablePath = null!; | ||
const string projectDirectory = "/data/python"; | ||
|
||
var action = () => new PythonProjectResource(name, executablePath, projectDirectory); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal("command", exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void CtorPythonProjectResourceShouldThrowWhenProjectDirectoryIsNull() | ||
{ | ||
const string name = "Python"; | ||
const string executablePath = "/src/python"; | ||
string projectDirectory = null!; | ||
|
||
var action = () => new PythonProjectResource(name, executablePath, projectDirectory); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal("workingDirectory", exception.ParamName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
And because the exception is being thrown from @mitchdenny @eerhardt @sebastienros Is there a pattern that we follow in such cases? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be honest, I would add a check, it would be more transparent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/using-standard-exception-types
I read this as the ParamName should be set to the name of the parameter that was invalid. In this case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to do the null check in the PythonResource ctor just for clarity. I'm not a fan of the ThrowIfNull method, seems a bit odd to do it that way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second thought it probably doesn't matter to the end result. |
||
} | ||
|
||
#endregion | ||
|
||
#region PythonProjectResourceBuilderExtensions | ||
|
||
[Fact] | ||
public void AddPythonProjectShouldThrowWhenBuilderIsNull() | ||
{ | ||
IDistributedApplicationBuilder builder = null!; | ||
const string name = "Python"; | ||
const string projectDirectory = "/src/python"; | ||
const string scriptPath = "scripts"; | ||
string[] scriptArgs = ["--traces"]; | ||
|
||
var action = () => builder.AddPythonProject( | ||
name, | ||
projectDirectory, | ||
scriptPath, | ||
scriptArgs); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(builder), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void AddPythonProjectShouldThrowWhenNameIsNull() | ||
{ | ||
var builder = DistributedApplication.CreateBuilder(); | ||
string name = null!; | ||
const string projectDirectory = "/src/python"; | ||
const string scriptPath = "scripts"; | ||
string[] scriptArgs = ["--traces"]; | ||
|
||
var action = () => builder.AddPythonProject( | ||
name, | ||
projectDirectory, | ||
scriptPath, | ||
scriptArgs); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(name), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void AddPythonProjectShouldThrowWhenProjectDirectoryIsNull() | ||
{ | ||
var builder = DistributedApplication.CreateBuilder(); | ||
const string name = "Python"; | ||
string projectDirectory = null!; | ||
const string scriptPath = "scripts"; | ||
string[] scriptArgs = ["--traces"]; | ||
|
||
var action = () => builder.AddPythonProject( | ||
name, | ||
projectDirectory, | ||
scriptPath, | ||
scriptArgs); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(projectDirectory), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void AddPythonProjectShouldThrowWhenScriptPathIsNull() | ||
{ | ||
var builder = DistributedApplication.CreateBuilder(); | ||
const string name = "Python"; | ||
const string projectDirectory = "/src/python"; | ||
string scriptPath = null!; | ||
string[] scriptArgs = ["--traces"]; | ||
|
||
var action = () => builder.AddPythonProject( | ||
name, | ||
projectDirectory, | ||
scriptPath, | ||
scriptArgs); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(scriptPath), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void AddPythonProjectShouldThrowWhenScriptArgsIsNull() | ||
{ | ||
var builder = DistributedApplication.CreateBuilder(); | ||
const string name = "Python"; | ||
const string projectDirectory = "/src/python"; | ||
const string scriptPath = "scripts"; | ||
string[] scriptArgs = null!; | ||
|
||
var action = () => builder.AddPythonProject( | ||
name, | ||
projectDirectory, | ||
scriptPath, | ||
scriptArgs); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(scriptArgs), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void AddPythonProjectWithVirtualEnvironmentPathShouldThrowWhenBuilderIsNull() | ||
{ | ||
IDistributedApplicationBuilder builder = null!; | ||
const string name = "Python"; | ||
const string projectDirectory = "/src/python"; | ||
const string scriptPath = "scripts"; | ||
var virtualEnvironmentPath = ".venv"; | ||
string[] scriptArgs = ["--traces"]; ; | ||
|
||
var action = () => builder.AddPythonProject( | ||
name, | ||
projectDirectory, | ||
scriptPath, | ||
virtualEnvironmentPath, | ||
scriptArgs); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(builder), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void AddPythonProjectWithVirtualEnvironmentPathShouldThrowWhenNameIsNull() | ||
{ | ||
var builder = DistributedApplication.CreateBuilder(); | ||
string name = null!; | ||
const string projectDirectory = "/src/python"; | ||
const string scriptPath = "scripts"; | ||
const string virtualEnvironmentPath = ".venv"; | ||
string[] scriptArgs = ["--traces"]; ; | ||
|
||
var action = () => builder.AddPythonProject( | ||
name, | ||
projectDirectory, | ||
scriptPath, | ||
virtualEnvironmentPath, | ||
scriptArgs); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(name), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void AddPythonProjectWithVirtualEnvironmentPathShouldThrowWhenProjectDirectoryIsNull() | ||
{ | ||
var builder = DistributedApplication.CreateBuilder(); | ||
const string name = "Python"; | ||
string projectDirectory = null!; | ||
const string scriptPath = "scripts"; | ||
const string virtualEnvironmentPath = ".venv"; | ||
string[] scriptArgs = ["--traces"]; ; | ||
|
||
var action = () => builder.AddPythonProject( | ||
name, | ||
projectDirectory, | ||
scriptPath, | ||
virtualEnvironmentPath, | ||
scriptArgs); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(projectDirectory), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void AddPythonProjectWithVirtualEnvironmentPathShouldThrowWhenScriptPathIsNull() | ||
{ | ||
var builder = DistributedApplication.CreateBuilder(); | ||
const string name = "Python"; | ||
const string projectDirectory = "/src/python"; | ||
string scriptPath = null!; | ||
const string virtualEnvironmentPath = ".venv"; | ||
string[] scriptArgs = ["--traces"]; ; | ||
|
||
var action = () => builder.AddPythonProject( | ||
name, | ||
projectDirectory, | ||
scriptPath, | ||
virtualEnvironmentPath, | ||
scriptArgs); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(scriptPath), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void AddPythonProjectWithVirtualEnvironmentPathShouldThrowWhenVirtualEnvironmentPathIsNull() | ||
{ | ||
var builder = DistributedApplication.CreateBuilder(); | ||
const string name = "Python"; | ||
const string projectDirectory = "/src/python"; | ||
const string scriptPath = "scripts"; | ||
string virtualEnvironmentPath = null!; | ||
string[] scriptArgs = ["--traces"]; ; | ||
|
||
var action = () => builder.AddPythonProject( | ||
name, | ||
projectDirectory, | ||
scriptPath, | ||
virtualEnvironmentPath, | ||
scriptArgs); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(virtualEnvironmentPath), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void AddPythonProjectWithVirtualEnvironmentPathShouldThrowWhenScriptArgsIsNull() | ||
{ | ||
var builder = DistributedApplication.CreateBuilder(); | ||
const string name = "Python"; | ||
const string projectDirectory = "/src/python"; | ||
const string scriptPath = "scripts"; | ||
const string virtualEnvironmentPath = ".venv"; | ||
string[] scriptArgs = null!; | ||
|
||
var action = () => builder.AddPythonProject( | ||
name, | ||
projectDirectory, | ||
scriptPath, | ||
virtualEnvironmentPath, | ||
scriptArgs); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(scriptArgs), exception.ParamName); | ||
} | ||
|
||
#endregion | ||
} |
Uh oh!
There was an error while loading. Please reload this page.