Пример #1
0
	def test_load_recursiveArray(self):
		ns = namespace.loads(
			"list:\n"
			"  - key1: value1\n"
			)
		self.assertEqual(ns,
			namespace(list=[namespace(key1='value1')]))
Пример #2
0
	def test_subnamespaces(self) :
		ns = namespace()
		ns.sub = namespace()
		ns.sub.foo = "value1"
		ns.sub.bar = "value2"
		self.assertEqual(ns.dump(),
			"sub:\n"
			"  foo: value1\n"
			"  bar: value2\n"
			)
Пример #3
0
	def test_setattribute(self):
		ns = namespace()
		ns.lala = "boo"
		self.assertEqual(ns.lala, 'boo')
		self.assertEqual(ns['lala'], 'boo')
		self.assertEqual(ns.dump(),
			"lala: boo\n")
Пример #4
0
	def test_dump_float(self) :
		yamlcontent = (
			"decimal: 3.41\n"
			)
		ns = namespace()
		ns.decimal = 3.41
		self.assertEqual(ns.dump(),
			yamlcontent)
Пример #5
0
	def test_setattribute_differentOrder(self):
		ns = namespace()
		ns.lola = "foo"
		ns.lala = "boo"
		self.assertEqual(ns.dump(),
			"lola: foo\n"
			"lala: boo\n"
			)
Пример #6
0
	def test_delattribute(self):
		ns = namespace()
		ns.lola = "foo"
		ns.lala = "boo"
		del ns.lola
		self.assertEqual(ns.dump(),
			"lala: boo\n"
			)
Пример #7
0
	def test_dump_date(self):
		yamlcontent = (
			"adate: 2000-02-28\n"
			)
		ns = namespace()
		ns.adate = dateutils.Date(2000,2,28)
		self.assertEqual(ns.dump(),
			yamlcontent)
Пример #8
0
	def test_dump_decimal(self) :
		yamlcontent = (
			"decimal: 3.41\n"
			)
		ns = namespace()
		ns.decimal = decimal.Decimal('3.41')
		self.assertEqual(ns.dump(),
			yamlcontent)
Пример #9
0
	def test_setattribute_twice_overwrites(self):
		ns = namespace()
		ns.lala = "boo"
		ns.lala = "foo"
		self.assertEqual(ns.lala, 'foo')
		self.assertEqual(ns['lala'], 'foo')
		self.assertEqual(ns.dump(),
			"lala: foo\n")
Пример #10
0
	def test_setattribute_many(self):
		ns = namespace()
		ns.lala = "boo"
		ns.lola = "foo"
		self.assertEqual(ns.lola, 'foo')
		self.assertEqual(ns['lola'], 'foo')
		self.assertEqual(ns.dump(),
			"lala: boo\n"
			"lola: foo\n")
Пример #11
0
	def test_dump_toFile(self):
		data = namespace(otra=u'caña')
		data.dump('test.yaml')
		try:
			import codecs
			with codecs.open("test.yaml",encoding='utf-8') as f:
				result = f.read()
			self.assertEqual(result, u"otra: caña\n")
		except: raise
		finally:
			import os
			os.unlink("test.yaml")
Пример #12
0
	def test_load_fromFile(self):
		data = u"hi: caña\n"
		import codecs
		with codecs.open("test.yaml",'w',encoding='utf-8') as f:
			f.write(data)
		try:
			result = namespace.load("test.yaml")
			self.assertEqual(result,
				namespace(hi=u'caña'))
		except: raise
		finally:
			import os
			os.unlink("test.yaml")
Пример #13
0
	def test_construction_default(self):
		ns = namespace()
		self.assertEqual(ns.dump(),
			"{}\n")
Пример #14
0
	def test_load_empty(self):
		self.assertEqual(namespace.loads("{}"),
			namespace())
Пример #15
0
	def test_delattribute(self):
		ns = namespace()
		ns.lola = "foo"
		with self.assertRaises(AttributeError):
			del ns.notexisting
Пример #16
0
	def test_dir_withNonExistingAttributes(self):
		ns = namespace()
		ns.attr1 = 'value1'
		self.assertFalse('bad' in dir(ns))
Пример #17
0
	def test_dir_withExistingAttributes(self):
		ns = namespace()
		ns.attr1 = 'value1'
		self.assertTrue('attr1' in dir(ns))
Пример #18
0
	def test_dir_withNonIdentifierNames(self):
		ns = namespace()
		ns['a-b'] = 'value1'

		self.assertFalse('a-b' in dir(ns))