def setUp(self): kitchen_sink_xml = os.path.join(os.getcwd(), 'sample-xml/elife-kitchen-sink.xml') # all of these methods are equivalent: #self.soup = bss(open(kitchen_sink_xml, 'r').read()) #self.soup = parser.parse_xml(open(kitchen_sink_xml, 'r')) self.soup = parser.parse_document(kitchen_sink_xml)
def setUp(self): kitchen_sink_xml = sample_xml('elife-kitchen-sink.xml') # all of these methods are equivalent: #self.soup = bss(open(kitchen_sink_xml, 'r').read()) #self.soup = parser.parse_xml(open(kitchen_sink_xml, 'r')) self.soup = parser.parse_document(kitchen_sink_xml)
def test_quickly(self): struct = [ (parser.doi, u"10.7554/eLife.00013"), (parser.journal_id, u"eLife"), (parser.journal_title, u"eLife"), #(parser.journal_issn, u"2050-084X"), (parser.publisher, u"eLife Sciences Publications, Ltd"), ] for func, expected in struct: soup = parser.parse_document(self.kitchen_sink_xml) got = func(soup) try: self.assertEqual(got, expected) except AssertionError: print 'failed on',func,'expected',expected,'got',got raise soup = parser.parse_document(self.kitchen_sink_xml) self.assertEqual(parser.journal_issn(soup, pub_format="electronic"), u"2050-084X")
def test_quickly(self): struct = [ (parser.doi, u"10.7554/eLife.00013"), (parser.journal_id, u"eLife"), (parser.journal_title, u"eLife"), #(parser.journal_issn, u"2050-084X"), (parser.publisher, u"eLife Sciences Publications, Ltd"), ] for func, expected in struct: soup = parser.parse_document(self.kitchen_sink_xml) got = func(soup) try: self.assertEqual(got, expected) except AssertionError: print 'failed on', func, 'expected', expected, 'got', got raise soup = parser.parse_document(self.kitchen_sink_xml) self.assertEqual(parser.journal_issn(soup, pub_format="electronic"), u"2050-084X")
def test_decision_letter(self, filename, expected_type): soup = parser.parse_document(sample_xml(filename)) self.assertEqual(type(raw_parser.decision_letter(soup)), expected_type)
def test_author_response(self, filename, expected_type): soup = parser.parse_document(sample_xml(filename)) self.assertEqual(type(raw_parser.author_response(soup)), expected_type)
def test_article_body(self, filename, expected_type): soup = parser.parse_document(sample_xml(filename)) self.assertEqual(type(raw_parser.article_body(soup)), expected_type)
def test_sub_article(self, filename, expected_len): soup = parser.parse_document(sample_xml(filename)) self.assertEqual(len(raw_parser.sub_article(soup)), expected_len)
def test_quickly2(self): soup = parser.parse_document(self.xml) self.assertEqual(raw_parser.article_type(soup), "research-article")
def test_abstract(self, filename, expected_len): soup = parser.parse_document(sample_xml(filename)) self.assertEqual(len(raw_parser.abstract(soup)), expected_len)
for filename in xml_filenames: if not os.path.exists(json_expected_folder(filename)): os.mkdir(json_expected_folder(filename)) # Output json files for testing expected output for function_attrs in json_functions: if type(function_attrs) == str: function_name = function_attrs function_arguments = None elif type(function_attrs) == tuple: function_name = function_attrs[0] if type(function_attrs[1]) == tuple: function_arguments = function_attrs[1] else: print "arguments for function " + function_name + " must be a tuple" soup = parser.parse_document(sample_xml(filename)) if function_arguments: result = getattr(parser, function_name)(soup, *function_arguments) else: result = getattr(parser, function_name)(soup) if result is not None: print "writing " + json_expected_file(filename, function_name) with open(json_expected_file(filename, function_name), "wb") as json_file_fp: json_file_fp.write(json.dumps(result, indent=4))
def test_mixed_citations(self): self.soup = parser.parse_document(sample_xml('elife-kitchen-sink.xml')) self.assertEqual(1, len(raw_parser.mixed_citations(self.soup)))
def test_funding_group(self, filename, expected_len): soup = parser.parse_document(sample_xml(filename)) self.assertEqual(len(raw_parser.funding_group(soup)), expected_len)
def test_fn_group(self, filename, content_type, expected_len): soup = parser.parse_document(sample_xml(filename)) self.assertEqual(len(raw_parser.fn_group(soup, content_type)), expected_len)
def test_pub_id_uri(self, filename, ext_link_type, expected_len): soup = parser.parse_document(sample_xml(filename)) self.assertEqual(len(raw_parser.ext_link(soup, ext_link_type)), expected_len)
def setUp(self): self.kitchen_sink_xml = sample_xml('elife-kitchen-sink.xml') self.xml = sample_xml('elife00013.xml') self.soup = parser.parse_document(self.kitchen_sink_xml)
def test_disp_formula(self, filename, expected_len): soup = parser.parse_document(sample_xml(filename)) self.assertEqual(len(raw_parser.disp_formula(soup)), expected_len)
def test_table_wrap_foot(self, filename, expected_len): soup = parser.parse_document(sample_xml(filename)) self.assertEqual(len(raw_parser.table_wrap_foot(soup)), expected_len)
def setUp(self): self.kitchen_sink_xml = os.path.join(os.getcwd(), 'sample-xml/elife-kitchen-sink.xml') self.xml = os.path.join(os.getcwd(), 'sample-xml/elife00013.xml') self.soup = parser.parse_document(self.kitchen_sink_xml)
def test_principal_award_recipient(self, filename, expected_len): soup = parser.parse_document(sample_xml(filename)) self.assertEqual(len(raw_parser.principal_award_recipient(soup)), expected_len)