def test_first_middle(self): "first and middle name vs last" n = bibname.BibName("Alan Glen Isaac and Dylan Schwilk") self.assertEqual(n.get_names_dicts()[0]["first"][0], "Alan") self.assertEqual(n.get_names_dicts()[0]["first"][1], "Glen") self.assertEqual(n.get_names_dicts()[0]["last"][0], "Isaac") self.assertEqual(n.get_names_dicts()[1]["first"][0], "Dylan") self.assertEqual(n.get_names_dicts()[1]["last"][0], "Schwilk")
def make_names(self, entry_formatter=None, try_fields=None): """return (BibName-object if possible else string) (from "raw" names). :change: 2006-08-02 altered to return BibName instance and not set _names :note: self returns None if field missing (-> no KeyError) :note: this method introduces the only dependence on simpleparse (via bibname) :TODO: return BibName instance for each available name field?? :Parameters: - `entry_formatter`: EntryFormatter instance to provide style information - `try_fields`: list of field names to try sequentially; none empty filed -> name """ # importing bibname here to avoid recursive import from bibstuff import bibname #ai: shd move all bibname into here? possibly if entry_formatter is None: for field in try_fields: raw_names = self[field] if raw_names: break else: raw_names, field = entry_formatter.pick_raw_names(self,try_fields) return bibname.BibName(raw_names,from_field=field) #names are in a BibName object
def test_latex_accents_chars(self): "LaTeX accents and non English characters" n = bibname.BibName(r"J\orgen M\"{a}rtin and Sven \AAs") self.assertEqual(n.get_names_dicts()[1]["first"][0], "Sven")
def test_parts_names_von_parts(self): """Find correct parts""" n = bibname.BibName("Joe von Hagel and van der Meer, Jako") (a, b) = n.get_last_names() self.assertEqual(a, "Hagel") self.assertEqual(b, "Meer")
def test_number_names_von_parts(self): """Should find 2 names""" n = bibname.BibName("Joe von Hagel and van der Meer, Jako") self.assertTrue(len(n.get_names_dicts()) == 2)
def test_formatter_last_first(self): """test template""" n = bibname.BibName(r"J\orgen M\"{a}rtin and Sven von der Stadt") f = n.format(self.names_formatter_last_first) self.assertEqual(f, 'M\\"{a}rtin, J., and von~der~Stadt, S.')
def test_formatter_initials(self): """test template""" n = bibname.BibName(r"J\orgen M\"{a}rtin and Sven \AAs") f = n.format(self.names_formatter_initials) self.assertEqual(f, 'J. M\\"{a}rtin, and S. \\AAs')