Permalink
Browse files

Simple test for barebone example

  • Loading branch information...
pneff committed May 26, 2008
1 parent c373f02 commit 5311b63c69c9fdf8308e8b624d2a5c1808a30524
View
@@ -0,0 +1,16 @@
+import sys
+import antlr3
+from servicegenLexer import servicegenLexer
+from servicegenParser import servicegenParser
+
+class Service:
+ """Parses a service description and returns the parse tree."""
+ def parse(self, file):
+ f = open(file, "r")
+ char_stream = antlr3.ANTLRStringStream(f.read())
+ f.close()
+
+ lexer = servicegenLexer(char_stream)
+ tokens = antlr3.CommonTokenStream(lexer)
+ parser = servicegenParser(tokens)
+ return parser.declaration()
View
@@ -0,0 +1,8 @@
+#!/usr/bin/python
+import unittest
+from tests.parser.SimpleParserTest import SimpleParserTest
+
+if __name__ == '__main__':
+ suite = unittest.TestLoader().loadTestsFromTestCase(SimpleParserTest)
+ unittest.TextTestRunner(verbosity=2).run(suite)
+
View
No changes.
@@ -0,0 +1,23 @@
+import unittest
+from parser.Service import Service
+from parser.servicegenLexer import servicegenLexer
+from tools.Service import DumpTree
+
+class SimpleParserTest(unittest.TestCase):
+ def testBasic(self):
+ """
+ Tests parsing of a very basic service. Just contains the service
+ name, nothing else.
+ """
+ service = self._parseService("basic.txt")
+ root = service.tree
+ self.assertEqual(root.getChild(0).getText(), 'service')
+ self.assertEqual(root.getChild(1).getText(), 'meteo')
+
+ def _parseService(self, service):
+ """Parses the service from the given file."""
+ s = Service()
+ return s.parse("tests/services/" + service)
+
+if __name__ == '__main__':
+ unittest.main()
View
No changes.
View
@@ -0,0 +1 @@
+service meteo;

0 comments on commit 5311b63

Please sign in to comment.