class Test_Patent_XMLElement(unittest.TestCase):
    def setUp(self):
        testfile = 'fixtures/xml/ipg120327.one.xml'
        self.patent = Patent(open(testfile))
        self.assertTrue(self.patent)

    def test_flatten(self):
        testlist = [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
        reslist = self.patent._flatten(testlist)
        goallist = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
        self.assertTrue(reslist == goallist, \
            "{0}\nshould be\n{1}".format(reslist,goallist))

    def test_extend_padding(self):
        testlist = [[1, 2, 3], [4, 5], [5, 6, 7, 8]]
        reslist = self.patent._extend_padding(testlist, 0)
        goallist = [[1, 2, 3, 0], [4, 5, 0, 0], [5, 6, 7, 8]]
        self.assertTrue(reslist == goallist, \
            "{0}\nshould be\n{1}".format(reslist,goallist))

    def test_extend_padding_string(self):
        testlist = [['a', 'b', 'c'], ['d']]
        reslist = self.patent._extend_padding(testlist)
        goallist = [['a', 'b', 'c'], ['d', '', '']]
        self.assertTrue(reslist == goallist, \
            "{0}\nshould be\n{1}".format(reslist,goallist))

    def test_flatten_with_extend(self):
        testlist = [[1, 4, 7], [2, 5, 8], [3, 6]]
        testlist = self.patent._extend_padding(testlist, 0)
        reslist = self.patent._flatten(testlist)
        goallist = [[1, 2, 3], [4, 5, 6], [7, 8, 0]]
        self.assertTrue(reslist == goallist, \
            "{0}\nshould be\n{1}".format(reslist,goallist))

    def test_flatten_with_extend_multiple(self):
        testlist = [[1, 4, 7], [2], [3, 6]]
        testlist = self.patent._extend_padding(testlist, 0)
        reslist = self.patent._flatten(testlist)
        goallist = [[1, 2, 3], [4, 0, 6], [7, 0, 0]]
        self.assertTrue(reslist == goallist, \
            "{0}\nshould be\n{1}".format(reslist,goallist))

    def test_escape_html_nosub(self):
        teststring = "<tag1> ampersand here: & </tag1>"
        resstring = self.patent._escape_html_nosub(teststring)
        goalstring = html_escape(teststring)
        self.assertTrue(resstring == goalstring, \
            "{0}\nshould be\n{1}".format(resstring,goalstring))

    def test_escape_html_nosub(self):
        substart = "<sub>"
        subend = "</sub>"
        teststring = "<escape & skip sub tags>"
        resstring = self.patent._escape_html_nosub(substart + teststring +
                                                   subend)
        goalstring = substart + html_escape(teststring) + subend
        self.assertTrue(resstring == goalstring, \
            "{0}\nshould be\n{1}".format(resstring,goalstring))
Esempio n. 2
0
class Test_Patent_XMLElement(unittest.TestCase):
    def setUp(self):
        testfile = 'fixtures/xml/ipg120327.one.xml'
        self.patent = Patent(open(testfile))
        self.assertTrue(self.patent)

    def test_flatten(self):
        testlist = [ [1,4,7], [2,5,8], [3,6,9] ]
        reslist = self.patent._flatten(testlist)
        goallist = [ [1,2,3], [4,5,6], [7,8,9] ]
        self.assertTrue(reslist == goallist, \
            "{0}\nshould be\n{1}".format(reslist,goallist))

    def test_extend_padding(self):
        testlist = [ [1,2,3], [4,5], [5,6,7,8] ]
        reslist = self.patent._extend_padding(testlist,0)
        goallist = [ [1,2,3,0], [4,5,0,0], [5,6,7,8] ]
        self.assertTrue(reslist == goallist, \
            "{0}\nshould be\n{1}".format(reslist,goallist))

    def test_extend_padding_string(self):
        testlist = [ ['a','b','c'], ['d'] ]
        reslist = self.patent._extend_padding(testlist)
        goallist = [ ['a','b','c'], ['d','',''] ]
        self.assertTrue(reslist == goallist, \
            "{0}\nshould be\n{1}".format(reslist,goallist))

    def test_flatten_with_extend(self):
        testlist = [ [1,4,7], [2,5,8], [3,6] ]
        testlist = self.patent._extend_padding(testlist,0)
        reslist = self.patent._flatten(testlist)
        goallist = [ [1,2,3], [4,5,6], [7,8,0] ]
        self.assertTrue(reslist == goallist, \
            "{0}\nshould be\n{1}".format(reslist,goallist))

    def test_flatten_with_extend_multiple(self):
        testlist = [ [1,4,7], [2], [3,6] ]
        testlist = self.patent._extend_padding(testlist,0)
        reslist = self.patent._flatten(testlist)
        goallist = [ [1,2,3], [4,0,6], [7,0,0] ]
        self.assertTrue(reslist == goallist, \
            "{0}\nshould be\n{1}".format(reslist,goallist))

    def test_escape_html_nosub(self):
        teststring = "<tag1> ampersand here: & </tag1>"
        resstring = self.patent._escape_html_nosub(teststring)
        goalstring = html_escape(teststring)
        self.assertTrue(resstring == goalstring, \
            "{0}\nshould be\n{1}".format(resstring,goalstring))

    def test_escape_html_nosub(self):
        substart = "<sub>"
        subend = "</sub>"
        teststring = "<escape & skip sub tags>"
        resstring = self.patent._escape_html_nosub(substart+teststring+subend)
        goalstring = substart+html_escape(teststring)+subend
        self.assertTrue(resstring == goalstring, \
            "{0}\nshould be\n{1}".format(resstring,goalstring))
Esempio n. 3
0
 def setUp(self):
     testfile = 'fixtures/xml/ipg120327.one.xml'
     self.patent = Patent(open(testfile))
     self.assertTrue(self.patent)
from xml.sax import make_parser, handler

sys.path.append('../lib')
from patXML import *

# Directory of test files
basedir = os.curdir
testdir = os.path.join(basedir, 'fixtures/unittest/fixtures/')
xml_files = [x for x in os.listdir(testdir)
             if re.match(r"20\d\d_\d.xml", x) != None] # Match fixtures

parsed_xml_old = []
parsed_xml_new = []
for xf in xml_files:
    old = XMLPatentBase(open(testdir+xf).read())
    new = Patent(open(testdir+xf))
    parsed_xml_old.append(old)
    parsed_xml_new.append(new)

class Test_Compatibility(unittest.TestCase):
    def setUp(self):
        # sanity check
        self.assertTrue(xml_files)

    def test_country(self):
        for old,new in zip(parsed_xml_old, parsed_xml_new):
            self.assertTrue( old.country == new.country, "{0}\nshould be\n{1}".format(new.country,old.country))

    def test_patent(self):
        for old,new in zip(parsed_xml_old, parsed_xml_new):
            self.assertTrue( old.patent == new.patent, "{0}\nshould be\n{1}".format(new.patent,old.patent))
 def setUp(self):
     testfile = 'fixtures/xml/ipg120327.one.xml'
     self.patent = Patent(open(testfile))
     self.assertTrue(self.patent)