示例#1
0
    def test_get_field_descriptor(self):
        class ConfigWithFallback(Config):
            field = ConfigText("field")

        cfg = ConfigWithFallback({"field": "foo"})
        fallback = FieldFallback()
        self.assertEqual(fallback.get_field_descriptor(cfg, "field"),
                         ConfigWithFallback.field)
        self.assertRaises(ConfigError, fallback.get_field_descriptor, cfg,
                          "no_field")
示例#2
0
    def test_field_present(self):
        class ConfigWithFallback(Config):
            field = ConfigText("field")
            field_empty = ConfigText("field_empty")
            field_default = ConfigText("field_default", default="bar")

        cfg = ConfigWithFallback({"field": "foo"})
        fallback = FieldFallback()
        self.assertEqual(fallback.field_present(cfg, "field"), True)
        self.assertEqual(fallback.field_present(cfg, "field_empty"), False)
        self.assertEqual(fallback.field_present(cfg, "field_default"), False)
示例#3
0
    def test_get_field_descriptor(self):
        class ConfigWithFallback(Config):
            field = ConfigText("field")

        cfg = ConfigWithFallback({"field": "foo"})
        fallback = FieldFallback()
        self.assertEqual(
            fallback.get_field_descriptor(cfg, "field"),
            ConfigWithFallback.field)
        self.assertRaises(
            ConfigError, fallback.get_field_descriptor, cfg, "no_field")
示例#4
0
    def test_field_present(self):
        class ConfigWithFallback(Config):
            field = ConfigText("field")
            field_empty = ConfigText("field_empty")
            field_default = ConfigText("field_default", default="bar")

        cfg = ConfigWithFallback({"field": "foo"})
        fallback = FieldFallback()
        self.assertEqual(fallback.field_present(cfg, "field"), True)
        self.assertEqual(fallback.field_present(cfg, "field_empty"), False)
        self.assertEqual(fallback.field_present(cfg, "field_default"), False)
示例#5
0
    def test_present(self):
        class ConfigWithFallback(Config):
            field = ConfigText("field")
            field_empty = ConfigText("field_empty")
            field_default = ConfigText("field_default", default="bar")
            field_default_required = ConfigText("field_default", default="baz")

        fallback = FieldFallback()
        fallback.required_fields = ("field", "field_default_required")

        self.assertEqual(fallback.present(ConfigWithFallback({})), False)

        cfg = ConfigWithFallback({
            "field": "foo",
            "field_default_required": "bar",
        })
        self.assertEqual(fallback.present(cfg), True)
示例#6
0
    def test_present(self):
        class ConfigWithFallback(Config):
            field = ConfigText("field")
            field_empty = ConfigText("field_empty")
            field_default = ConfigText("field_default", default="bar")
            field_default_required = ConfigText("field_default", default="baz")

        fallback = FieldFallback()
        fallback.required_fields = ("field", "field_default_required")

        self.assertEqual(fallback.present(ConfigWithFallback({})), False)

        cfg = ConfigWithFallback({
            "field": "foo",
            "field_default_required": "bar",
        })
        self.assertEqual(fallback.present(cfg), True)
示例#7
0
 def test_build_value_not_implemented(self):
     fallback = FieldFallback()
     self.assertRaises(NotImplementedError, fallback.build_value, None)
示例#8
0
 def test_present_not_implemented(self):
     fallback = FieldFallback()
     self.assertRaises(NotImplementedError, fallback.present, None)