public void Detect_Throws_WhenUnsupportedPythonVersion_IsSetInOptions() { // Arrange var unsupportedVersion = "100.100.100"; var supportedVersion = "1.2.3"; var pythonScriptGeneratorOptions = new PythonScriptGeneratorOptions() { PythonVersion = unsupportedVersion }; var platform = CreatePlatform( supportedVersions: new[] { supportedVersion }, defaultVersion: supportedVersion, pythonScriptGeneratorOptions: pythonScriptGeneratorOptions); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "", PythonConstants.RequirementsFileName); IOHelpers.CreateFile(sourceDir, "python-" + supportedVersion, PythonConstants.RuntimeFileName); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act & Assert var exception = Assert.Throws <UnsupportedVersionException>(() => platform.Detect(context)); Assert.Equal( $"Platform 'python' version '{unsupportedVersion}' is unsupported. " + $"Supported versions: {supportedVersion}", exception.Message); }
public void Detect_ReturnsVersionFromRuntimeTextFile_IfEnvironmentVariableValueIsNotPresent() { // Arrange var expectedVersion = "2.5.0"; var environment = new TestEnvironment(); var detector = CreatePythonLanguageDetector( supportedPythonVersions: new[] { "100.100.100", expectedVersion, "1.2.3" }, defaultVersion: expectedVersion, environment); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "", PythonConstants.RequirementsFileName); IOHelpers.CreateFile(sourceDir, "", "app.py"); IOHelpers.CreateFile(sourceDir, $"python-{expectedVersion}", PythonConstants.RuntimeFileName); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert Assert.NotNull(result); Assert.Equal("python", result.Language); Assert.Equal(expectedVersion, result.LanguageVersion); }
public void Detect_ReturnsResult_WithAllPropertiesPopulatedWithExpectedInformation() { // Arrange var expectedPythonVersion = "3.5.6"; var detector = CreatePythonPlatformDetector(); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "channels:", PythonConstants.CondaEnvironmentYmlFileName); IOHelpers.CreateFile(sourceDir, "requirements.txt content", PythonConstants.RequirementsFileName); IOHelpers.CreateFile( sourceDir, "notebook content", $"notebook1.{PythonConstants.JupyterNotebookFileExtensionName}"); IOHelpers.CreateFile(sourceDir, $"python-{expectedPythonVersion}", PythonConstants.RuntimeFileName); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert var pythonPlatformResult = Assert.IsType <PythonPlatformDetectorResult>(result); Assert.Equal(PythonConstants.PlatformName, pythonPlatformResult.Platform); Assert.Equal(expectedPythonVersion, pythonPlatformResult.PlatformVersion); Assert.True(pythonPlatformResult.HasJupyterNotebookFiles); Assert.True(pythonPlatformResult.HasCondaEnvironmentYmlFile); }
public void Detect_ReutrnsResult_WhenNoPyFileExists_ButRuntimeTextFileExists_HavingPythonVersionInIt() { // Arrange var expectedVersion = "1000.1000.1000"; var defaultVersion = "1000.1000.1001"; var detector = CreatePythonPlatformDetector( supportedPythonVersions: new[] { defaultVersion, expectedVersion }, defaultVersion: defaultVersion, new PythonScriptGeneratorOptions()); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); // No file with a '.py' extension IOHelpers.CreateFile(sourceDir, "", PythonConstants.RequirementsFileName); IOHelpers.CreateFile(sourceDir, $"python-{expectedVersion}", "runtime.txt"); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert Assert.NotNull(result); Assert.Equal("python", result.Platform); Assert.Equal(expectedVersion, result.PlatformVersion); }
public void Detect_ReturnsVersionFromOptions_EvenIfRuntimeTextFileHasVersion() { // Arrange var expectedVersion = "1.2.3"; var runtimeTextFileVersion = "2.5.0"; var pythonScriptGeneratorOptions = new PythonScriptGeneratorOptions() { PythonVersion = expectedVersion }; var platform = CreatePlatform( supportedVersions: new[] { expectedVersion }, defaultVersion: expectedVersion, pythonScriptGeneratorOptions: pythonScriptGeneratorOptions); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "", "app.py"); IOHelpers.CreateFile(sourceDir, "", PythonConstants.RequirementsFileName); IOHelpers.CreateFile(sourceDir, $"python-{runtimeTextFileVersion}", PythonConstants.RuntimeFileName); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = platform.Detect(context); // Assert Assert.NotNull(result); Assert.Equal(PythonConstants.PlatformName, result.Platform); Assert.Equal(expectedVersion, result.PlatformVersion); }
public void Detect_ReturnsNull_WhenSourceDirectoryIsEmpty() { // Arrange var detector = CreatePythonLanguageDetector(supportedPythonVersions: new[] { Common.PythonVersions.Python37Version }); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); // No files in source directory var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); // Act var result = detector.Detect(repo); // Assert Assert.Null(result); }
public void Detect_ReutrnsNull_WhenRequirementsFileDoesNotExist() { // Arrange var detector = CreatePythonLanguageDetector(supportedPythonVersions: new[] { Common.PythonVersions.Python37Version }); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "foo.py content", "foo.py"); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); // Act var result = detector.Detect(repo); // Assert Assert.Null(result); }
public void Detect_ReturnsNull_WhenSourceDirectoryIsEmpty() { // Arrange var detector = CreatePythonPlatformDetector(); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); // No files in source directory var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert Assert.Null(result); }
public void Detect_ReturnsNull_WhenRequirementsFileDoesNotExist() { // Arrange var detector = CreatePythonPlatformDetector(); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "foo.py content", "foo.py"); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert Assert.Null(result); }
public void Detect_ReturnsFalse_WhenValidCondaEnvironmentFileDoesNotExist(string environmentFileName) { // Arrange var detector = CreatePythonPlatformDetector(); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "foo:", environmentFileName); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert Assert.Null(result); }
public void Detect_ReutrnsNull_WhenRequirementsTextFileExists_ButNoPyOrRuntimeFileExists() { // Arrange var detector = CreatePythonLanguageDetector(supportedPythonVersions: new[] { Common.PythonVersions.Python37Version }); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); // No files with '.py' or no runtime.txt file IOHelpers.CreateFile(sourceDir, "requirements.txt content", PythonConstants.RequirementsFileName); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); // Act var result = detector.Detect(repo); // Assert Assert.Null(result); }
public void Detect_ReturnsNull_ForMalformedCondaYamlFiles(string environmentFileName) { // Arrange var detector = CreatePythonPlatformDetector(); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "\"invalid text", environmentFileName); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert Assert.Null(result); }
public void Detect_ReutrnsNull_WhenRuntimeTextFileExists_ButDoesNotTextInExpectedFormat(string fileContent) { // Arrange var detector = CreatePythonLanguageDetector(supportedPythonVersions: new[] { Common.PythonVersions.Python37Version }); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "", PythonConstants.RequirementsFileName); IOHelpers.CreateFile(sourceDir, fileContent, "runtime.txt"); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); // Act var result = detector.Detect(repo); // Assert Assert.Null(result); }
public void Detect_ReturnsNull_WhenRuntimeTextFileExists_ButDoesNotTextInExpectedFormat(string fileContent) { // Arrange var detector = CreatePythonPlatformDetector(); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "", PythonConstants.RequirementsFileName); IOHelpers.CreateFile(sourceDir, fileContent, "runtime.txt"); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert Assert.Null(result); }
public void Detect_ReturnsNull_WhenRequirementsTextFileExists_ButNoPyOrRuntimeFileExists() { // Arrange var detector = CreatePythonPlatformDetector(); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); // No files with '.py' or no runtime.txt file IOHelpers.CreateFile(sourceDir, "requirements.txt content", PythonConstants.RequirementsFileName); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert Assert.Null(result); }
public void Detect_Throws_WhenUnsupportedPythonVersion_FoundInRuntimeFile() { // Arrange var detector = CreatePythonLanguageDetector(supportedPythonVersions: new[] { Common.PythonVersions.Python37Version }); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "", PythonConstants.RequirementsFileName); IOHelpers.CreateFile(sourceDir, "python-100.100.100", PythonConstants.RuntimeFileName); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); // Act & Assert var exception = Assert.Throws <UnsupportedVersionException>(() => detector.Detect(repo)); Assert.Equal( $"Target Python version '100.100.100' is unsupported. Supported versions are: {Common.PythonVersions.Python37Version}", exception.Message); }
public void Detect_ReturnsNull_WhenSourceDirectoryIsEmpty() { // Arrange var version = "100.100.100"; var detector = CreatePythonLanguageDetector( supportedPythonVersions: new[] { version }, defaultVersion: version); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); // No files in source directory var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert Assert.Null(result); }
public void Detect_ReturnsResult_WithPythonDefaultVersion_WhenNoRuntimeTextFileExists() { // Arrange var detector = CreatePythonLanguageDetector(supportedPythonVersions: new[] { Common.PythonVersions.Python37Version }); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "content", PythonConstants.RequirementsFileName); IOHelpers.CreateFile(sourceDir, "foo.py content", "foo.py"); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); // Act var result = detector.Detect(repo); // Assert Assert.NotNull(result); Assert.Equal("python", result.Language); Assert.Equal(Common.PythonVersions.Python37Version, result.LanguageVersion); }
public void Detect_ReutrnsNull_WhenOnlyRuntimeTextFileExists_ButDoesNotHaveTextInExpectedFormat( string fileContent) { // Arrange var detector = CreatePythonPlatformDetector(new PythonScriptGeneratorOptions()); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); // No files with '.py' or no requirements.txt file IOHelpers.CreateFile(sourceDir, fileContent, PythonConstants.RuntimeFileName); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert Assert.Null(result); }
public void Detect_ReutrnsResult_WhenRequirementsFileDoesNotExist_ButDotPyFilesExist() { // Arrange var detector = CreatePythonPlatformDetector(new PythonScriptGeneratorOptions()); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "foo.py content", "foo.py"); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert Assert.NotNull(result); Assert.Equal(PythonConstants.PlatformName, result.Platform); Assert.Null(result.PlatformVersion); }
public void Detect_ReutrnsResult_WhenOnlyRequirementsTextFileExists_ButNoPyOrRuntimeFileExists() { // Arrange var detector = CreatePythonPlatformDetector(new PythonScriptGeneratorOptions()); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); // No files with '.py' or no runtime.txt file IOHelpers.CreateFile(sourceDir, "requirements.txt content", PythonConstants.RequirementsFileName); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert Assert.NotNull(result); Assert.Equal(PythonConstants.PlatformName, result.Platform); Assert.Null(result.PlatformVersion); }
public void Detect_ReutrnsResult_WhenNoPyFileExists_ButRuntimeTextFileExists_HavingPythonVersionInIt() { // Arrange var detector = CreatePythonLanguageDetector(supportedPythonVersions: new[] { Common.PythonVersions.Python37Version }); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); // No file with a '.py' extension IOHelpers.CreateFile(sourceDir, "", PythonConstants.RequirementsFileName); IOHelpers.CreateFile(sourceDir, $"python-{Common.PythonVersions.Python37Version}", "runtime.txt"); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); // Act var result = detector.Detect(repo); // Assert Assert.NotNull(result); Assert.Equal("python", result.Language); Assert.Equal(Common.PythonVersions.Python37Version, result.LanguageVersion); }
public void Detect_ReturnsNullVersion_IfNoVersionFoundFromApp_OrOptions() { // Arrange var detector = CreatePythonPlatformDetector(); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "", PythonConstants.RequirementsFileName); IOHelpers.CreateFile(sourceDir, "", "app.py"); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert Assert.NotNull(result); Assert.Equal("python", result.Platform); Assert.Null(result.PlatformVersion); }
public void Detect_ReturnsDefaultVersion_IfNoVersionFoundFromApp_OrOptions() { // Arrange var expectedVersion = "1.2.3"; var platform = CreatePlatform(defaultVersion: expectedVersion); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "", PythonConstants.RequirementsFileName); IOHelpers.CreateFile(sourceDir, "", "app.py"); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = platform.Detect(context); // Assert Assert.NotNull(result); Assert.Equal(PythonConstants.PlatformName, result.Platform); Assert.Equal(expectedVersion, result.PlatformVersion); }
public void Detect_ReturnsVersionFromRuntimeTextFile(string expectedVersion) { // Arrange var detector = CreatePythonPlatformDetector(); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "", PythonConstants.RequirementsFileName); IOHelpers.CreateFile(sourceDir, "", "app.py"); IOHelpers.CreateFile(sourceDir, $"python-{expectedVersion}", PythonConstants.RuntimeFileName); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert Assert.NotNull(result); Assert.Equal(PythonConstants.PlatformName, result.Platform); Assert.Equal(expectedVersion, result.PlatformVersion); }
public void Detect_ReturnsResult_WithPythonDefaultVersion_WhenNoRuntimeTextFileExists() { // Arrange var expectedVersion = "1.2.3"; var platform = CreatePlatform(defaultVersion: expectedVersion); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "content", PythonConstants.RequirementsFileName); IOHelpers.CreateFile(sourceDir, "foo.py content", "foo.py"); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = platform.Detect(context); // Assert Assert.NotNull(result); Assert.Equal(PythonConstants.PlatformName, result.Platform); Assert.Equal(expectedVersion, result.PlatformVersion); }
public void Detect_ReutrnsNull_WhenRequirementsFileDoesNotExist() { // Arrange var version = "100.100.100"; var detector = CreatePythonPlatformDetector( supportedPythonVersions: new[] { version }, defaultVersion: version, new PythonScriptGeneratorOptions()); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "foo.py content", "foo.py"); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert Assert.Null(result); }
public void Detect_ReutrnsNull_WhenRequirementsTextFileExists_ButNoPyOrRuntimeFileExists() { // Arrange var version = "100.100.100"; var detector = CreatePythonPlatformDetector( supportedPythonVersions: new[] { version }, defaultVersion: version, new PythonScriptGeneratorOptions()); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); // No files with '.py' or no runtime.txt file IOHelpers.CreateFile(sourceDir, "requirements.txt content", PythonConstants.RequirementsFileName); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert Assert.Null(result); }
public void Detect_ReturnsResult_WhenValidCondaEnvironmentFileExists(string environmentFileName) { // Arrange var detector = CreatePythonPlatformDetector(); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "channels:", environmentFileName); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert var pythonPlatformResult = Assert.IsType <PythonPlatformDetectorResult>(result); Assert.Equal(PythonConstants.PlatformName, pythonPlatformResult.Platform); Assert.Null(pythonPlatformResult.PlatformVersion); Assert.False(pythonPlatformResult.HasJupyterNotebookFiles); Assert.True(pythonPlatformResult.HasCondaEnvironmentYmlFile); }
public void Detect_ReutrnsNull_WhenRuntimeTextFileExists_ButDoesNotTextInExpectedFormat(string fileContent) { // Arrange var supportedVersion = "1.2.3"; var detector = CreatePythonPlatformDetector( supportedPythonVersions: new[] { supportedVersion }, defaultVersion: supportedVersion, new PythonScriptGeneratorOptions()); var sourceDir = IOHelpers.CreateTempDir(_tempDirRoot); IOHelpers.CreateFile(sourceDir, "", PythonConstants.RequirementsFileName); IOHelpers.CreateFile(sourceDir, fileContent, "runtime.txt"); var repo = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance); var context = CreateContext(repo); // Act var result = detector.Detect(context); // Assert Assert.Null(result); }