Skip to content

Commit

Permalink
Fixes locale dependent test output comparisons
Browse files Browse the repository at this point in the history
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 dotnet#74
  • Loading branch information
veikkoeeva committed Jun 1, 2018
1 parent fb06f38 commit 611858f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/Microsoft.ML.TestFramework/BaseTestClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");
Expand Down

0 comments on commit 611858f

Please sign in to comment.