Skip to content

Commit

Permalink
Upgrade the NUnit test adapter (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreeve authored Sep 12, 2023
1 parent 4fdc979 commit 24f2aa9
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 97 deletions.
2 changes: 1 addition & 1 deletion csharp.test/ParquetSharp.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Parquet.Net" Version="3.8.6" />
</ItemGroup>

Expand Down
44 changes: 25 additions & 19 deletions csharp.test/TestColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,35 @@ public static void TestPrimitives()
{
foreach (var expected in expectedPrimitives)
{
Console.WriteLine("Testing primitive type {0}", expected.Type);
try
{
Assert.True(LogicalTypeFactory.Default.IsSupported(expected.Type));
var type = expected.Type;
var column = new Column(type, expected.Name, expected.LogicalTypeOverride);

Assert.True(LogicalTypeFactory.Default.IsSupported(expected.Type));
var type = expected.Type;
var column = new Column(type, expected.Name, expected.LogicalTypeOverride);
using var node = column.CreateSchemaNode();

using var node = column.CreateSchemaNode();
using var nodeLogicalType = node.LogicalType;
Assert.AreEqual(expected.LogicalType, nodeLogicalType);
Assert.AreEqual(-1, node.FieldId);
Assert.AreEqual(expected.Name, node.Name);
Assert.AreEqual(NodeType.Primitive, node.NodeType);
Assert.AreEqual(null, node.Parent);
Assert.AreEqual(expected.Repetition, node.Repetition);

using var nodeLogicalType = node.LogicalType;
Assert.AreEqual(expected.LogicalType, nodeLogicalType);
Assert.AreEqual(-1, node.FieldId);
Assert.AreEqual(expected.Name, node.Name);
Assert.AreEqual(NodeType.Primitive, node.NodeType);
Assert.AreEqual(null, node.Parent);
Assert.AreEqual(expected.Repetition, node.Repetition);
var primitive = (PrimitiveNode) node;

var primitive = (PrimitiveNode) node;

Assert.AreEqual(expected.ColumnOrder, primitive.ColumnOrder);
Assert.AreEqual(expected.PhysicalType, primitive.PhysicalType);
Assert.AreEqual(expected.Length, primitive.TypeLength);
using var logicalType = primitive.LogicalType;
Assert.AreEqual(expected.LogicalType, logicalType);
Assert.AreEqual(expected.ColumnOrder, primitive.ColumnOrder);
Assert.AreEqual(expected.PhysicalType, primitive.PhysicalType);
Assert.AreEqual(expected.Length, primitive.TypeLength);
using var logicalType = primitive.LogicalType;
Assert.AreEqual(expected.LogicalType, logicalType);
}
catch (Exception)
{
TestContext.Out.WriteLine("Failure testing primitive type {0}", expected.Type);
throw;
}
}
}
finally
Expand Down
6 changes: 2 additions & 4 deletions csharp.test/TestDecimal128.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ public static void TestRoundTrip(int scale)

foreach (var value in decimals)
{
Console.WriteLine($"{value:E}");
Assert.AreEqual(value, new Decimal128(value, multiplier).ToDecimal(multiplier));
Assert.That(value, Is.EqualTo(new Decimal128(value, multiplier).ToDecimal(multiplier)));

Console.WriteLine($"{-value:E}");
Assert.AreEqual(-value, new Decimal128(-value, multiplier).ToDecimal(multiplier));
Assert.That(-value, Is.EqualTo(new Decimal128(-value, multiplier).ToDecimal(multiplier)));
}
}

Expand Down
80 changes: 44 additions & 36 deletions csharp.test/TestLogicalTypeRoundtrip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,21 @@ public static void TestRoundTrip(

foreach (var column in expectedColumns)
{
Console.WriteLine("Writing '{0}' ({1})", column.Name, column.Values.GetType().GetElementType());

using var columnWriter = rowGroupWriter.NextColumn().LogicalWriter(writeBufferLength);
columnWriter.Apply(new LogicalValueSetter(column.Values, rowsPerBatch));
try
{
using var columnWriter = rowGroupWriter.NextColumn().LogicalWriter(writeBufferLength);
columnWriter.Apply(new LogicalValueSetter(column.Values, rowsPerBatch));
}
catch (Exception)
{
TestContext.Out.WriteLine("Failure writing '{0}' ({1})", column.Name, column.Values.GetType().GetElementType());
throw;
}
}

fileWriter.Close();
}

Console.WriteLine();

// Read back the columns and make sure they match.
AssertReadRoundtrip(rowsPerBatch, readBufferLength, buffer, expectedColumns);
}
Expand Down Expand Up @@ -94,8 +98,6 @@ public static void TestRoundTripBuffered(
var column = expectedColumns[i];
var range = (r, Math.Min(r + rangeLength, NumRows));

Console.WriteLine("Writing '{0}' (element type: {1}) (range: {2})", column.Name, column.Values.GetType().GetElementType(), range);

using var columnWriter = rowGroupWriter.Column(i).LogicalWriter(writeBufferLength);
columnWriter.Apply(new LogicalValueSetter(column.Values, rowsPerBatch, range));
}
Expand All @@ -104,8 +106,6 @@ public static void TestRoundTripBuffered(
fileWriter.Close();
}

Console.WriteLine();

// Read back the columns and make sure they match.
AssertReadRoundtrip(rowsPerBatch, readBufferLength, buffer, expectedColumns);
}
Expand Down Expand Up @@ -295,38 +295,46 @@ private static void AssertReadRoundtrip(int rowsPerBatch, int readBufferLength,
using var chunkMetaData = rowGroupMetaData.GetColumnChunkMetaData(c);
using var statistics = chunkMetaData.Statistics;

Console.WriteLine("Reading '{0}'", expected.Name);

using var root = fileMetaData.Schema.ColumnRoot(c);
Assert.AreEqual(expected.Name, root.Name);
using var path = descr.Path;
Assert.AreEqual(expected.Name, path.ToDotVector().First());
Assert.AreEqual(c, fileMetaData.Schema.ColumnIndex(path.ToDotString()));
Assert.AreEqual(expected.PhysicalType, descr.PhysicalType);
using var logicalType = descr.LogicalType;
Assert.AreEqual(expected.LogicalType, logicalType);
Assert.AreEqual(expected.Values, columnReader.Apply(new LogicalValueGetter(checked((int) numRows), rowsPerBatch)));
Assert.AreEqual(expected.Length, descr.TypeLength);
Assert.AreEqual((expected.LogicalType as DecimalLogicalType)?.Precision ?? -1, descr.TypePrecision);
Assert.AreEqual((expected.LogicalType as DecimalLogicalType)?.Scale ?? -1, descr.TypeScale);
Assert.AreEqual(expected.HasStatistics, chunkMetaData.IsStatsSet);

if (expected.HasStatistics)
try
{
Assert.AreEqual(expected.HasMinMax, statistics?.HasMinMax);
Assert.AreEqual(expected.NullCount, statistics?.NullCount);
Assert.AreEqual(expected.NumValues, statistics?.NumValues);
Assert.AreEqual(expected.PhysicalType, statistics?.PhysicalType);
using var root = fileMetaData.Schema.ColumnRoot(c);
Assert.AreEqual(expected.Name, root.Name);
using var path = descr.Path;
Assert.AreEqual(expected.Name, path.ToDotVector().First());
Assert.AreEqual(c, fileMetaData.Schema.ColumnIndex(path.ToDotString()));
Assert.AreEqual(expected.PhysicalType, descr.PhysicalType);
using var logicalType = descr.LogicalType;
Assert.AreEqual(expected.LogicalType, logicalType);
Assert.AreEqual(expected.Values,
columnReader.Apply(new LogicalValueGetter(checked((int) numRows), rowsPerBatch)));
Assert.AreEqual(expected.Length, descr.TypeLength);
Assert.AreEqual((expected.LogicalType as DecimalLogicalType)?.Precision ?? -1,
descr.TypePrecision);
Assert.AreEqual((expected.LogicalType as DecimalLogicalType)?.Scale ?? -1, descr.TypeScale);
Assert.AreEqual(expected.HasStatistics, chunkMetaData.IsStatsSet);

if (expected.HasStatistics)
{
Assert.AreEqual(expected.HasMinMax, statistics?.HasMinMax);
Assert.AreEqual(expected.NullCount, statistics?.NullCount);
Assert.AreEqual(expected.NumValues, statistics?.NumValues);
Assert.AreEqual(expected.PhysicalType, statistics?.PhysicalType);

if (expected.HasMinMax)
if (expected.HasMinMax)
{
Assert.AreEqual(expected.Min, expected.Converter(statistics!.MinUntyped, descr));
Assert.AreEqual(expected.Max, expected.Converter(statistics!.MaxUntyped, descr));
}
}
else
{
Assert.AreEqual(expected.Min, expected.Converter(statistics!.MinUntyped, descr));
Assert.AreEqual(expected.Max, expected.Converter(statistics!.MaxUntyped, descr));
Assert.IsNull(statistics);
}
}
else
catch (Exception)
{
Assert.IsNull(statistics);
TestContext.Out.WriteLine("Failure reading '{0}'", expected.Name);
throw;
}
}

Expand Down
78 changes: 42 additions & 36 deletions csharp.test/TestPhysicalTypeRoundtrip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,16 @@ private static void TestRoundTrip(ExpectedColumn[] expectedColumns, bool useDict

foreach (var column in expectedColumns)
{
Console.WriteLine("Writing '{0}'", column.Name);

using var columnWriter = rowGroupWriter.NextColumn();
columnWriter.Apply(new ValueSetter(column.Values));
try
{
using var columnWriter = rowGroupWriter.NextColumn();
columnWriter.Apply(new ValueSetter(column.Values));
}
catch (Exception)
{
TestContext.WriteLine("Failure writing '{0}'", column.Name);
throw;
}
}

fileWriter.Close();
Expand Down Expand Up @@ -137,11 +143,6 @@ private static void TestRoundTripBuffered(ExpectedColumn[] expectedColumns, bool
var column = expectedColumns[i];
var range = (r, Math.Min(r + rangeLength, numRows));

if (range.Item1 == 0 || range.Item2 == numRows)
{
Console.WriteLine("Writing '{0}' (range: {1})", column.Name, range);
}

using var columnWriter = rowGroupWriter.Column(i);
columnWriter.Apply(new ValueSetter(column.Values, range));
}
Expand Down Expand Up @@ -181,34 +182,39 @@ private static void AssertReadRoundtrip(ResizableBuffer buffer, ExpectedColumn[]
for (int c = 0; c != fileMetaData.NumColumns; ++c)
{
using var columnReader = rowGroupReader.Column(c);

var expected = expectedColumns[c];

Console.WriteLine("Reading '{0}'", expected.Name);

var descr = columnReader.ColumnDescriptor;
using var chunkMetaData = rowGroupMetaData.GetColumnChunkMetaData(c);

Assert.AreEqual(expected.MaxDefinitionlevel, descr.MaxDefinitionLevel);
Assert.AreEqual(expected.MaxRepetitionLevel, descr.MaxRepetitionLevel);
Assert.AreEqual(expected.PhysicalType, descr.PhysicalType);
using var logicalType = descr.LogicalType;
Assert.AreEqual(expected.LogicalType, logicalType);
Assert.AreEqual(expected.ColumnOrder, descr.ColumnOrder);
Assert.AreEqual(expected.SortOrder, descr.SortOrder);
Assert.AreEqual(expected.Name, descr.Name);
Assert.AreEqual(expected.TypeLength, descr.TypeLength);
Assert.AreEqual(expected.TypePrecision, descr.TypePrecision);
Assert.AreEqual(expected.TypeScale, descr.TypeScale);

var expectedEncodings = expected.Encodings
.Where(e => useDictionaryEncoding || e != Encoding.RleDictionary).ToArray();
var actualEncodings = chunkMetaData.Encodings.Distinct().ToArray();
// Encoding ordering is not important
Assert.That(actualEncodings, Is.EquivalentTo(expectedEncodings));

Assert.AreEqual(expected.Compression, chunkMetaData.Compression);
Assert.AreEqual(expected.Values, columnReader.Apply(new PhysicalValueGetter(chunkMetaData.NumValues)).values);
try
{
var descr = columnReader.ColumnDescriptor;
using var chunkMetaData = rowGroupMetaData.GetColumnChunkMetaData(c);

Assert.AreEqual(expected.MaxDefinitionlevel, descr.MaxDefinitionLevel);
Assert.AreEqual(expected.MaxRepetitionLevel, descr.MaxRepetitionLevel);
Assert.AreEqual(expected.PhysicalType, descr.PhysicalType);
using var logicalType = descr.LogicalType;
Assert.AreEqual(expected.LogicalType, logicalType);
Assert.AreEqual(expected.ColumnOrder, descr.ColumnOrder);
Assert.AreEqual(expected.SortOrder, descr.SortOrder);
Assert.AreEqual(expected.Name, descr.Name);
Assert.AreEqual(expected.TypeLength, descr.TypeLength);
Assert.AreEqual(expected.TypePrecision, descr.TypePrecision);
Assert.AreEqual(expected.TypeScale, descr.TypeScale);

var expectedEncodings = expected.Encodings
.Where(e => useDictionaryEncoding || e != Encoding.RleDictionary).ToArray();
var actualEncodings = chunkMetaData.Encodings.Distinct().ToArray();
// Encoding ordering is not important
Assert.That(actualEncodings, Is.EquivalentTo(expectedEncodings));

Assert.AreEqual(expected.Compression, chunkMetaData.Compression);
Assert.AreEqual(expected.Values,
columnReader.Apply(new PhysicalValueGetter(chunkMetaData.NumValues)).values);
}
catch (Exception)
{
TestContext.Out.WriteLine("Failure reading '{0}'", expected.Name);
throw;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion fsharp.test/ParquetSharp.Test.FSharp.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="FsUnit" Version="5.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 24f2aa9

Please sign in to comment.