class TestScriptContainer(ElementTester): def setup_method(self, method): self.element = ScriptContainer() def test_addScript(self): assert self.element._scripts == [] self.element.addScript("alert('I am a script :D');") self.element.addScript("var value = 'I am another script';") assert self.element._scripts == [ "alert('I am a script :D');", "var value = 'I am another script';" ] assert "alert('I am a script :D');" in self.element.toHTML() assert "var value = 'I am another script';" in self.element.toHTML() def test_removeScript(self): assert self.element._scripts == [] self.element.addScript("alert('I am a script :D');") assert self.element._scripts == ["alert('I am a script :D');"] self.element.removeScript("alert('I am a script :D');") assert self.element._scripts == []
class TestScriptContainer(ElementTester): def setup_method(self, method): self.element = ScriptContainer() def test_addScript(self): assert self.element._scripts == [] self.element.addScript("alert('I am a script :D');") self.element.addScript("var value = 'I am another script';") assert self.element._scripts == ["alert('I am a script :D');", "var value = 'I am another script';"] assert "alert('I am a script :D');" in self.element.toHTML() assert "var value = 'I am another script';" in self.element.toHTML() def test_removeScript(self): assert self.element._scripts == [] self.element.addScript("alert('I am a script :D');") assert self.element._scripts == ["alert('I am a script :D');"] self.element.removeScript("alert('I am a script :D');") assert self.element._scripts == []
def getSingleElementGenerationTimes(): generationTimes = DictUtils.OrderedDict() for product in Factory.products.keys(): if "." in product: continue doneSection() startTime = time.time() scripts = ScriptContainer() element = Factory.build(product, 'Test', 'Product') element.setScriptContainer(scripts) html = element.toHTML() html += scripts.toHTML() generationTime = time.time() - startTime results['createAllOnce'] += generationTime generationTimes[generationTime] = (product, len(html)) results['longestCreationTime'] = generationTimes.orderedKeys[-1] return generationTimes
def getGenerationTimeForAllElementsLooped100Times(): startTime = time.time() allProducts = Box('AllProducts') scripts = ScriptContainer() allProducts.setScriptContainer(scripts) for x in xrange(100): doneSection() results['loopedCreate'] = results['loopedInit'] + results['loopedToHtml'] for product in Factory.products.keys(): allProducts.addChildElement(Factory.build(product, 'Test', 'Product')) instantiationTime = time.time() - startTime results['loopedInit'] = instantiationTime startTime = time.time() html = allProducts.toHTML() html += scripts.toHTML() generationTime = (time.time() - startTime) results['loopedToHtml'] = generationTime results['loopedToHtmlSize'] = len(html) results['loopedCreate'] = results['loopedInit'] + results['loopedToHtml']
def getGenerationTimeForAllElementsLooped100Times(): startTime = time.time() allProducts = Box('AllProducts') scripts = ScriptContainer() allProducts.setScriptContainer(scripts) for x in xrange(100): doneSection() results[ 'loopedCreate'] = results['loopedInit'] + results['loopedToHtml'] for product in Factory.products.keys(): allProducts.addChildElement( Factory.build(product, 'Test', 'Product')) instantiationTime = time.time() - startTime results['loopedInit'] = instantiationTime startTime = time.time() html = allProducts.toHTML() html += scripts.toHTML() generationTime = (time.time() - startTime) results['loopedToHtml'] = generationTime results['loopedToHtmlSize'] = len(html) results['loopedCreate'] = results['loopedInit'] + results['loopedToHtml']