Skip to content

Commit 2fff248

Browse files
committed
Add unit test
1 parent 0195e20 commit 2fff248

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/testing/InheritanceTest.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace Python.Test
4+
{
5+
public class BaseClass
6+
{
7+
public bool IsBase() => true;
8+
}
9+
10+
public class DerivedClass : BaseClass
11+
{
12+
public new bool IsBase() => false;
13+
}
14+
}

src/testing/Python.Test.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -83,6 +83,7 @@
8383
<Compile Include="generictest.cs" />
8484
<Compile Include="globaltest.cs" />
8585
<Compile Include="indexertest.cs" />
86+
<Compile Include="InheritanceTest.cs" />
8687
<Compile Include="interfacetest.cs" />
8788
<Compile Include="methodtest.cs" />
8889
<Compile Include="moduletest.cs" />
@@ -110,4 +111,4 @@
110111
<Copy SourceFiles="$(TargetAssembly)" DestinationFolder="$(SolutionDir)\src\tests\fixtures" />
111112
<!--Copy SourceFiles="$(TargetAssemblyPdb)" Condition="Exists('$(TargetAssemblyPdb)')" DestinationFolder="$(PythonBuildDir)" /-->
112113
</Target>
113-
</Project>
114+
</Project>

src/tests/test_class.py

+11
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,14 @@ def PyCallback(self, self2):
281281
testobj.DoCallback()
282282
assert testobj.PyCallbackWasCalled
283283
assert testobj.SameReference
284+
285+
286+
def test_method_inheritance():
287+
"""Ensure that we call the overridden method instead of the one provided in
288+
the base class."""
289+
290+
base = Test.BaseClass()
291+
derived = Test.DerivedClass()
292+
293+
assert base.IsBase() == True
294+
assert derived.IsBase() == False

0 commit comments

Comments
 (0)