def testTupleAndOr(self):
     c = preconditions.parse("None or tuple[int or str]")
     self.assertIsInstance(c, preconditions._OrPrecondition)
     c1, c2 = c._choices
     self.assertClassName("NoneType", c1)
     self.assertIsInstance(c2, preconditions._TuplePrecondition)
     self.assertOr(["int", "str"], c2._element_condition)
 def testIsInstance(self):
     saved = dict(preconditions._REGISTERED_CLASSES)
     try:
         # Can't parse class until it is registered.
         self.assertRaises(ValueError, preconditions.parse, "{BaseClass}")
         # Check parsed condition.
         preconditions.register(BaseClass)
         condition = preconditions.parse("{BaseClass}")
         self.assertIsInstance(condition,
                               preconditions._IsInstancePrecondition)
         self.assertEquals(BaseClass, condition._cls)
         # Can't re-register a class.
         self.assertRaises(AssertionError, preconditions.register,
                           BaseClass)
     finally:
         # Leave the world as we found it.
         preconditions._REGISTERED_CLASSES = saved
 def testOr(self):
     self.assertOr(["int", "str", "float"],
                   preconditions.parse("int or str or float"))
 def testTuple(self):
     c = preconditions.parse("tuple[int]")
     self.assertIsInstance(c, preconditions._TuplePrecondition)
     self.assertClassName("int", c._element_condition)
 def testNone(self):
     self.assertClassName("NoneType", preconditions.parse("None"))
 def testName(self):
     self.assertClassName("Foo", preconditions.parse("Foo"))