fix MRO for multimethod.__call__ using iterative algorithm.
Add tests MRO for inherited multimethods with multiple inheritance Add tests for inherited and overridden multimethods
This commit is contained in:

committed by
Greg Becker

parent
43d94d4a30
commit
2621af41d1
@@ -19,3 +19,6 @@ class when subclass multi-methods do not match.
|
||||
|
||||
def base_method(self):
|
||||
return "base_method"
|
||||
|
||||
def diamond_inheritance(self):
|
||||
return "base_package"
|
||||
|
@@ -0,0 +1,21 @@
|
||||
# Copyright 2013-2018 Lawrence Livermore National Security, LLC and other
|
||||
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
||||
#
|
||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||
|
||||
from spack.pkg.builtin.mock.multimethod_base import MultimethodBase
|
||||
|
||||
|
||||
class MultimethodDiamondParent(MultimethodBase):
|
||||
"""This package is designed for use with Spack's multimethod test.
|
||||
It has a bunch of test cases for the @when decorator that the
|
||||
test uses.
|
||||
"""
|
||||
|
||||
@when('@3.0')
|
||||
def diamond_inheritance(self):
|
||||
return "second_parent"
|
||||
|
||||
@when('@4.0, 2.0')
|
||||
def diamond_inheritance(self):
|
||||
return "should never be reached"
|
@@ -0,0 +1,18 @@
|
||||
# Copyright 2013-2018 Lawrence Livermore National Security, LLC and other
|
||||
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
||||
#
|
||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||
|
||||
import spack.pkg.builtin.mock.multimethod_inheritor as mi
|
||||
import spack.pkg.builtin.mock.multimethod_diamond_parent as mp
|
||||
|
||||
|
||||
class MultimethodDiamond(mi.MultimethodInheritor, mp.MultimethodDiamondParent):
|
||||
"""This package is designed for use with Spack's multimethod test.
|
||||
It has a bunch of test cases for the @when decorator that the
|
||||
test uses.
|
||||
"""
|
||||
|
||||
@when('@4.0')
|
||||
def diamond_inheritance(self):
|
||||
return 'subclass'
|
@@ -11,3 +11,14 @@ class MultimethodInheritor(Multimethod):
|
||||
It has a bunch of test cases for the @when decorator that the
|
||||
test uses.
|
||||
"""
|
||||
|
||||
@when('@1.0')
|
||||
def inherited_and_overridden(self):
|
||||
return "inheritor@1.0"
|
||||
|
||||
#
|
||||
# Test multi-level inheritance
|
||||
#
|
||||
@when('@2:')
|
||||
def base_method(self):
|
||||
return 'multimethod-inheritor'
|
||||
|
@@ -124,4 +124,28 @@ def different_by_virtual_dep(self):
|
||||
#
|
||||
@when("@2:")
|
||||
def base_method(self):
|
||||
return "subclass_method"
|
||||
return 'multimethod'
|
||||
|
||||
#
|
||||
# Make sure methods with non-default implementations in a superclass
|
||||
# will invoke those methods when none in the subclass match but one in
|
||||
# the superclass does.
|
||||
#
|
||||
@when("@1.0")
|
||||
def inherited_and_overridden(self):
|
||||
return "base@1.0"
|
||||
|
||||
@when("@2.0")
|
||||
def inherited_and_overridden(self):
|
||||
return "base@2.0"
|
||||
|
||||
#
|
||||
# Make sure that multimethods follow MRO properly with diamond inheritance
|
||||
#
|
||||
@when('@2.0')
|
||||
def diamond_inheritance(self):
|
||||
return 'first_parent'
|
||||
|
||||
@when('@4.0')
|
||||
def diamond_inheritance(self):
|
||||
return "should_not_be_reached"
|
||||
|
Reference in New Issue
Block a user