def test_cells_memory_leak1(self): cell = Subscribed(lambda: Sequence([ Span("Thing(k=%s).x = %s" % (thing.k, thing.x)) for thing in Thing.lookupAll(k=0) ])) def workFn(db, cells, iterations=5000): with db.view(): thing = Thing.lookupAny(k=0) for counter in range(iterations): with db.transaction(): thing.delete() thing = Thing(k=0, x=counter) cells.renderMessages() def initFn(db, cells): with db.transaction(): Thing(k=0, x=0) cells.renderMessages() workFn(db, cells, iterations=500) self.helper_memory_leak(cell, initFn, workFn, 1)
def test_cells_messages(self): pair = [Container("HI"), Container("HI2")] pairCell = Sequence(pair) self.cells.withRoot(pairCell) msgs = self.cells.renderMessages() expectedCells = [self.cells._root, pairCell, pair[0], pair[1]] self.assertTrue(self.cells._root in self.cells) self.assertTrue(pairCell in self.cells) self.assertTrue(pair[0] in self.cells) self.assertTrue(pair[1] in self.cells) messages = {} for m in msgs: assert m['id'] not in messages messages[m['id']] = m for c in expectedCells: self.assertTrue(c.identity in messages) self.assertEqual( set(messages[pairCell.identity]['replacements'].values()), set([pair[0].identity, pair[1].identity])) self.assertEqual( set(messages[self.cells._root.identity]['replacements'].values()), set([pairCell.identity]))
def test_sequence_html_valid(self): elements = [Text("Element One"), Text("Element two")] cell = Sequence(elements) cell.recalculate() html = cell.contents self.assertHTMLNotEmpty(html) self.assertHTMLValid(html)
def servicesTableDataPrep(s, field, serviceCounts): """Prep data for display in services table. s : service object service data dictionary field : str serviceCounts : list of ints """ if field == 'Service': data = Clickable(s.name, "/services/" + s.name) elif field == 'Codebase Status': data = ( Clickable( Sequence([Octicon('stop').color('red'), Span('Unlocked')]), lambda: s.lock()) if s.isUnlocked else Clickable( Sequence([Octicon('shield').color('green'), Span('Locked')]), lambda: s.prepare()) if s.isLocked else Clickable( Sequence([Octicon('shield').color('orange'), Span('Prepared')]), lambda: s.unlock())) elif field == 'Codebase': data = (str(s.codebase) if s.codebase else "") elif field == 'Module': data = s.service_module_name elif field == 'Class': data = s.service_class_name elif field == 'Placement': data = s.placement elif field == 'Active': data = Subscribed( lambda: len(service_schema.ServiceInstance.lookupAll(service=s))) elif field == 'TargetCount': data = Dropdown(s.target_count, [(str(ct), __serviceCountSetter(s, ct)) for ct in serviceCounts]) elif field == 'Cores': data = str(s.coresUsed) elif field == 'RAM': data = str(s.gbRamUsed) elif field == 'Boot Status': data = (Popover(Octicon("alert"), "Failed", Traceback(s.lastFailureReason or "<Unknown>")) if s.isThrottled() else "") else: data = "" return data
def view(): buttons = Sequence([ Padding(), Button(Sequence([Octicon('shield').color('green'), Span('Lock ALL')]), lambda: [s.lock() for s in service_schema.Service.lookupAll()]), Button( Sequence([Octicon('shield').color('orange'), Span('Prepare ALL')]), lambda: [s.prepare() for s in service_schema.Service.lookupAll()]), Button( Sequence([Octicon('stop').color('red'), Span('Unlock ALL')]), lambda: [s.unlock() for s in service_schema.Service.lookupAll()]), ]) tabs = Tabs(Services=servicesTable(), Hosts=hostsTable()) return Sequence([buttons, tabs])
def checkThing2s(): ensureSubscribedType(Thing2) res = Sequence([ Span("Thing(k=%s).x = %s" % (thing.k, thing.x)) for thing in Thing2.lookupAll() ]) computed.set() return res
def test_cells_recalculation(self): pair = [Container("HI"), Container("HI2")] self.cells.withRoot(Sequence(pair)) self.cells.renderMessages() pair[0].setChild("HIHI") # a new message for the child, and also for 'pair[0]' self.assertEqual(len(self.cells.renderMessages()), 3)
def test_cells_subscriptions(self): self.cells.withRoot( Subscribed(lambda: Sequence([ Span("Thing(k=%s).x = %s" % (thing.k, thing.x)) for thing in Thing.lookupAll() ]))) self.cells.renderMessages() with self.db.transaction(): Thing(x=1, k=1) Thing(x=2, k=2) self.cells._recalculateCells() with self.db.transaction(): Thing(x=3, k=3) # three 'Span', three 'Text', the Sequence, the Subscribed, and a delete self.assertEqual(len(self.cells.renderMessages()), 9)