Ejemplo n.º 1
0
 def test_validate(self):
   collection_exactly_a_or_b = TypedCollection(Exactly(self.A, self.B))
   self.assertEqual([self.A()], collection_exactly_a_or_b.validate_satisfied_by([self.A()]))
   self.assertEqual([self.B()], collection_exactly_a_or_b.validate_satisfied_by([self.B()]))
   with self.assertRaisesWithMessage(TypeConstraintError, dedent("""\
       in wrapped constraint TypedCollection(Exactly(A or B)): value A() (with type 'A') must satisfy this type constraint: SubclassesOf(Iterable).
       Note that objects matching {} are not considered iterable.""")
                                     .format(_string_type_constraint)):
     collection_exactly_a_or_b.validate_satisfied_by(self.A())
   with self.assertRaisesWithMessage(TypeConstraintError, dedent("""\
       in wrapped constraint TypedCollection(Exactly(A or B)) matching iterable object [C()]: value C() (with type 'C') must satisfy this type constraint: Exactly(A or B).""")):
     collection_exactly_a_or_b.validate_satisfied_by([self.C()])
Ejemplo n.º 2
0
 def test_validate(self):
   collection_exactly_a_or_b = TypedCollection(Exactly(self.A, self.B))
   self.assertEqual([self.A()], collection_exactly_a_or_b.validate_satisfied_by([self.A()]))
   self.assertEqual([self.B()], collection_exactly_a_or_b.validate_satisfied_by([self.B()]))
   with self.assertRaisesWithMessage(TypeConstraintError, dedent("""\
       in wrapped constraint TypedCollection(Exactly(A or B)): value A() (with type 'A') must satisfy this type constraint: SubclassesOf(Iterable).
       Note that objects matching {} are not considered iterable.""")
                                     .format(TypedCollection.exclude_iterable_constraint)):
     collection_exactly_a_or_b.validate_satisfied_by(self.A())
   with self.assertRaisesWithMessage(TypeConstraintError, dedent("""\
       in wrapped constraint TypedCollection(Exactly(A or B)) matching iterable object [C()]: value C() (with type 'C') must satisfy this type constraint: Exactly(A or B).""")):
     collection_exactly_a_or_b.validate_satisfied_by([self.C()])
Ejemplo n.º 3
0
 def test_validate(self):
     collection_exactly_a_or_b = TypedCollection(Exactly(self.A, self.B))
     self.assertEqual([self.A()],
                      collection_exactly_a_or_b.validate_satisfied_by(
                          [self.A()]))
     self.assertEqual([self.B()],
                      collection_exactly_a_or_b.validate_satisfied_by(
                          [self.B()]))
     with self.assertRaisesWithMessage(
             TypeConstraintError,
             "in wrapped constraint TypedCollection(Exactly(A or B)): value A() (with type 'A') must satisfy this type constraint: SubclassesOf(Iterable)."
     ):
         collection_exactly_a_or_b.validate_satisfied_by(self.A())
     with self.assertRaisesWithMessage(
             TypeConstraintError,
             "in wrapped constraint TypedCollection(Exactly(A or B)) matching iterable object [C()]: value C() (with type 'C') must satisfy this type constraint: Exactly(A or B)."
     ):
         collection_exactly_a_or_b.validate_satisfied_by([self.C()])