def generate_name(): """main function""" title = choice(S_TITLE_TYPES, p=P_TITLE_TYPES) has_title = choice(S_TRUEFALSE, p=P_TITLE) has_subtitle = choice(S_TRUEFALSE, p=title['p_subtitle']) tokens = [] if has_title: tokens.append(Factory.create_token(title['type'])) if choice(S_TRUEFALSE, p=P_NUMERAL): tokens.append(Factory.create_token('Numeral')) if not has_title or has_subtitle: if has_title: tokens.append(":") tokens.append(Factory.create_token('Subtitle')) if choice(S_TRUEFALSE, p=P_EDITION): tokens.append((Factory.create_token('Edition'))) name = " ".join([str(t) for t in tokens]).replace(" :", ":") return name
def test_creation_vthes(self): self.assertEqual(Factory.create_token('VTheS').__class__.__name__, 'VTheS')
def test_creation_s1vss2(self): self.assertEqual(Factory.create_token('S1VsS2').__class__.__name__, 'S1VsS2')
def test_creation_nonexisting(self): # check that s.split fails when the separator is not a string with self.assertRaises(ValueError): Factory.create_token('NonExistingType')
def test_creation_subtitle(self): self.assertEqual(Factory.create_token('Subtitle').__class__.__name__, 'Subtitle')
def test_creation_random(self): self.assertEqual(Factory.create_token('RandomWord').__class__.__name__, 'RandomWord')
def test_creation_compound(self): self.assertEqual(Factory.create_token('CompoundWord').__class__.__name__, 'CompoundWord')
def test_creation_numeral(self): self.assertEqual(Factory.create_token('Numeral').__class__.__name__, 'Numeral')
def test_creation_edition(self): self.assertEqual(Factory.create_token('Edition').__class__.__name__, 'Edition')