Skip to content

Commit

Permalink
Full coverage for '_add_classic_mro'.
Browse files Browse the repository at this point in the history
Brings coverage to 100%.
  • Loading branch information
tseaver committed Oct 1, 2016
1 parent 14f5aa9 commit 0595d8b
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/ExtensionClass/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#
##############################################################################

import sys

from ExtensionClass import *
from doctest import DocTestSuite
import unittest
Expand Down Expand Up @@ -916,6 +918,65 @@ class WithBaseAndNoAttributes(Base, NoAttributes):
# Therefore, we don't get AttributeError, we get our defined exception
self.assertRaises(YouShallNotPass, getattr, WithBaseAndNoAttributes(), 'a')

class Test_add_classic_mro(unittest.TestCase):

def _callFUT(self, mro, cls):
from ExtensionClass import _add_classic_mro as FUT
return FUT(mro, cls)

def test_w_empty_mro_newstyle_class_no_bases(self):

class _Class(object):
pass

mro = []
self._callFUT(mro, _Class)
self.assertEqual(mro, [_Class, object])

def test_w_empty_mro_newstyle_class_w_bases(self):

class _Base(object):
pass

class _Derived(_Base):
pass

mro = []
self._callFUT(mro, _Derived)
self.assertEqual(mro, [_Derived, _Base, object])

def test_w_empty_mro_newstyle_class_w_diamond_inheritance(self):

class _Base(object):
pass

class _One(_Base):
pass

class _Another(_Base):
pass

class _Derived(_One, _Another):
pass

mro = []
self._callFUT(mro, _Derived)
self.assertEqual(mro, [_Derived, _One, _Base, object, _Another])

@unittest.skipIf(sys.version_info[0] > 2, 'Py3k: no classic classes')
def test_w_filled_mro_oldstyle_class_w_bases(self):

class _Base:
pass

class _Derived(_Base):
pass

already = object()
mro = [already]
self._callFUT(mro, _Derived)
self.assertEqual(mro, [already, _Derived, _Base])

def test_suite():
return unittest.TestSuite((
DocTestSuite('ExtensionClass'),
Expand Down

0 comments on commit 0595d8b

Please sign in to comment.