Skip to content

Commit c9d950e

Browse files
authored
Fixed bug in tensorflow tests due to excessively long paths for working folders (#4816)
1 parent 35504fd commit c9d950e

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

test/Microsoft.ML.Tests/ScenariosWithDirectInstantiation/TensorflowTests.cs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,33 @@ namespace Microsoft.ML.Scenarios
2929

3030
internal sealed class TensorFlowScenariosTestsFixture : IDisposable
3131
{
32+
public static string tempFolder;
3233
public static string parentWorkspacePath;
3334
public static string assetsPath;
34-
internal void CreateParentWorkspacePathForImageClassification()
35+
internal static void CreateParentWorkspacePathForImageClassification()
3536
{
36-
string assetsRelativePath = @"assets";
37-
assetsPath = GetAbsolutePath(assetsRelativePath);
38-
string workspacePath = Path.Combine(assetsPath, "cached");
37+
tempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
38+
assetsPath = Path.Combine(tempFolder, "assets");
39+
parentWorkspacePath = Path.Combine(assetsPath, "cached");
3940
// Delete if the workspace path already exists
40-
if (Directory.Exists(workspacePath))
41+
if (Directory.Exists(parentWorkspacePath))
4142
{
42-
Directory.Delete(workspacePath, true);
43+
Directory.Delete(parentWorkspacePath, true);
4344
}
4445

4546
// Create a new empty workspace path
46-
Directory.CreateDirectory(workspacePath);
47-
parentWorkspacePath = workspacePath;
47+
Directory.CreateDirectory(parentWorkspacePath);
4848
}
4949

50-
public TensorFlowScenariosTestsFixture()
50+
static TensorFlowScenariosTestsFixture()
5151
{
5252
CreateParentWorkspacePathForImageClassification();
5353
}
5454

5555
public void Dispose()
5656
{
57-
// clean up test data
57+
Directory.Delete(tempFolder, true);
5858
}
59-
60-
public static string GetAbsolutePath(string relativePath) =>
61-
Path.Combine(new FileInfo(typeof(
62-
TensorFlowScenariosTestsFixture).Assembly.Location).Directory.FullName, relativePath);
6359
}
6460

6561
[Collection("NoParallelization")]
@@ -1880,11 +1876,6 @@ private static void UnZip(String gzArchiveName, String destFolder)
18801876
File.Create(Path.Combine(destFolder, flag));
18811877
}
18821878

1883-
public static string GetAbsolutePath(string relativePath) =>
1884-
Path.Combine(new FileInfo(typeof(
1885-
TensorFlowScenariosTests).Assembly.Location).Directory.FullName, relativePath);
1886-
1887-
18881879
public class ImageData
18891880
{
18901881
[LoadColumn(0)]

0 commit comments

Comments
 (0)