class BibTex_Conversion_Tests(unittest.TestCase): test_data = os.path.join(os.path.dirname(__file__), 'test_data') def setUp(self): self.impl = BibtexParser() def test_conversion(self): test_data = read_utf8_data(os.path.join(self.test_data, "latex_encoded_characters.bib")) results = self.impl.parseString(test_data, parseAll=True) print self.impl.dump_rdf_to_bib_string(results)
class BibTex_Tests(unittest.TestCase): test_data = os.path.join(os.path.dirname(__file__), 'test_data') def setUp(self): model = Model() model.config = config_helper(UserConfig(dir_name=".gref", config_file="config")) self.impl = BibtexParser(model) self.parser = self.impl.create_parser() def dump_rdf(self, results, format="pretty-xml"): for i in results[0]: graph = create_graph() internal_rdf_dict_to_graph(i, results[0][i], graph) print graph.serialize(format=format) def test_empty_field(self): test_data = read_utf8_data(os.path.join(self.test_data, "empty_field.bib")) results = self.impl.parseString(test_data, parseAll=True) self.dump_rdf(results, format="n3") print self.impl.dump_rdf_to_bib_string(results) def test_duplicate_fields(self): test_data = read_utf8_data(os.path.join(self.test_data, "duplicate_field_name.bib")) results = self.impl.parseString(test_data, parseAll=True) self.dump_rdf(results, format="n3") print self.impl.dump_rdf_to_bib_string(results) def test_latex_encoding(self): test_data = read_utf8_data(os.path.join(self.test_data, "latex_encoded_characters.bib")) results = self.impl.parseString(test_data, parseAll=True) self.dump_rdf(results, format="n3") print self.impl.dump_rdf_to_bib_string(results) def test_web_page(self): test_data = read_utf8_data(os.path.join(self.test_data, "web_reference.bib")) results = self.impl.parseString(test_data, parseAll=True) pprint(results) self.dump_rdf(results, format="n3") print self.impl.dump_rdf_to_bib_string(results) def test_book(self): test_data = read_utf8_data(os.path.join(self.test_data, "book.bib")) results = self.impl.parseString(test_data, parseAll=True) self.dump_rdf(results, format="n3") print self.impl.dump_rdf_to_bib_string(results) def test_non_alphanum_char_in_keys(self): test_data = read_utf8_data(os.path.join(self.test_data, "non-alphanum_char_in_keys.bib")) results = self.impl.parseString(test_data, parseAll=True) self.dump_rdf(results, format="n3") print self.impl.dump_rdf_to_bib_string(results) def test_incomplete_second_entry(self): with self.assertRaises(ParseException): test_data = read_utf8_data(os.path.join(self.test_data, "incomplete_second_entry.bib")) results = self.parser.parseString(test_data, parseAll=True) def test_scopus_conference(self): test_data = read_utf8_data(os.path.join(self.test_data, "scopus_conference.bib")) results = self.impl.parseString(test_data, parseAll=True) self.dump_rdf(results, format="n3") print self.impl.dump_rdf_to_bib_string(results) def test_tandf_conference(self): test_data = read_utf8_data(os.path.join(self.test_data, "tandf.bib")) results = self.impl.parseString(test_data, parseAll=True) self.dump_rdf(results, format="n3") print self.impl.dump_rdf_to_bib_string(results) def test_springerlink(self): test_data = read_utf8_data(os.path.join(self.test_data, "springerlink.bib")) results = self.impl.parseString(test_data, parseAll=True) self.dump_rdf(results, format="n3") print self.impl.dump_rdf_to_bib_string(results)