本文整理汇总了Python中cards.Deck.__exit__方法的典型用法代码示例。如果您正苦于以下问题:Python Deck.__exit__方法的具体用法?Python Deck.__exit__怎么用?Python Deck.__exit__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cards.Deck
的用法示例。
在下文中一共展示了Deck.__exit__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Test_context_manager
# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import __exit__ [as 别名]
class Test_context_manager(unittest.TestCase):
"""
Unit tests for Deck.__enter__() and __exit__()
"""
def setUp(self):
self.acquire_func = MockFunction()
self.release_func = MockFunction()
self.deck = Deck()
self.deck.lock.acquire = self.acquire_func
self.deck.lock.release = self.release_func
def test(self):
with self.deck as cm:
self.assertIs(cm, self.deck)
self.assertListEqual(self.acquire_func.invocations, [((), {})])
self.assertListEqual(self.release_func.invocations, [])
self.assertListEqual(self.acquire_func.invocations, [((), {})])
self.assertListEqual(self.release_func.invocations, [((), {})])
def test_enter(self):
result = self.deck.__enter__()
self.assertIs(result, self.deck)
self.assertListEqual(self.acquire_func.invocations, [((), {})])
def test_exit_noexception(self):
result = self.deck.__exit__(None, None, None)
self.assertIsNone(result)
self.assertListEqual(self.release_func.invocations, [((), {})])
def test_exit_exception(self):
try:
raise Exception()
except:
(exc_type, exc_value, traceback) = sys.exc_info()
result = self.deck.__exit__(exc_type, exc_value, traceback)
self.assertIsNone(result)
self.assertListEqual(self.release_func.invocations, [((), {})])