本文整理汇总了Python中models.match.Match.to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Match.to_dict方法的具体用法?Python Match.to_dict怎么用?Python Match.to_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.match.Match
的用法示例。
在下文中一共展示了Match.to_dict方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MatchTest
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import to_dict [as 别名]
class MatchTest(unittest.TestCase):
def setUp(self):
self.alpha_name = 'a_name'
self.alpha_passage = 'a_passage'
self.alpha_indices = (0, 12)
self.beta_name = 'b_name'
self.beta_passage = 'b_passage'
self.beta_indices = (12, 24)
self.match = Match(alpha_passage=self.alpha_passage,
alpha_indices=self.alpha_indices,
beta_passage=self.beta_passage,
beta_indices=self.beta_indices)
def test_to_dict(self):
"""
Test dict conversion for JSON serialization
"""
match_dict = self.match.to_dict()
self.assertEqual(self.alpha_passage, match_dict['alpha_passage'])
self.assertEqual(self.alpha_indices, match_dict['alpha_indices'])
self.assertEqual(self.beta_passage, match_dict['beta_passage'])
self.assertEqual(self.beta_indices, match_dict['beta_indices'])
def test_eq(self):
"""
Test match equality
"""
a = Match(alpha_passage=u'one',
alpha_indices=(3, 5),
beta_passage=u'two',
beta_indices=(9, 11))
b = Match(alpha_passage=u'two',
alpha_indices=(9, 11),
beta_passage=u'one',
beta_indices=(3, 5))
c = Match(alpha_passage=u'five',
alpha_indices=(44, 47),
beta_passage=u'six',
beta_indices=(0, 3))
self.assertTrue(a == b)
self.assertFalse(a == c)
self.assertFalse(b == c)
# If objects are equal their hashes must also be equal
hash_a = hash(a)
hash_b = hash(b)
hash_c = hash(c)
self.assertTrue(hash_a == hash_b)
self.assertFalse(hash_a == hash_c)
self.assertFalse(hash_b == hash_c)
def test_swap_alpha_beta(self):
"""
Test swapping alpha and beta documents
"""
alpha_passage = u'one'
alpha_indices = (3, 5)
beta_passage = u'two'
beta_indices = (9, 11)
a = Match(alpha_passage=alpha_passage,
alpha_indices=alpha_indices,
beta_passage=beta_passage,
beta_indices=beta_indices)
a.swap_alpha_beta()
self.assertEqual(a.beta_passage, alpha_passage)
self.assertEqual(a.beta_indices, alpha_indices)
self.assertEqual(a.alpha_passage, beta_passage)
self.assertEqual(a.alpha_indices, beta_indices)