def test_comparison_works(self): self.assertTrue(NotEmptyValidator() == NotEmptyValidator()) self.assertTrue(NotEmptyValidator("?") == NotEmptyValidator("?")) self.assertTrue(NotEmptyValidator() != NotEmptyValidator("?")) self.assertTrue(NotEmptyValidator() != object())
def test_isnt_broken(self): validator = NotEmptyValidator() self.assertEqual(validator(self._Config.var, "some value"), None)
def test_rejects_empty_values(self): validator = NotEmptyValidator() self.assertEqual(validator(self._Config.var, ""), "cannot be empty")
def test_supports_custom_message(self): validator = NotEmptyValidator("name required!") self.assertEqual(validator(self._Config.var, ""), "name required!")
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