Example #1
0
    def testNested(self):
        self.assertRaiseLCE(DictionaryError,
                            "policy_bad_subdef.dictionary is a string",
                            Dictionary, "Malformed subdictionary",
                            self.getTestDictionary("nested_dictionary_bad_1.paf"))

        p = Policy(self.getTestDictionary("nested_policy_good.paf"))
        self.assertRaiseLCE(DictionaryError, "Unknown Dictionary property",
                            Dictionary, "Malformed subdictionary",
                            self.getTestDictionary("nested_dictionary_bad_2.paf"))

        d = Dictionary(self.getTestDictionary("nested_dictionary_good.paf"))
        d.check()
        self.assertRaiseLCE(lsst.pex.exceptions.LogicError, "dictionaryFile needs to be loaded",
                            d.validate, "dictionaryFile not loaded", p)
        self.assertFalse(d.hasSubDictionary("policy_1"))
        self.assertTrue(d.hasSubDictionary("policy_2"))
        self.assertFalse(d.hasSubDictionary("policy_load"))
        n = d.loadPolicyFiles(self.getTestDictionary(), True)
        self.assertTrue(d.hasSubDictionary("policy_load"))
        self.assertEqual(n, 1)  # number of files loaded
        d.validate(p)

        ve = ValidationError("Dictionary_1.py", 1, "testNested")
        p = Policy(self.getTestDictionary("nested_policy_bad.paf"))
        d.validate(p, ve.cpp)
        self.assertEqual(ve.getErrors("policy_1"), ValidationError.WRONG_TYPE)
        self.assertEqual(ve.getErrors("policy_2.foo"),
                         ValidationError.VALUE_DISALLOWED)
        self.assertEqual(ve.getErrors("policy_2.bar"),
                         ValidationError.MISSING_REQUIRED)
        self.assertEqual(ve.getErrors("policy_3.baz.qux"),
                         ValidationError.WRONG_TYPE)
        self.assertEqual(ve.getErrors("policy_3.baz.paisley"),
                         ValidationError.MISSING_REQUIRED)
        self.assertEqual(ve.getErrors("policy_3.baz.paisley"),
                         ValidationError.MISSING_REQUIRED)
        self.assertEqual(ve.getErrors("policy_load.height"),
                         ValidationError.MISSING_REQUIRED)
        self.assertEqual(ve.getParamCount(), 6)

        # multiple nesting
        p = Policy(self.getTestDictionary("nested_policy_1.paf"))
        n = p.loadPolicyFiles(self.getTestDictionary())
        self.assertEqual(n, 3)
        self.assertEqual(p.getString("1.2b.foo"), "bar")

        d = Dictionary(self.getTestDictionary("nested_dictionary_1.paf"))
        n = d.loadPolicyFiles(self.getTestDictionary())
        self.assertEqual(n, 3)
        p = Policy(True, d)  # load from defaults
        self.assertEqual(p.getString("1.2a.foo"), "bar")
        self.assertEqual(p.getString("1.2b.foo"), "bar")

        # error in child
        d = Dictionary(self.getTestDictionary("nested_dictionary_bad_child.paf"))
        d.loadPolicyFiles(self.getTestDictionary())
        # this should really be caught during loadPolicyFiles(), above
        self.assertRaiseLCE(DictionaryError, "Unknown type: \"NotAType\"",
                            d.makeDef("sub.something").getType,
                            "Loaded sub-dictionary specified a bogus type")
    def testNested(self):
        self.assertRaiseLCE(DictionaryError,
                            "policy_bad_subdef.dictionary is a string",
                            Dictionary, "Malformed subdictionary",
                            self.getTestDictionary("nested_dictionary_bad_1.paf"))

        p = Policy(self.getTestDictionary("nested_policy_good.paf"))
        self.assertRaiseLCE(DictionaryError, "Unknown Dictionary property",
                            Dictionary, "Malformed subdictionary",
                            self.getTestDictionary("nested_dictionary_bad_2.paf"))

        d = Dictionary(self.getTestDictionary("nested_dictionary_good.paf"))
        d.check()
        self.assertRaiseLCE(lsst.pex.exceptions.LogicError, "dictionaryFile needs to be loaded",
                            d.validate, "dictionaryFile not loaded", p)
        self.assert_(not d.hasSubDictionary("policy_1"))
        self.assert_(d.hasSubDictionary("policy_2"))
        self.assert_(not d.hasSubDictionary("policy_load"))
        n = d.loadPolicyFiles(self.getTestDictionary(), True)
        self.assert_(d.hasSubDictionary("policy_load"))
        self.assert_(n == 1) # number of files loaded
        d.validate(p)

        ve = ValidationError("Dictionary_1.py", 1, "testNested")
        p = Policy(self.getTestDictionary("nested_policy_bad.paf"))
        d.validate(p, ve.cpp)
        self.assert_(ve.getErrors("policy_1") == ValidationError.WRONG_TYPE)
        self.assert_(ve.getErrors("policy_2.foo")
                     == ValidationError.VALUE_DISALLOWED)
        self.assert_(ve.getErrors("policy_2.bar")
                     == ValidationError.MISSING_REQUIRED)
        self.assert_(ve.getErrors("policy_3.baz.qux")
                     == ValidationError.WRONG_TYPE)
        self.assert_(ve.getErrors("policy_3.baz.paisley")
                     == ValidationError.MISSING_REQUIRED)
        self.assert_(ve.getErrors("policy_3.baz.paisley")
                     == ValidationError.MISSING_REQUIRED)
        self.assert_(ve.getErrors("policy_load.height")
                     == ValidationError.MISSING_REQUIRED)
        self.assert_(ve.getParamCount() == 6)

        # multiple nesting
        p = Policy(self.getTestDictionary("nested_policy_1.paf"))
        n = p.loadPolicyFiles(self.getTestDictionary())
        self.assert_(n == 3)
        self.assert_(p.getString("1.2b.foo") == "bar")

        d = Dictionary(self.getTestDictionary("nested_dictionary_1.paf"))
        n = d.loadPolicyFiles(self.getTestDictionary())
        self.assert_(n == 3)
        p = Policy(True, d) # load from defaults
        self.assert_(p.getString("1.2a.foo") == "bar")
        self.assert_(p.getString("1.2b.foo") == "bar")

        # error in child
        d = Dictionary(self.getTestDictionary("nested_dictionary_bad_child.paf"))
        d.loadPolicyFiles(self.getTestDictionary())
        # this should really be caught during loadPolicyFiles(), above
        self.assertRaiseLCE(DictionaryError, "Unknown type: \"NotAType\"",
                            d.makeDef("sub.something").getType,
                            "Loaded sub-dictionary specified a bogus type")
Example #3
0
    def testValues(self):
        d = Dictionary(self.getTestDictionary("values_dictionary.paf"))
        d.check()
        p = Policy(self.getTestDictionary("values_policy_good_1.paf"))
        ve = ValidationError("Dictionary_1.py", 0, "testValues")
        d.validate(p, ve.cpp)
        self.assertEqual(ve.getParamCount(), 0)

        # policy: disallow allowed, min, max
        p = Policy(self.getTestDictionary("values_policy_bad_policy_set.paf"))
        ve = ValidationError("Dictionary_1.py", 1, "testValues")
        d.validate(p, ve.cpp)
        self.assertEqual(ve.getErrors("policy_set_type"),
                         ValidationError.VALUE_DISALLOWED)
        p = Policy(self.getTestDictionary("values_policy_bad_policy_max.paf"))
        ve = ValidationError("Dictionary_1.py", 2, "testValues")
        d.validate(p, ve.cpp)
        self.assertEqual(ve.getErrors("policy_max_type"),
                         ValidationError.VALUE_OUT_OF_RANGE)
        p = Policy(self.getTestDictionary("values_policy_bad_policy_min.paf"))
        ve = ValidationError("Dictionary_1.py", 3, "testValues")
        d.validate(p, ve.cpp)
        self.assertEqual(ve.getErrors("policy_min_type"),
                         ValidationError.VALUE_OUT_OF_RANGE)

        # minOccurs/maxOccurs
        p = Policy(self.getTestDictionary("values_policy_bad_occurs.paf"))
        ve = ValidationError("Dictionary_1.py", 1, "testValues")
        d.validate(p, ve.cpp)
        self.assertEqual(ve.getParamCount(), 6)
        self.assertEqual(ve.getErrors("bool_set_count_type"),
                         ValidationError.TOO_MANY_VALUES)
        self.assertEqual(ve.getErrors("int_range_count_type"),
                         ValidationError.MISSING_REQUIRED)
        self.assertEqual(ve.getErrors("double_range_count_type"),
                         ValidationError.TOO_MANY_VALUES)
        self.assertEqual(ve.getErrors("string_count_type"),
                         ValidationError.ARRAY_TOO_SHORT)
        self.assertEqual(ve.getErrors("disallowed"),
                         ValidationError.TOO_MANY_VALUES)
        self.assertEqual(ve.getErrors("policy_count_type"),
                         ValidationError.TOO_MANY_VALUES)

        # min
        p = Policy(self.getTestDictionary("values_policy_bad_min.paf"))
        ve = ValidationError("Dictionary_1.py", 1, "testValues")
        d.validate(p, ve.cpp)
        self.assertEqual(ve.getParamCount(), 4)
        self.assertEqual(ve.getErrors(), ValidationError.VALUE_OUT_OF_RANGE)
        self.assertEqual(ve.getErrors("string_count_type"), ValidationError.OK)
        self.assertEqual(ve.getErrors("policy_count_type"), ValidationError.OK)
        # max
        p = Policy(self.getTestDictionary("values_policy_bad_max.paf"))
        ve = ValidationError("Dictionary_1.py", 1, "testValues")
        d.validate(p, ve.cpp)
        self.assertEqual(ve.getParamCount(), 4)
        self.assertEqual(ve.getErrors(), ValidationError.VALUE_OUT_OF_RANGE)
        self.assertEqual(ve.getErrors("string_count_type"), ValidationError.OK)
        self.assertEqual(ve.getErrors("policy_count_type"), ValidationError.OK)

        # allowed
        p = Policy(self.getTestDictionary("values_policy_bad_allowed.paf"))
        ve = ValidationError("Dictionary_1.py", 1, "testValues")
        d.validate(p, ve.cpp)
        self.assertEqual(ve.getParamCount(), 4)
        self.assertEqual(ve.getErrors(), ValidationError.VALUE_DISALLOWED)
        self.assertEqual(ve.getErrors("int_range_count_type"), ValidationError.OK)
        self.assertEqual(ve.getErrors("string_count_type"), ValidationError.OK)
        self.assertEqual(ve.getErrors("policy_count_type"), ValidationError.OK)

        # allowed & min/max
        p = Policy(self.getTestDictionary("values_policy_bad_allowedminmax.paf"))
        ve = ValidationError("Dictionary_1.py", 1, "testValues")
        d.validate(p, ve.cpp)
        self.assertEqual(ve.getParamCount(), 2)
        self.assertEqual(ve.getErrors("int_range_set_type"),
                         int(ValidationError.VALUE_DISALLOWED) +
                         int(ValidationError.VALUE_OUT_OF_RANGE))
        self.assertEqual(ve.getErrors("double_range_count_type"),
                         int(ValidationError.TOO_MANY_VALUES) +
                         int(ValidationError.VALUE_OUT_OF_RANGE))
        ve = ValidationError("Dictionary_1.py", 1, "testValues")
        d.validate(p, ve.cpp)
    def testValues(self):
        d = Dictionary(self.getTestDictionary("values_dictionary.paf"))
        d.check()
        p = Policy(self.getTestDictionary("values_policy_good_1.paf"))
        ve = ValidationError("Dictionary_1.py", 0, "testValues")
        d.validate(p, ve.cpp)
        self.assert_(ve.getParamCount() == 0)

        # policy: disallow allowed, min, max
        p = Policy(self.getTestDictionary("values_policy_bad_policy_set.paf"))
        ve = ValidationError("Dictionary_1.py", 1, "testValues")
        d.validate(p, ve.cpp)
        self.assert_(ve.getErrors("policy_set_type") 
                     == ValidationError.VALUE_DISALLOWED)
        p = Policy(self.getTestDictionary("values_policy_bad_policy_max.paf"))
        ve = ValidationError("Dictionary_1.py", 2, "testValues")
        d.validate(p, ve.cpp)
        self.assert_(ve.getErrors("policy_max_type") 
                     == ValidationError.VALUE_OUT_OF_RANGE)
        p = Policy(self.getTestDictionary("values_policy_bad_policy_min.paf"))
        ve = ValidationError("Dictionary_1.py", 3, "testValues")
        d.validate(p, ve.cpp)
        self.assert_(ve.getErrors("policy_min_type") 
                     == ValidationError.VALUE_OUT_OF_RANGE)

        # minOccurs/maxOccurs
        p = Policy(self.getTestDictionary("values_policy_bad_occurs.paf"))
        ve = ValidationError("Dictionary_1.py", 1, "testValues")
        d.validate(p, ve.cpp)
        self.assert_(ve.getParamCount() == 6)
        self.assert_(ve.getErrors("bool_set_count_type")
                    == ValidationError.TOO_MANY_VALUES)
        self.assert_(ve.getErrors("int_range_count_type")
                    == ValidationError.MISSING_REQUIRED)
        self.assert_(ve.getErrors("double_range_count_type")
                    == ValidationError.TOO_MANY_VALUES)
        self.assert_(ve.getErrors("string_count_type")
                    == ValidationError.ARRAY_TOO_SHORT)
        self.assert_(ve.getErrors("disallowed")
                    == ValidationError.TOO_MANY_VALUES)
        self.assert_(ve.getErrors("policy_count_type")
                    == ValidationError.TOO_MANY_VALUES)

        # min
        p = Policy(self.getTestDictionary("values_policy_bad_min.paf"))
        ve = ValidationError("Dictionary_1.py", 1, "testValues")
        d.validate(p, ve.cpp)
        self.assert_(ve.getParamCount() == 4)
        self.assert_(ve.getErrors() == ValidationError.VALUE_OUT_OF_RANGE)
        self.assert_(ve.getErrors("string_count_type") == ValidationError.OK)
        self.assert_(ve.getErrors("policy_count_type") == ValidationError.OK)
        # max
        p = Policy(self.getTestDictionary("values_policy_bad_max.paf"))
        ve = ValidationError("Dictionary_1.py", 1, "testValues")
        d.validate(p, ve.cpp)
        self.assert_(ve.getParamCount() == 4)
        self.assert_(ve.getErrors() == ValidationError.VALUE_OUT_OF_RANGE)
        self.assert_(ve.getErrors("string_count_type") == ValidationError.OK)
        self.assert_(ve.getErrors("policy_count_type") == ValidationError.OK)

        # allowed
        p = Policy(self.getTestDictionary("values_policy_bad_allowed.paf"))
        ve = ValidationError("Dictionary_1.py", 1, "testValues")
        d.validate(p, ve.cpp)
        self.assert_(ve.getParamCount() == 4)
        self.assert_(ve.getErrors() == ValidationError.VALUE_DISALLOWED)
        self.assert_(ve.getErrors("int_range_count_type") == ValidationError.OK)
        self.assert_(ve.getErrors("string_count_type") == ValidationError.OK)
        self.assert_(ve.getErrors("policy_count_type") == ValidationError.OK)

        # allowed & min/max
        p = Policy(self.getTestDictionary("values_policy_bad_allowedminmax.paf"))
        ve = ValidationError("Dictionary_1.py", 1, "testValues")
        d.validate(p, ve.cpp)
        self.assert_(ve.getParamCount() == 2)
        self.assert_(ve.getErrors("int_range_set_type") 
                     == ValidationError.VALUE_DISALLOWED 
                     + ValidationError.VALUE_OUT_OF_RANGE)
        self.assert_(ve.getErrors("double_range_count_type") 
                     == ValidationError.TOO_MANY_VALUES 
                     + ValidationError.VALUE_OUT_OF_RANGE)
        ve = ValidationError("Dictionary_1.py", 1, "testValues")
        d.validate(p, ve.cpp)