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))
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))