Exemple #1
0
 def test_name(self):
     v1 = Variable()
     self.assertIsNone(v1.name)
     v2 = Variable('var')
     self.assertEqual(v2.name, 'var')
     v3 = Variable(name='var')
     self.assertEqual(v3.name, 'var')
Exemple #2
0
 class TestConfig(Config):
     v1 = Variable()
     v2 = Variable(section="v23_section")
     v3 = Variable(section="v23_section")
     v_unset = Variable()
     v_bool = Variable(section="type_section", kind=bool)
     v_int = Variable(section="type_section", kind=int)
     v_float = Variable(section="type_section", kind=float)
     v_list = Variable(section="type_section", kind=list)
     v_str = Variable(section="type_section", kind=str)
     s = Section()
     ps = ParametricSection()
Exemple #3
0
 def test_name(self):
     s1 = Section()
     self.assertIsNone(s1.name)
     s2 = Section('sec')
     self.assertEqual(s2.name, 'sec')
     s3 = Variable(name='sec')
     self.assertEqual(s3.name, 'sec')
Exemple #4
0
 def test_validator_list__with_NotUnsetValidator(self):
     """
     verify that each Variable has a validator_list and that, if
     customized, and if using NotUnsetValidator it will take precedence
     over all other validators, including the implicit KindValidator
     """
     var = Variable(validator_list=[NotUnsetValidator()])
     self.assertEqual(var.validator_list,
                      [NotUnsetValidator(), KindValidator])
Exemple #5
0
 def test_validator_list__explicit(self):
     """
     verify that each Variable has a validator_list and that, if
     customized, the list contains the custom validators, preceded by
     the implicit KindValidator object
     """
     def DummyValidator(variable, new_value):
         """ Dummy validator for the test below"""
         pass
     var = Variable(validator_list=[DummyValidator])
     self.assertEqual(var.validator_list, [KindValidator, DummyValidator])
Exemple #6
0
 def test_kind(self):
     v1 = Variable(kind=bool)
     self.assertIs(v1.kind, bool)
     v2 = Variable(kind=int)
     self.assertIs(v2.kind, int)
     v3 = Variable(kind=float)
     self.assertIs(v3.kind, float)
     v4 = Variable(kind=str)
     self.assertIs(v4.kind, str)
     v5 = Variable()
     self.assertIs(v5.kind, str)
     v6 = Variable(kind=list)
     self.assertIs(v6.kind, list)
     with self.assertRaises(ValueError):
         Variable(kind=dict)
Exemple #7
0
 class _Config(Config):
     var = Variable()
Exemple #8
0
 class _Config(Config):
     var_bool = Variable(kind=bool)
     var_int = Variable(kind=int)
     var_float = Variable(kind=float)
     var_str = Variable(kind=str)
Exemple #9
0
        class TestConfig(Config):
            v = Variable()

            def validate_whole(self):
                raise ValidationError(TestConfig.v, self.v, "v is evil")
Exemple #10
0
 class TestConfig(Config):
     v = Variable(validator_list=[NotUnsetValidator()])
Exemple #11
0
 class TestConfig(Config):
     l = Variable(kind=list)
Exemple #12
0
 class _Config(Config):
     var = Variable("The Name", kind=list)
Exemple #13
0
 class TestConfig(Config):
     v1 = Variable()
     v2 = Variable()
Exemple #14
0
 def test_validator_list__default(self):
     """
     verify that each Variable has a validator_list and that by default,
     that list contains a KindValidator as the first element
     """
     self.assertEqual(Variable().validator_list, [KindValidator])
Exemple #15
0
 def test_section(self):
     v1 = Variable()
     self.assertEqual(v1.section, 'DEFAULT')
     v2 = Variable(section='foo')
     self.assertEqual(v2.section, 'foo')
Exemple #16
0
 class TestConfig(Config):
     v = Variable()
Exemple #17
0
class Provider1Definition(Config):
    """
    A Config-like class for parsing plainbox provider definition files

    .. note::

        The location attribute is special, if set, it defines the base
        directory of *all* the other directory attributes. If location is
        unset, then all the directory attributes default to None (that is,
        there is no directory of that type). This is actually a convention that
        is implemented in :class:`Provider1PlugIn`. Here, all the attributes
        can be Unset and their validators only check values other than Unset.
    """

    location = Variable(
        section='PlainBox Provider',
        help_text=_("Base directory with provider data"),
        validator_list=[
            # NOTE: it *can* be unset!
            NotEmptyValidator(),
            AbsolutePathValidator(),
            ExistingDirectoryValidator(),
        ])

    name = Variable(section='PlainBox Provider',
                    help_text=_("Name of the provider"),
                    validator_list=[
                        NotUnsetValidator(),
                        NotEmptyValidator(),
                        IQNValidator(),
                    ])

    @property
    def name_without_colon(self):
        return self.name.replace(':', '.')

    version = Variable(section='PlainBox Provider',
                       help_text=_("Version of the provider"),
                       validator_list=[
                           NotUnsetValidator(),
                           NotEmptyValidator(),
                           VersionValidator(),
                       ])

    description = Variable(section='PlainBox Provider',
                           help_text=_("Description of the provider"))

    gettext_domain = Variable(
        section='PlainBox Provider',
        help_text=_("Name of the gettext domain for translations"),
        validator_list=[
            # NOTE: it *can* be unset!
            PatternValidator("[a-z0-9_-]+"),
        ])

    @property
    def effective_gettext_domain(self):
        """
        effective value of gettext_domian

        The effective value is :meth:`gettex_domain` itself, unless it is
        Unset. If it is Unset the effective value None.
        """
        if self.gettext_domain is not Unset:
            return self.gettext_domain

    jobs_dir = Variable(
        section='PlainBox Provider',
        help_text=_("Pathname of the directory with job definitions"),
        validator_list=[
            # NOTE: it *can* be unset
            NotEmptyValidator(),
            AbsolutePathValidator(),
            ExistingDirectoryValidator(),
        ])

    @property
    def implicit_jobs_dir(self):
        """
        implicit value of jobs_dir (if Unset)

        The implicit value is only defined if location is not Unset. It is the
        'jobs' subdirectory of the directory that location points to.
        """
        if self.location is not Unset:
            return os.path.join(self.location, "jobs")

    @property
    def effective_jobs_dir(self):
        """
        effective value of jobs_dir

        The effective value is :meth:`jobs_dir` itself, unless it is Unset. If
        it is Unset the effective value is the :meth:`implicit_jobs_dir`, if
        that value would be valid. The effective value may be None.
        """
        if self.jobs_dir is not Unset:
            return self.jobs_dir
        implicit = self.implicit_jobs_dir
        if implicit is not None and os.path.isdir(implicit):
            return implicit

    whitelists_dir = Variable(
        section='PlainBox Provider',
        help_text=_("Pathname of the directory with whitelists definitions"),
        validator_list=[
            # NOTE: it *can* be unset
            NotEmptyValidator(),
            AbsolutePathValidator(),
            ExistingDirectoryValidator(),
        ])

    @property
    def implicit_whitelists_dir(self):
        """
        implicit value of whitelists_dir (if Unset)

        The implicit value is only defined if location is not Unset. It is the
        'whitelists' subdirectory of the directory that location points to.
        """
        if self.location is not Unset:
            return os.path.join(self.location, "whitelists")

    @property
    def effective_whitelists_dir(self):
        """
        effective value of whitelists_dir

        The effective value is :meth:`whitelists_dir` itself, unless it is
        Unset. If it is Unset the effective value is the
        :meth:`implicit_whitelists_dir`, if that value would be valid. The
        effective value may be None.
        """
        if self.whitelists_dir is not Unset:
            return self.whitelists_dir
        implicit = self.implicit_whitelists_dir
        if implicit is not None and os.path.isdir(implicit):
            return implicit

    data_dir = Variable(
        section='PlainBox Provider',
        help_text=_("Pathname of the directory with provider data"),
        validator_list=[
            # NOTE: it *can* be unset
            NotEmptyValidator(),
            AbsolutePathValidator(),
            ExistingDirectoryValidator(),
        ])

    @property
    def implicit_data_dir(self):
        """
        implicit value of data_dir (if Unset)

        The implicit value is only defined if location is not Unset. It is the
        'data' subdirectory of the directory that location points to.
        """
        if self.location is not Unset:
            return os.path.join(self.location, "data")

    @property
    def effective_data_dir(self):
        """
        effective value of data_dir

        The effective value is :meth:`data_dir` itself, unless it is Unset. If
        it is Unset the effective value is the :meth:`implicit_data_dir`, if
        that value would be valid. The effective value may be None.
        """
        if self.data_dir is not Unset:
            return self.data_dir
        implicit = self.implicit_data_dir
        if implicit is not None and os.path.isdir(implicit):
            return implicit

    bin_dir = Variable(
        section='PlainBox Provider',
        help_text=_("Pathname of the directory with provider executables"),
        validator_list=[
            # NOTE: it *can* be unset
            NotEmptyValidator(),
            AbsolutePathValidator(),
            ExistingDirectoryValidator(),
        ])

    @property
    def implicit_bin_dir(self):
        """
        implicit value of bin_dir (if Unset)

        The implicit value is only defined if location is not Unset. It is the
        'bin' subdirectory of the directory that location points to.
        """
        if self.location is not Unset:
            return os.path.join(self.location, "bin")

    @property
    def effective_bin_dir(self):
        """
        effective value of bin_dir

        The effective value is :meth:`bin_dir` itself, unless it is Unset. If
        it is Unset the effective value is the :meth:`implicit_bin_dir`, if
        that value would be valid. The effective value may be None.
        """
        if self.bin_dir is not Unset:
            return self.bin_dir
        implicit = self.implicit_bin_dir
        if implicit is not None and os.path.isdir(implicit):
            return implicit

    locale_dir = Variable(
        section='PlainBox Provider',
        help_text=_("Pathname of the directory with locale data"),
        validator_list=[
            # NOTE: it *can* be unset
            NotEmptyValidator(),
            AbsolutePathValidator(),
            ExistingDirectoryValidator(),
        ])

    @property
    def implicit_locale_dir(self):
        """
        implicit value of locale_dir (if Unset)

        The implicit value is only defined if location is not Unset. It is the
        'locale' subdirectory of the directory that location points to.
        """
        if self.location is not Unset:
            return os.path.join(self.location, "locale")

    @property
    def implicit_build_locale_dir(self):
        """
        implicit value of locale_dir (if Unset) as laid out in the source tree

        This value is only applicable to source layouts, where the built
        translation catalogs are in the build/mo directory.
        """
        if self.location is not Unset:
            return os.path.join(self.location, "build", "mo")

    @property
    def effective_locale_dir(self):
        """
        effective value of locale_dir

        The effective value is :meth:`locale_dir` itself, unless it is Unset.
        If it is Unset the effective value is the :meth:`implicit_locale_dir`,
        if that value would be valid. The effective value may be None.
        """
        if self.locale_dir is not Unset:
            return self.locale_dir
        implicit1 = self.implicit_locale_dir
        if implicit1 is not None and os.path.isdir(implicit1):
            return implicit1
        implicit2 = self.implicit_build_locale_dir
        if implicit2 is not None and os.path.isdir(implicit2):
            return implicit2