private PythonPlatform CreatePlatform( string[] supportedVersions = null, string defaultVersion = null, string detectedVersion = null, BuildScriptGeneratorOptions commonOptions = null, PythonScriptGeneratorOptions pythonScriptGeneratorOptions = null) { supportedVersions = supportedVersions ?? new[] { defaultVersion }; defaultVersion = defaultVersion ?? Common.PythonVersions.Python37Version; var versionProvider = new TestPythonVersionProvider( supportedPythonVersions: supportedVersions, defaultVersion: defaultVersion); commonOptions = commonOptions ?? new BuildScriptGeneratorOptions(); pythonScriptGeneratorOptions = pythonScriptGeneratorOptions ?? new PythonScriptGeneratorOptions(); var detector = new TestPythonPlatformDetector(detectedVersion: detectedVersion); return(new PythonPlatform( Options.Create(commonOptions), Options.Create(pythonScriptGeneratorOptions), versionProvider, NullLogger <PythonPlatform> .Instance, detector, new PythonPlatformInstaller(Options.Create(commonOptions), NullLoggerFactory.Instance))); }
public void GeneratedSnippet_DoesNotHaveInstallScript_IfVersionIsAlreadyPresentOnDisk() { // Arrange var options = new BuildScriptGeneratorOptions() { EnableDynamicInstall = true }; var environment = new TestEnvironment(); var installerScriptSnippet = "##INSTALLER_SCRIPT##"; var versionProvider = new TestPythonVersionProvider(new[] { "3.7.5", "3.8.0" }, defaultVersion: "3.7.5"); var platformInstaller = new TestPythonPlatformInstaller( isVersionAlreadyInstalled: true, installerScript: installerScriptSnippet, Options.Create(options), environment); var platform = CreatePlatform(environment, versionProvider, platformInstaller, options); var repo = new MemorySourceRepo(); repo.AddFile("", PythonConstants.RequirementsFileName); repo.AddFile("print(1)", "bla.py"); var context = new BuildScriptGeneratorContext { SourceRepo = repo, PythonVersion = "3.7.5" }; // Act var snippet = platform.GenerateBashBuildScriptSnippet(context); // Assert Assert.NotNull(snippet); Assert.Null(snippet.PlatformInstallationScriptSnippet); Assert.Contains(ManifestFilePropertyKeys.PythonVersion, snippet.BuildProperties.Keys); Assert.Equal("3.7.5", snippet.BuildProperties[ManifestFilePropertyKeys.PythonVersion]); }
private PythonPlatform CreatePlatform(string defaultVersion = null) { var versionProvider = new TestPythonVersionProvider( supportedVersions: new[] { Common.PythonVersions.Python37Version }, defaultVersion: defaultVersion); var commonOptions = Options.Create(new BuildScriptGeneratorOptions()); var pythonScriptGeneratorOptions = Options.Create(new PythonScriptGeneratorOptions()); return(new PythonPlatform( commonOptions, pythonScriptGeneratorOptions, versionProvider, NullLogger <PythonPlatform> .Instance, detector: null, new PythonPlatformInstaller(commonOptions, NullLoggerFactory.Instance))); }
public void GeneratedSnippet_HaveInstallScript_IfCustomRequirementsTxtPathSpecified() { // Arrange var pythonScriptGeneratorOptions = new PythonScriptGeneratorOptions() { CustomRequirementsTxtPath = "foo/requirements.txt" }; var commonOptions = new BuildScriptGeneratorOptions() { EnableDynamicInstall = true, CustomRequirementsTxtPath = "foo/requirements.txt" }; var installerScriptSnippet = "##INSTALLER_SCRIPT##"; var versionProvider = new TestPythonVersionProvider(new[] { "3.7.5", "3.8.0" }, defaultVersion: "3.7.5"); var platformInstaller = new TestPythonPlatformInstaller( isVersionAlreadyInstalled: false, installerScript: installerScriptSnippet, Options.Create(commonOptions), NullLoggerFactory.Instance); var platform = CreatePlatform( versionProvider, platformInstaller, commonOptions, pythonScriptGeneratorOptions); var repo = new MemorySourceRepo(); repo.AddFile("", "foo/requirements.txt"); repo.AddFile("print(1)", "bla.py"); var context = new BuildScriptGeneratorContext { SourceRepo = repo }; var detectorResult = new PythonPlatformDetectorResult { Platform = PythonConstants.PlatformName, PlatformVersion = "3.7.5", HasRequirementsTxtFile = true, }; // Act var snippet = platform.GetInstallerScriptSnippet(context, detectorResult); // Assert Assert.NotNull(snippet); }
public void GeneratedSnippet_HasInstallationScript_IfDynamicInstallIsEnabled() { // Arrange var pythonScriptGeneratorOptions = new PythonScriptGeneratorOptions(); var commonOptions = new BuildScriptGeneratorOptions() { EnableDynamicInstall = true }; var installerScriptSnippet = "##INSTALLER_SCRIPT##"; var versionProvider = new TestPythonVersionProvider(new[] { "3.7.5", "3.8.0" }, defaultVersion: "3.7.5"); var platformInstaller = new TestPythonPlatformInstaller( isVersionAlreadyInstalled: false, installerScript: installerScriptSnippet, Options.Create(commonOptions), NullLoggerFactory.Instance); var platform = CreatePlatform( versionProvider, platformInstaller, commonOptions, pythonScriptGeneratorOptions); var repo = new MemorySourceRepo(); repo.AddFile("", PythonConstants.RequirementsFileName); repo.AddFile("print(1)", "bla.py"); var context = new BuildScriptGeneratorContext { SourceRepo = repo }; context.ResolvedPythonVersion = "3.7.5"; // Act var snippet = platform.GenerateBashBuildScriptSnippet(context); // Assert Assert.NotNull(snippet); Assert.NotNull(snippet.PlatformInstallationScriptSnippet); Assert.Equal(installerScriptSnippet, snippet.PlatformInstallationScriptSnippet); Assert.Contains(ManifestFilePropertyKeys.PythonVersion, snippet.BuildProperties.Keys); Assert.Equal("3.7.5", snippet.BuildProperties[ManifestFilePropertyKeys.PythonVersion]); }