Skip to content

Commit

Permalink
fix the requested_extras parsing for pip report (#1154)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauld-msft authored Jun 5, 2024
1 parent 9f1e5a9 commit dec038a
Show file tree
Hide file tree
Showing 6 changed files with 371 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ public sealed record PipInstallationReportItem
/// Extras requested by the user.
/// </summary>
[JsonProperty("requested_extras")]
public JObject RequestedExtras { get; set; }
public JArray RequestedExtras { get; set; }
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
<data name="pip_report_multi_pkg" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>pip_report_multi_pkg.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="pip_report_simple_extras" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>pip_report_simple_extras.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="pip_report_single_pkg" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>pip_report_single_pkg.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class PipReportComponentDetectorTests : BaseDetectorTest<PipReportCompone
private readonly PipInstallationReport singlePackageReportBadVersion;
private readonly PipInstallationReport multiPackageReport;
private readonly PipInstallationReport jupyterPackageReport;
private readonly PipInstallationReport simpleExtrasReport;

public PipReportComponentDetectorTests()
{
Expand All @@ -43,6 +44,7 @@ public PipReportComponentDetectorTests()
this.singlePackageReportBadVersion = JsonConvert.DeserializeObject<PipInstallationReport>(TestResources.pip_report_single_pkg_bad_version);
this.multiPackageReport = JsonConvert.DeserializeObject<PipInstallationReport>(TestResources.pip_report_multi_pkg);
this.jupyterPackageReport = JsonConvert.DeserializeObject<PipInstallationReport>(TestResources.pip_report_jupyterlab);
this.simpleExtrasReport = JsonConvert.DeserializeObject<PipInstallationReport>(TestResources.pip_report_simple_extras);
}

[TestMethod]
Expand Down Expand Up @@ -207,6 +209,31 @@ public async Task TestPipReportDetector_SingleComponentAsync()
sixComponent.License.Should().Be("MIT");
}

[TestMethod]
public async Task TestPipReportDetector_SimpleExtrasAsync()
{
this.pipCommandService.Setup(x => x.GenerateInstallationReportAsync(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync((this.simpleExtrasReport, null));

var (result, componentRecorder) = await this.DetectorTestUtility
.WithFile("requirements.txt", string.Empty)
.ExecuteDetectorAsync();

result.ResultCode.Should().Be(ProcessingResultCode.Success);

this.mockLogger.Verify(x => x.Log(
LogLevel.Information,
It.IsAny<EventId>(),
It.Is<It.IsAnyType>((o, t) => o.ToString().StartsWith("PipReport: Generating pip installation report")),
It.IsAny<Exception>(),
(Func<It.IsAnyType, Exception, string>)It.IsAny<object>()));

var detectedComponents = componentRecorder.GetDetectedComponents();
var pipComponents = detectedComponents.Where(detectedComponent => detectedComponent.Component.Id.Contains("pip")).ToList();
var requestsComponent = pipComponents.Single(x => ((PipComponent)x.Component).Name.Equals("requests")).Component as PipComponent;
requestsComponent.Version.Should().Be("2.32.3");
}

[TestMethod]
public async Task TestPipReportDetector_MultiComponentAsync()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests [security] >= 2.32.3, == 2.32.* ; python_version > "2.7"

0 comments on commit dec038a

Please sign in to comment.