From 611858f4cda3574c9da292a31d16ab76b4d06417 Mon Sep 17 00:00:00 2001 From: Veikko Eeva Date: Fri, 1 Jun 2018 21:03:47 +0300 Subject: [PATCH] Fixes locale dependent test output comparisons The tests do not pass on systems with locale other than en-US. The error happens since the results are written to files and the contents of the files are compared to set of correct results produced under en-US locale. The fix is to imbue en-US culture to the test thread so that results will be output in format that is comparable with the test format. This patch fixes only tests, but do not guarantee calculation will be correct in production systems using a locale different than en-US. In particular, there can be problems in reading data and then conversing data from characters to numeric format. Fixes #74 --- test/Microsoft.ML.TestFramework/BaseTestClass.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/Microsoft.ML.TestFramework/BaseTestClass.cs b/test/Microsoft.ML.TestFramework/BaseTestClass.cs index cb5781f25c..b5d7a23db3 100644 --- a/test/Microsoft.ML.TestFramework/BaseTestClass.cs +++ b/test/Microsoft.ML.TestFramework/BaseTestClass.cs @@ -3,7 +3,9 @@ // See the LICENSE file in the project root for more information. using Microsoft.ML.Runtime.Internal.Internallearn.Test; +using System.Globalization; using System.IO; +using System.Threading; using Xunit.Abstractions; namespace Microsoft.ML.TestFramework @@ -18,6 +20,11 @@ public class BaseTestClass public BaseTestClass(ITestOutputHelper output) { + //This locale is currently set for tests only so that the produced output + //files can be compared on systems with other locales to give set of known + //correct results that are on en-US locale. + Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); + var currentAssemblyLocation = new FileInfo(typeof(BaseTestClass).Assembly.Location); _rootDir = currentAssemblyLocation.Directory.Parent.Parent.Parent.Parent.FullName; _outDir = Path.Combine(currentAssemblyLocation.Directory.FullName, "TestOutput");