def test_name(self): """ The C{name} attribute of a L{NamedConstant} refers to the value passed for the C{name} parameter to C{_realize}. """ name = NamedConstant() name._realize(self.container, "bar", None) self.assertEqual("bar", name.name)
def test_representation(self): """ The string representation of an instance of L{NamedConstant} includes the container the instances belongs to as well as the instance's name. """ name = NamedConstant() name._realize(self.container, "bar", None) self.assertEqual("<foo=bar>", repr(name))
def test_equality(self): """ A L{NamedConstant} instance compares equal to itself. """ name = NamedConstant() name._realize(self.container, "bar", None) self.assertTrue(name == name) self.assertFalse(name != name)
def matchExpression(fieldName, matchString, matchType, matchFlags): # special case recordType field if fieldName == FieldName.recordType: # change kind to record type matchValue = vCardKindToRecordTypeMap.get(matchString.lower()) if matchValue is None: matchValue = NamedConstant() matchValue.description = u"" # change types and flags matchFlags &= ~MatchFlags.caseInsensitive matchType = MatchType.equals else: matchValue = matchString.decode("utf-8") return MatchExpression(fieldName, matchValue, matchType, matchFlags)
def test_hash(self): """ Because two different L{NamedConstant} instances do not compare as equal to each other, they also have different hashes to avoid collisions when added to a C{dict} or C{set}. """ first = NamedConstant() first._realize(self.container, "bar", None) second = NamedConstant() second._realize(self.container, "bar", None) self.assertNotEqual(hash(first), hash(second))
def test_nonequality(self): """ Two different L{NamedConstant} instances do not compare equal to each other. """ first = NamedConstant() first._realize(self.container, "bar", None) second = NamedConstant() second._realize(self.container, "bar", None) self.assertFalse(first == second) self.assertTrue(first != second)
class Environments(Names): """ The environments that documentation can be published to. """ PRODUCTION = NamedConstant() STAGING = NamedConstant()
class BranchType(Names): master = NamedConstant() release = NamedConstant() maintenance = NamedConstant() development = NamedConstant()
class ThreadWorkerState(Names): STOPPED = NamedConstant() RUNNING = NamedConstant()
class UnknownConstant(Names): unknown = NamedConstant()
class Input(Names): apple = NamedConstant()
class DatasetBackend(Names): loopback = NamedConstant() zfs = NamedConstant() aws = NamedConstant() openstack = NamedConstant()
class RecordType(Names): macOSXServerWiki = NamedConstant() macOSXServerWiki.description = u"Mac OS X Server Wiki"
class STATE(Names): FOLLOWER = NamedConstant() CANDIDATE = NamedConstant() LEADER = NamedConstant()
class LDAPMatchType(Names): """ LDAP match types. For each constant defined, if there is an equivalent L{MatchType} constant, the attribute C{matchType} reference that constant. It is otherwise unset. For each constant defined, the attribute C{queryString} will be a L{unicode} format string that, when formatted, is an LDAP query string (eg. C{(attribute=value)}). The format string may reference the following names: - C{notOp} for the "not" operator, which may be C{u"!"} or C{u""}. - C{attribute} for the name of the LDAP attribute to match. - C{value} for the value to match against. @cvar any: Attribute has any value. @cvar equals: Attribute equals value. @cvar startsWith: Attribute starts with value. @cvar endsWith: Attribute ends with value. @cvar contains: Attribute contains value. @cvar lessThan: Attribute is less than value. @cvar greaterThan: Attribute is greater than value. @cvar lessThanOrEqualTo: Attribute is less than or equal to value. @cvar greaterThanOrEqualTo: Attribute is greater than or equal to value. """ any = NamedConstant() any.queryString = u"({notOp}{attribute}=*)" equals = NamedConstant() equals.matchType = MatchType.equals equals.queryString = u"({notOp}{attribute}={value})" startsWith = NamedConstant() startsWith.matchType = MatchType.startsWith startsWith.queryString = u"({notOp}{attribute}={value}*)" endsWith = NamedConstant() endsWith.matchType = MatchType.endsWith endsWith.queryString = u"({notOp}{attribute}=*{value})" contains = NamedConstant() contains.matchType = MatchType.contains contains.queryString = u"({notOp}{attribute}=*{value}*)" lessThan = NamedConstant() lessThan.matchType = MatchType.lessThan lessThan.queryString = u"({notOp}{attribute}<{value})" greaterThan = NamedConstant() greaterThan.matchType = MatchType.greaterThan greaterThan.queryString = u"({notOp}{attribute}>{value})" lessThanOrEqualTo = NamedConstant() lessThanOrEqualTo.matchType = MatchType.lessThanOrEqualTo lessThanOrEqualTo.queryString = u"({notOp}{attribute}<={value})" greaterThanOrEqualTo = NamedConstant() greaterThanOrEqualTo.matchType = MatchType.greaterThanOrEqualTo greaterThanOrEqualTo.queryString = u"({notOp}{attribute}>={value})" @classmethod def fromMatchType(cls, matchType): """ Look up an L{LDAPMatchType} from a L{MatchType}. @param matchType: A match type. @type matchType: L{MatchType} @return: The cooresponding LDAP match type. @rtype: L{LDAPMatchType} """ if not hasattr(cls, "_matchTypeByMatchType"): cls._matchTypeByMatchType = dict( ((matchType.matchType, matchType) for matchType in cls.iterconstants() if hasattr(matchType, "matchType"))) return cls._matchTypeByMatchType.get(matchType, None)
class MoreNamedLetters(Names): """ Some more letters, named. """ digamma = NamedConstant() zeta = NamedConstant()
class NamedLetters(Names): """ Some letters, named. """ alpha = NamedConstant() beta = NamedConstant()
class WikiAccessLevel(Names): none = NamedConstant() read = NamedConstant() write = NamedConstant()
class FieldName(Names): memberUIDs = NamedConstant() memberUIDs.description = u"member UIDs" memberUIDs.multiValue = True