コード例 #1
0
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 == []
コード例 #2
0
def getSingleElementGenerationTimes():
    generationTimes = 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
コード例 #3
0
def getSingleElementGenerationTimes():
    generationTimes = 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
コード例 #4
0
def getGenerationTimeForAllElementsLooped100Times():
    startTime = time.time()
    allProducts = Box('AllProducts')
    scripts = ScriptContainer()
    allProducts.setScriptContainer(scripts)
    for x in xrange(100):
        doneSection()
        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']
コード例 #5
0
def getGenerationTimeForAllElementsLooped100Times():
    startTime = time.time()
    allProducts = Box('AllProducts')
    scripts = ScriptContainer()
    allProducts.setScriptContainer(scripts)
    for x in xrange(100):
        doneSection()
        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']