def testNameGeneration(idno, typ, benamning, motiv_beskrivning, avbildad_namn, avbildad_ort, date_foto, date_produktion): need_more = (u'Fartygsmodell', u'Fartygsporträtt', u'Marinmotiv', u'Modell', u'Ritning', u'Teckning', u'Akvarell', u'Karta', u'Kopparstick', u'Lavering', u'Sjökort', u'Sjöstrid', u'Porträtt') txt = u'' if typ == u'Foto': if len(avbildad_namn) > 0: txt += ', '.join(helpers.flip_names(avbildad_namn)) if len(txt) > 0 and len(avbildad_ort) > 0: txt += u'. ' txt += avbildad_ort # only add date if other info if date_foto.lower() != u'odaterad': if len(txt) > 0 and len(date_foto) > 0: txt += u'. ' txt += date_foto elif len(motiv_beskrivning) > 0: txt += motiv_beskrivning if len(txt) == 0: filenameList[idno] = {'typ': typ, 'descr': None} return u'Inget namn kan genereras (foto3)' if typ == u'Föremål': txt += benamning if len(benamning) == 0: filenameList[idno] = {'typ': typ, 'descr': None} return u'Inget namn kan genereras (föremål3)' elif benamning in need_more: txt2 = '' if len(avbildad_namn) > 0: txt2 += ', '.join(helpers.flip_names(avbildad_namn)) elif len(motiv_beskrivning) > 0: txt2 += motiv_beskrivning else: filenameList[idno] = {'typ': typ, 'descr': None} return u'Inget namn kan genereras (föremål3 med need_more)' if len(avbildad_ort) > 0: txt2 += u'. %s' % avbildad_ort if len(date_produktion) > 0 and \ date_produktion.lower() != u'odaterad': txt2 += u'. %s' % date_produktion txt = u'%s-%s' % (txt, txt2) txt = helpers.cleanString(txt) txt = helpers.touchup(txt) filenameList[idno] = {'typ': typ, 'descr': helpers.shortenString(txt)}
def test_clean_string_colons(self): test_string = ':s,a: ,:' expected = 's,a, ,-' self.assertEqual(cleanString(test_string), expected)
def test_clean_string_separators(self): test_string = '#|/\\' expected = '----' self.assertEqual(cleanString(test_string), expected)
def test_clean_string_brackets(self): test_string = '[{()}]' expected = '((()))' self.assertEqual(cleanString(test_string), expected)
def test_clean_string_unusual_whitespace(self): test_string = 'a\x8fb' expected = 'a b' self.assertEqual(cleanString(test_string), expected)
def test_clean_string_normal_whitespace(self): test_string = ' a\tb\nc\xa0d ' expected = 'a b c d' self.assertEqual(cleanString(test_string), expected)
def test_clean_string_empty(self): self.assertEqual(cleanString(''), '')