Beispiel #1
0
 def target_register_spec(self):
     """
     Make a TargetRegister object
     """
     return sb.create_spec(
         TargetRegister,
         collector=sb.formatted(
             sb.overridden("{collector}"), formatter=MergedOptionStringFormatter
         ),
     )
Beispiel #2
0
        class V:
            spec = sb.formatted(sb.string_spec(), formatter=MergedOptionStringFormatter)
            target_register = mock.Mock(name="target_register")

            @hp.memoized_property
            def meta(s):
                options = MergedOptions.using(
                    {"target_register": s.target_register}, dont_prefix=[mock.Mock]
                )
                return Meta(options, [])
Beispiel #3
0
    def normalise_filled(self, meta, val):
        options_spec = sb.set_options(
            filename=sb.required(sb.string_spec()), optional=sb.defaulted(sb.boolean(), False)
        )
        lst_spec = sb.listof(sb.or_spec(sb.string_spec(), options_spec))

        if isinstance(val, list):
            val = {"after": lst_spec.normalise(meta, val)}

        val = sb.set_options(after=lst_spec, before=lst_spec).normalise(meta, val)

        formatted = sb.formatted(sb.string_spec(), formatter=MergedOptionStringFormatter)

        for key in ("after", "before"):
            result = []

            for i, thing in enumerate(val[key]):
                filename = thing
                optional = False
                if isinstance(thing, dict):
                    filename = thing["filename"]
                    optional = thing["optional"]

                filename = formatted.normalise(meta.at(key).indexed_at(i), filename)
                if optional and not os.path.exists(filename):
                    log.warning(hp.lc("Ignoring optional configuration", filename=filename))
                    continue

                if not os.path.exists(filename):
                    raise BadConfiguration(
                        "Specified extra file doesn't exist",
                        source=self.source,
                        filename=filename,
                        meta=meta,
                    )

                result.append(filename)

            val[key] = result

        return self.extras_spec.normalise(meta, val)
Beispiel #4
0
    it "knows about listof":
        self.assertSignature(sb.listof(sb.integer_spec()), "[ integer , ... ]")
        self.assertSignature(sb.listof(sb.any_spec()), "[ <item> , ... ]")

    it "knows about dictof":
        self.assertSignature(sb.dictof(sb.string_spec(), sb.integer_spec()), "{ string : integer }")
        self.assertSignature(sb.dictof(sb.string_spec(), sb.any_spec()), "{ string : <item> }")

    it "knows about container_spec":

        class Container:
            def __init__(self, value):
                pass

        self.assertSignature(sb.container_spec(Container, sb.string_spec()), "string")

    it "knows about formatted":
        self.assertSignature(sb.formatted(sb.string_spec(), formatter=None), "string")

    it "knows about or_spec":
        self.assertSignature(
            sb.or_spec(sb.string_spec(), sb.dictionary_spec()), "string or dictionary"
        )
        self.assertSignature(sb.or_spec(), "")
        self.assertSignature(sb.or_spec(sb.string_spec()), "string")
        self.assertSignature(sb.or_spec(sb.string_spec(), sb.any_spec()), "string or <item>")
        self.assertSignature(
            sb.or_spec(sb.string_spec(), sb.any_spec(), sb.boolean()), "string or <item> or boolean"
        )