From 1b2dae18e71e77a4ccc7c29c8215e6a4468dfce8 Mon Sep 17 00:00:00 2001 From: "Harish S. Kulkarni" Date: Fri, 7 Feb 2020 18:26:37 -0800 Subject: [PATCH] Fixed bug in tensorflow tests due to excessively long paths for working folders --- .../TensorflowTests.cs | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/test/Microsoft.ML.Tests/ScenariosWithDirectInstantiation/TensorflowTests.cs b/test/Microsoft.ML.Tests/ScenariosWithDirectInstantiation/TensorflowTests.cs index ab5d38a326..5b9022e1be 100644 --- a/test/Microsoft.ML.Tests/ScenariosWithDirectInstantiation/TensorflowTests.cs +++ b/test/Microsoft.ML.Tests/ScenariosWithDirectInstantiation/TensorflowTests.cs @@ -29,37 +29,33 @@ namespace Microsoft.ML.Scenarios internal sealed class TensorFlowScenariosTestsFixture : IDisposable { + public static string tempFolder; public static string parentWorkspacePath; public static string assetsPath; - internal void CreateParentWorkspacePathForImageClassification() + internal static void CreateParentWorkspacePathForImageClassification() { - string assetsRelativePath = @"assets"; - assetsPath = GetAbsolutePath(assetsRelativePath); - string workspacePath = Path.Combine(assetsPath, "cached"); + tempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); + assetsPath = Path.Combine(tempFolder, "assets"); + parentWorkspacePath = Path.Combine(assetsPath, "cached"); // Delete if the workspace path already exists - if (Directory.Exists(workspacePath)) + if (Directory.Exists(parentWorkspacePath)) { - Directory.Delete(workspacePath, true); + Directory.Delete(parentWorkspacePath, true); } // Create a new empty workspace path - Directory.CreateDirectory(workspacePath); - parentWorkspacePath = workspacePath; + Directory.CreateDirectory(parentWorkspacePath); } - public TensorFlowScenariosTestsFixture() + static TensorFlowScenariosTestsFixture() { CreateParentWorkspacePathForImageClassification(); } public void Dispose() { - // clean up test data + Directory.Delete(tempFolder, true); } - - public static string GetAbsolutePath(string relativePath) => - Path.Combine(new FileInfo(typeof( - TensorFlowScenariosTestsFixture).Assembly.Location).Directory.FullName, relativePath); } [Collection("NoParallelization")] @@ -1880,11 +1876,6 @@ private static void UnZip(String gzArchiveName, String destFolder) File.Create(Path.Combine(destFolder, flag)); } - public static string GetAbsolutePath(string relativePath) => - Path.Combine(new FileInfo(typeof( - TensorFlowScenariosTests).Assembly.Location).Directory.FullName, relativePath); - - public class ImageData { [LoadColumn(0)]