Exemple #1
0
	def setUp(self):
		
		text = """<tag_1 list=[2,3,4,5,56 -4,] str="some kind of
cool s\\"tring thing">
	<tag_2 dict={"_yoma 7&m a":["yes" 5 7 ]  5:"funtimes", hello:958e40, }>
		<tag_3 attr=3940e10/>
	</tag_2>
	<tag_2 banana = 'she\\'s on fire!' yes=true />
</tag_1>"""
		
		self.root = _parse(text)
Exemple #2
0
	def test_mismatched_tags(self):
		with self.assertRaises(JXIParseError):
			_parse("""<tag arrt="something"><tag></tag></targ>""")

		_parse("""
    <person 
    	firstName="John"
    	lastName="Smith"
    	age=25
    	address={
    		streetAddress:"21 2nd Street"
    		city:"New York"
    		state:"NY"
    		postalCode:"10021"
    	}
    	phoneNumbers=[
    		{ type:"home" number:"212 555-1234" }
    		{ type:"fax"  number:"646 555-4567" }
    	]
    />
""")
Exemple #3
0
	def test_adding_and_removing_stuff(self):
		# check that stuff gets deleted properly
		del self.root["tag_2"][0][0] # delete tag_3
		self.assertEqual(len(self.root[0]), 0)
		del self.root["tag_2"]
		self.assertEqual(len(self.root), 0)

		with self.assertRaises(IndexError):
			del self.root[0]

		with self.assertRaises(KeyError):
			del self.root["tag_2"]

		# now try adding stuffs
		for i in range(10):
			self.root._add(_parse("<item id=%d />" % i))

		# print self.root[0]._tag_name
		# check they're all there
		for i in range(10):
			self.assertEqual(self.root[i].id, i)
			self.assertEqual(self.root["item"][i].id, i)


		# add some in the middle or something.
		# do it backwards to check if the reordering thingy works
		for i in range(4, -1, -1):
			self.root._add(_parse("<otheritem id=%d/>" % i), 5)

		# check that they're in the right place
		for i in range(5):
			self.assertEqual(self.root[i+5].id, i)
			self.assertEqual(self.root[i+5]._tag_name, "otheritem")
			self.assertEqual(self.root["otheritem"][i].id, i)
			
		# now do a weird one just to be sure
		self.root._add(_parse("<otheritem weird=true />"), 8)
		self.assertTrue(self.root[8].weird)
		self.assertTrue(self.root["otheritem"][3].weird)
Exemple #4
0
	def test_bad_closing_tag(self):
		with self.assertRaises(JXIParseError):
			_parse("""<tag arrt="something">""")

		with self.assertRaises(JXIParseError):
			_parse("""<tag arrt="something"><tag>""")

		with self.assertRaises(JXIParseError):
			_parse("""<tag arrt="something"<tag>""")
Exemple #5
0
	def test_bad_stuff_in_tag(self):
		with self.assertRaises(JXIParseError):
			_parse("""<tag arrt="something">s</tag>""")
		with self.assertRaises(JXIParseError):
			_parse("""<tag arrt="something">#</tag>""")
		with self.assertRaises(JXIParseError):
			_parse("""<tag arrt="something"><</tag>""")
		with self.assertRaises(JXIParseError):
			_parse("""<tag arrt="something">4</tag>""")
		with self.assertRaises(JXIParseError):
			_parse("""<tag arrt="something">"s"</tag>""")
		with self.assertRaises(JXIParseError):
			_parse("""<tag arrt="something">'yo'</tag>""")
Exemple #6
0
	def test_bad_attribute_name(self):
		with self.assertRaises(JXIParseError):
			_parse("""<tag _arrt="something"></tag>""")
		with self.assertRaises(JXIParseError):
			_parse("""<tag 4arrt="something"></tag>""")
Exemple #7
0
	def test_bad_attribute(self):
		with self.assertRaises(JXIParseError):
			_parse("""<tag arrt=something></tag>""")

		_parse("""<tag arrt=[1,2,"hello",true]></tag>""")
		with self.assertRaises(JXIParseError):
			_parse("""<tag arrt=[1,2,"hello",blah]></tag>""")
		with self.assertRaises(JXIParseError):
			_parse("""<tag arrt=[1,2,"hello",-]></tag>""")

		_parse("""<tag arrt={name:true, name2:false}></tag>""")
		with self.assertRaises(JXIParseError):
			_parse("""<tag arrt={name:true, name2:blah}></tag>""")
		with self.assertRaises(JXIParseError):
			_parse("""<tag arrt={name:true, name2:_}></tag>""")
Exemple #8
0
	def test_unclosed_string(self):
		with self.assertRaises(JXIParseError):
			_parse("""<tag arrt="something'></tag>""")

		with self.assertRaises(JXIParseError):
			_parse("""<tag arrt='something"></tag>""")
Exemple #9
0
	def test_decode(self):
		self.root = _parse(str(self.root))
		self.test_encode()
		self.test_adding_and_removing_stuff()