def __init__(self, vampire_sheet): from uploader import VAMPIRE_TAG_DATES, VAMPIRE_TAG_RENAMES from uploader import TRAIT_TAG_RENAMES from uploader import TRAITLIST_TAG_RENAMES from uploader import ENTRY_TAG_DATES, ENTRY_TAG_RENAMES from uploader import translate_date, map_attributes self.sheet = vampire_sheet vamp_attrs = dict((k, str(v)) for k,v in self.sheet.__dict__.iteritems()) vamp_attrs.update((k, str(v)) for k,v in self.sheet.vampiresheet.__dict__.iteritems()) vamp_attrs['player'] = self.sheet.player.username vamp_attrs['npc'] = 'yes' if self.sheet.npc else 'no' vamp_attrs['name'] = self.sheet.name for date_attribute in VAMPIRE_TAG_DATES: vamp_attrs[date_attribute] = translate_date(getattr(self.sheet, date_attribute)) reversed_map = dict((v, k) for k, v in VAMPIRE_TAG_RENAMES.iteritems()) map_attributes(reversed_map, vamp_attrs) #pprint(vamp_attrs) self.vampire = CrapvineVampire() self.vampire.read_attributes(vamp_attrs) #pprint(self.vampire.startdate) #pprint(self.vampire.npc) for tlp in self.sheet.get_traitlist_properties(): tl_attrs = dict((k, str(v)) for k,v in tlp.__dict__.iteritems()) tl_attrs['name'] = tlp.name.name map_attributes(dict((v,k) for k,v in TRAITLIST_TAG_RENAMES.iteritems()), tl_attrs) #pprint(tl_attrs) ctl = CrapvineTraitList() ctl.read_attributes(tl_attrs) for t in self.sheet.get_traits(tlp.name.name): t_attrs = dict((k, str(v)) for k,v in t.__dict__.iteritems()) map_attributes(dict((v, k) for k, v in TRAIT_TAG_RENAMES.iteritems()), t_attrs) ct = CrapvineTrait() ct.read_attributes(t_attrs) ctl.add_trait(ct) self.vampire.add_traitlist(ctl) e = CrapvineExperience() e.read_attributes({ 'unspent':str(self.sheet.experience_unspent), 'earned':str(self.sheet.experience_earned)}) for ee in self.sheet.experience_entries.all(): ee_attrs = dict((k, str(v)) for k,v in ee.__dict__.iteritems()) for date_attribute in ENTRY_TAG_DATES: ee_attrs[date_attribute] = translate_date(getattr(ee, date_attribute)) map_attributes(dict((v, k) for k, v in ENTRY_TAG_RENAMES.iteritems()), ee_attrs) cee = CrapvineExperienceEntry() cee.read_attributes(ee_attrs) e.add_entry(cee) self.vampire.add_experience(e)
def startElement(self, name, attrs): if name == 'vampire': if not attrs.has_key('name'): return v = Vampire() v.read_attributes(attrs) self.current_vampire = v elif name == 'experience': if self.current_experience: raise IOError('Experience encountered while still reading traitlist') exp = Experience() exp.read_attributes(attrs) self.current_experience = exp if self.current_vampire: self.current_vampire.add_experience(exp) elif name == 'entry': if not self.current_experience: raise IOError('Entry without bounding Experience') ent = ExperienceEntry() ent.read_attributes(attrs) self.current_experience.add_entry(ent, False) elif name == 'entry': pass elif name == 'biography': self.reading_biography = True elif name == 'notes': self.reading_notes = True elif name == 'traitlist': if self.current_traitlist: raise IOError('TraitList encountered while still reading traitlist') tl = TraitList() tl.read_attributes(attrs) self.current_traitlist = tl if self.current_vampire: self.current_vampire.add_traitlist(tl) elif name == 'trait': if not self.current_traitlist: raise IOError('Trait without bounding traitlist') t = Trait() t.read_attributes(attrs) self.current_traitlist.add_trait(t)
def setUp(self): self.traits = [] self.traitlist = TraitList()
class TraitListTestCase(unittest.TestCase): def setUp(self): self.traits = [] self.traitlist = TraitList() def __build_trait(self, name, val, note=''): t = Trait() t.name = name t.val = val t.note = note return t def testAddition(self): assert self.traitlist.trait_changes == None t = self.__build_trait('Example', 3, 'Carlsbad') self.traitlist.add_trait(t) assert t in self.traitlist.traits assert len(self.traitlist.traits) == 1 assert self.traitlist.trait_changes != None changes = self.traitlist.get_changes_strings() assert changes.first == "Added Example x3 (Carlsbad)" def testDisplay(self): fully_tested = { self.__build_trait('Example', 3, 'Carlsbad') : { '0' : 'Example', '1' : 'Example x3 (Carlsbad)', '2' : 'Example x3 OOO (Carlsbad)', '3' : 'Example OOO (Carlsbad)', '4' : 'Example (3, Carlsbad)', '5' : 'Example (Carlsbad)', '6' : 'Example (3)', '7' : 'Example (Carlsbad)OExample (Carlsbad)OExample (Carlsbad)', '8' : 'OOO', '9' : '3', '10': 'Carlsbad', 'Default': 'Example x3 (Carlsbad)' }, self.__build_trait('Example', 3, '') : { '0' : 'Example', '1' : 'Example x3', '2' : 'Example x3 OOO', '3' : 'Example OOO', '4' : 'Example (3)', '5' : 'Example', '6' : 'Example (3)', '7' : 'ExampleOExampleOExample', '8' : 'OOO', '9' : '3', '10': '', 'Default': 'Example x3' }, self.__build_trait('Example', 0, '') : { '0' : 'Example', '1' : 'Example', '2' : 'Example', '3' : 'Example', '4' : 'Example', '5' : 'Example', '6' : 'Example', '7' : 'Example', '8' : '', '9' : '', '10': '', 'Default': 'Example' }, self.__build_trait('Example', 0, 'Carlsbad') : { '0' : 'Example', '1' : 'Example (Carlsbad)', '2' : 'Example (Carlsbad)', '3' : 'Example (Carlsbad)', '4' : 'Example (Carlsbad)', '5' : 'Example (Carlsbad)', '6' : 'Example', '7' : 'Example (Carlsbad)', '8' : '', '9' : '', '10': 'Carlsbad', 'Default': 'Example (Carlsbad)' } } for trait, test_list in fully_tested.iteritems(): for display_type, expected_result in test_list.iteritems(): print display_type print trait self.assertEqual(trait.display_str(display_type), expected_result) def testBasic(self): assert False