File: testError.py

package info (click to toggle)
blahtexml 1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,092 kB
  • sloc: cpp: 10,929; xml: 402; python: 302; ansic: 282; makefile: 99
file content (50 lines) | stat: -rw-r--r-- 1,395 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python

from subprocess import Popen, PIPE, STDOUT
import unittest
import xml.etree.ElementTree as ET

class ErrorTests(unittest.TestCase):
	def setUp(self):
		print("")
	
	def validateError(self, input, errorId, startPos, length):
		p = Popen(['../Build/blahtex', '--mathml'], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
		
		p.stdin.write(input)
		p.stdin.close()
		p.wait()
		
		rootNode = ET.fromstring(p.stdout.read())
		
		errorNode = rootNode.find("error")
		
		self.assertEqual(errorNode.find("id").text, errorId)
		self.assertEqual(int(errorNode.find("startPos").text), startPos)
		self.assertEqual(int(errorNode.find("length").text), length)


class BraceErrorTests(ErrorTests):
	def testOpenBrace(self):
		self.validateError("2^{5", "UnmatchedOpenBrace", 2, 1)
		self.validateError("4^{6 * 2^{5", "UnmatchedOpenBrace", 2, 1)
		self.validateError("4^{6} * 2^{5", "UnmatchedOpenBrace", 10, 1)
		self.validateError("2^{2{5}", "UnmatchedOpenBrace", 2, 1)
	
	def testCloseBrace(self):
		self.validateError("2^5}", "UnmatchedCloseBrace", 3, 1)


class CharErrorTests(ErrorTests):
	def testIllegalFinalBackslash(self):
		self.validateError("2\\", "IllegalFinalBackslash", 1, 1)


class RecognitionErrorTests(ErrorTests):
	def testUnrecognisedCommand(self):
		self.validateError("2 + \\testingwrongcommand", "UnrecognisedCommand", 4, 20)


if __name__ == '__main__':
	unittest.main()