def teste_sortear(self): lt_res = [0, 8, 2, 4, 5, 6, 7, 9, 1, 3] lt_res.reverse() # sortear() usa pop(), que funciona do fim para o começo t = Tombola(range(10), self.fnrand) for i in range(len(t)): res = t.sortear() assert lt_res[i] == res, '%s != %s' % (lt_res[i], res)
class YTombola( OFS.SimpleItem.Item, # A simple Principia object. Not Folderish. Persistent, # Make us persistent. Yaah! Acquisition.Implicit, # Uh, whatever. AccessControl.Role.RoleManager, # Security manager. ): """Tombola class.""" meta_type = "YTombola" def __init__(self, id, title, bolas): """initialise a new instance of Tombola""" self.tombola = Tombola(bolas) # apply(Tombola.__init__, (self, bolas)) self.id = id self.title = title # self.tombola.__allow_access_to_unprotected_subobjects__ = 1 # self.sortear = self.tombola.sortear def sortear(self): """sorteia o próximo item""" return self.tombola.sortear() def __getattr__(self, attr): if hasattr(self.tombola, attr): return getattr(self.tombola, attr) else: raise AttributeError, "procuramos mas não achamos '%s'" % attr manage_options = ( {"label": "Edit", "action": "manage_main"}, {"label": "View", "action": ""}, # invocar a própria instância (call->index_html) {"label": "Security", "action": "manage_access"}, {"label": "Sortear", "action": "sortear"}, ) __ac_permissions__ = ( ("View management screens", ("manage_tabs", "manage_main")), ("Change permissions", ("manage_access",)), ("Change Tômbola", ("manage_edit",)), ("View Tômbola", ("",)), ("Use Tômbola", ("sortear", "misturar")), ) index_html = HTMLFile("index", globals()) # View Interface manage_main = HTMLFile("tombolaEdit", globals()) # Management Interface def manage_edit(self, title, bolas, REQUEST=None): """proc""" self.title = title self.bolas = bolas if REQUEST is not None: return MessageDialog(title="Edited", message="Properties for %s changed." % self.id, action="./manage_main")
def teste_sortear_exception(self): t = Tombola(range(3)) t.sortear() t.sortear() t.sortear() self.assertRaises(TombolaVazia, t.sortear)