All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Lib.test.test_sax_jy.py Maven / Gradle / Ivy

Go to download

Jython is an implementation of the high-level, dynamic, object-oriented language Python written in 100% Pure Java, and seamlessly integrated with the Java platform. It thus allows you to run Python on any Java platform.

There is a newer version: 2.7.4
Show newest version
import sys
import StringIO
import unittest

from xml.sax import saxutils
from xml.sax import make_parser
from xml.sax.handler import feature_namespaces

from test import test_support

file = StringIO.StringIO("""
  
    Neil Gaiman
    Glyn Dillon
    Charles Vess
  
  
    Peter Milligan
    Chris Bachalo
  
""")

class FindIssue(saxutils.DefaultHandler):
    def __init__(self, title, number):
        self.search_title, self.search_number = title, number
        self.match = 0

    def startElement(self,name,attrs):
        global match
        if name != 'comic' : return

        title = attrs.get('title', None)
        number = attrs.get('number',None)
        if title == self.search_title and number == self.search_number:
            self.match += 1

class SimpleSaxTest(unittest.TestCase):
    def test_find_issue(self):
        parser = make_parser()
        parser.setFeature(feature_namespaces,0)
        dh = FindIssue('Sandman', '62')
        parser.setContentHandler(dh)
        parser.parse(file)
        self.assertEquals(1, dh.match)
def test_main():
    test_support.run_unittest(SimpleSaxTest)

if __name__ == "__main__":
    test_main()




© 2015 - 2024 Weber Informatics LLC | Privacy Policy