def test_model_group_container(self): group = ModelGroup('choice') group.append(('a', )) self.assertListEqual(group[:], [('a', )]) group[0] = ('a', 'b') self.assertListEqual(group[:], [('a', 'b')]) group.append(('c', )) self.assertListEqual(group[:], [('a', 'b'), ('c', )]) del group[0] self.assertListEqual(group[:], [('c', )])
def test_effective_min_occurs(self): group = ModelGroup('sequence') self.assertEqual(group.effective_min_occurs, 0) group.append(ParticleMixin()) self.assertEqual(group.effective_min_occurs, 1) group.append(ParticleMixin()) group[0].min_occurs = 0 self.assertEqual(group.effective_min_occurs, 1) group.model = 'choice' self.assertEqual(group.effective_min_occurs, 0) group[1].min_occurs = 0 group.model = 'sequence' self.assertEqual(group.effective_min_occurs, 0) group.model = 'choice' group[0].min_occurs = group[1].min_occurs = 1 self.assertEqual(group.effective_min_occurs, 1)
def test_is_pointless(self): root_group = ModelGroup('choice') group = ModelGroup('sequence') root_group.append(group) self.assertTrue(group.is_pointless(parent=root_group)) group.append(('A',)) self.assertTrue(group.is_pointless(parent=root_group)) group.append(('B',)) self.assertFalse(group.is_pointless(parent=root_group))
def test_has_occurs_restriction(self): group = ModelGroup('sequence') other = ModelGroup('sequence') other.append(ParticleMixin()) self.assertTrue(group.has_occurs_restriction(other)) group.append(ParticleMixin()) self.assertTrue(group.has_occurs_restriction(other)) for model in ['sequence', 'all', 'choice']: group = ModelGroup(model) group.append(ParticleMixin()) self.assertTrue(group.has_occurs_restriction(other=ParticleMixin())) self.assertFalse(group.has_occurs_restriction(other=ParticleMixin(2, 2))) self.assertTrue(group.has_occurs_restriction(other=ParticleMixin(1, None))) group.max_occurs = None self.assertFalse(group.has_occurs_restriction(other=ParticleMixin())) self.assertTrue(group.has_occurs_restriction(other=ParticleMixin(1, None)))
def test_effective_max_occurs(self): group = ModelGroup('sequence') self.assertEqual(group.effective_max_occurs, 0) group.append(ParticleMixin()) self.assertEqual(group.effective_max_occurs, 1) group.append(ParticleMixin(max_occurs=2)) self.assertEqual(group.effective_max_occurs, 1) group[0].min_occurs = group[0].max_occurs = 0 self.assertEqual(group.effective_max_occurs, 2) group[1].min_occurs = group[1].max_occurs = 0 self.assertEqual(group.effective_max_occurs, 0) group.append(ParticleMixin()) self.assertEqual(group.effective_max_occurs, 1) group[2].min_occurs = 0 self.assertEqual(group.effective_max_occurs, 1) group[0].max_occurs = None self.assertIsNone(group.effective_max_occurs) group[2].min_occurs = 1 group = ModelGroup('choice') group.append(ParticleMixin()) self.assertEqual(group.effective_max_occurs, 1) group.append(ParticleMixin()) group[0].min_occurs = group[0].max_occurs = 0 self.assertEqual(group.effective_max_occurs, 1) group[0].max_occurs = None self.assertIsNone(group.effective_max_occurs) group = ModelGroup('sequence') group.append(ParticleMixin()) self.assertEqual(group.effective_max_occurs, 1) group[0].max_occurs = None self.assertIsNone(group.effective_max_occurs) group[0].max_occurs = 1 self.assertEqual(group.effective_max_occurs, 1) group.max_occurs = None self.assertIsNone(group.effective_max_occurs)
def test_is_empty(self): group = ModelGroup('all') self.assertTrue(group.is_empty()) group.append(('A', )) self.assertFalse(group.is_empty())