예제 #1
0
 def test_single(self):
   superclasses_of_b = SuperclassesOf(self.B)
   self.assertEqual((self.B,), superclasses_of_b.types)
   self.assertTrue(superclasses_of_b.satisfied_by(self.A()))
   self.assertTrue(superclasses_of_b.satisfied_by(self.B()))
   self.assertFalse(superclasses_of_b.satisfied_by(self.BPrime()))
   self.assertFalse(superclasses_of_b.satisfied_by(self.C()))
예제 #2
0
 def test_multiple(self):
   superclasses_of_a_or_b = SuperclassesOf(self.A, self.B)
   self.assertEqual((self.A, self.B), superclasses_of_a_or_b.types)
   self.assertTrue(superclasses_of_a_or_b.satisfied_by(self.A()))
   self.assertTrue(superclasses_of_a_or_b.satisfied_by(self.B()))
   self.assertFalse(superclasses_of_a_or_b.satisfied_by(self.BPrime()))
   self.assertFalse(superclasses_of_a_or_b.satisfied_by(self.C()))
예제 #3
0
 def test_multiple(self):
   superclasses_of_a_or_b = SuperclassesOf(self.A, self.B)
   self.assertEqual((self.A, self.B), superclasses_of_a_or_b.types)
   self.assertTrue(superclasses_of_a_or_b.satisfied_by(self.A()))
   self.assertTrue(superclasses_of_a_or_b.satisfied_by(self.B()))
   self.assertFalse(superclasses_of_a_or_b.satisfied_by(self.BPrime()))
   self.assertFalse(superclasses_of_a_or_b.satisfied_by(self.C()))
예제 #4
0
 def test_single(self):
   superclasses_of_b = SuperclassesOf(self.B)
   self.assertEqual((self.B,), superclasses_of_b.types)
   self.assertTrue(superclasses_of_b.satisfied_by(self.A()))
   self.assertTrue(superclasses_of_b.satisfied_by(self.B()))
   self.assertFalse(superclasses_of_b.satisfied_by(self.BPrime()))
   self.assertFalse(superclasses_of_b.satisfied_by(self.C()))
예제 #5
0
 def test_validate(self):
   superclasses_of_a_or_b = SuperclassesOf(self.A, self.B)
   self.assertEqual(self.A(), superclasses_of_a_or_b.validate_satisfied_by(self.A()))
   self.assertEqual(self.B(), superclasses_of_a_or_b.validate_satisfied_by(self.B()))
   with self.assertRaisesWithMessage(
       TypeConstraintError,
       "value C() (with type 'C') must satisfy this type constraint: SuperclassesOf(A or B)."):
     superclasses_of_a_or_b.validate_satisfied_by(self.C())
예제 #6
0
  def test_str_and_repr(self):
    superclasses_of_b = SuperclassesOf(self.B)
    self.assertEqual("SuperclassesOf(B)", str(superclasses_of_b))
    self.assertEqual("SuperclassesOf(B)", repr(superclasses_of_b))

    superclasses_of_multiple = SuperclassesOf(self.A, self.B)
    self.assertEqual("SuperclassesOf(A or B)", str(superclasses_of_multiple))
    self.assertEqual("SuperclassesOf(A, B)", repr(superclasses_of_multiple))
예제 #7
0
 def test_validate(self):
   superclasses_of_a_or_b = SuperclassesOf(self.A, self.B)
   self.assertEqual(self.A(), superclasses_of_a_or_b.validate_satisfied_by(self.A()))
   self.assertEqual(self.B(), superclasses_of_a_or_b.validate_satisfied_by(self.B()))
   with self.assertRaisesWithMessage(
       TypeConstraintError,
       "value C() (with type 'C') must satisfy this type constraint: SuperclassesOf(A or B)."):
     superclasses_of_a_or_b.validate_satisfied_by(self.C())