コード例 #1
0
	def testGetNamespace(self):
		"""
		This method tests :func:`foundations.namespace.getNamespace` definition.
		"""

		self.assertIsInstance(namespace.getNamespace("Namespace:Attribute", ":"), str)
		self.assertEqual(namespace.getNamespace("Namespace|Attribute"), "Namespace")
		self.assertEqual(namespace.getNamespace("Namespace:Attribute", ":"), "Namespace")
		self.assertEqual(namespace.getNamespace("Namespace|Attribute|Value", rootOnly=True), "Namespace")
		self.assertIsNone(namespace.getNamespace("Namespace"))
コード例 #2
0
	def testAttributeExists(self):
		"""
		This method tests :meth:`foundations.parsers.SectionsFileParser.attributeExists` method.
		"""

		for type, file in STANDARD_FILES.iteritems():
			sectionsFileParser = SectionsFileParser(file)
			sectionsFileParser.read() and sectionsFileParser.parse(False, rawSections=STANDARD_FILES_RAW_SECTIONS[type])
			for attribute in RANDOM_ATTRIBUTES[type]:
				self.assertTrue(sectionsFileParser.attributeExists(attribute, namespace.getNamespace(attribute,
																									rootOnly=True)))
				self.assertFalse(sectionsFileParser.attributeExists("Unknown", namespace.getNamespace(attribute,
																									rootOnly=True)))
コード例 #3
0
	def testGetValue(self):
		"""
		This method tests :meth:`foundations.parsers.SectionsFileParser.getValue` method.
		"""

		for type, file in STANDARD_FILES.iteritems():
			sectionsFileParser = SectionsFileParser(file)
			sectionsFileParser.read() and sectionsFileParser.parse(False, rawSections=STANDARD_FILES_RAW_SECTIONS[type])
			for attribute, value in RANDOM_ATTRIBUTES[type].iteritems():
				self.assertIsInstance(sectionsFileParser.getValue(attribute, namespace.getNamespace(attribute,
																									rootOnly=True)), str)
				self.assertIsInstance(sectionsFileParser.getValue(attribute, namespace.getNamespace(attribute,
																									rootOnly=True),
																									encode=True), unicode)
				self.assertEqual(sectionsFileParser.getValue(attribute, namespace.getNamespace(attribute,
																								rootOnly=True)), value)
コード例 #4
0
	def registerModule(self, name, path):
		"""
		This method registers given module.

		:param name: Module name. ( String )
		:param path: Module path. ( Layout )
		:return: Method success. ( Boolean )
		"""

		if name in self:
			raise foundations.exceptions.ProgrammingError("{0} | '{1}' module is already registered!".format(
			self.__class__.__name__, name))

		name = namespace.getNamespace(name, rootOnly=True)
		self.__modules[name] = Module(name=name, path=os.path.dirname(path))
		return True