Ejemplo n.º 1
0
    def test(self):
        from drawBot.drawBotDrawingTools import _drawBotDrawingTool

        code = compile(source, "<%s>" % exampleName, "exec")

        namespace = {}
        _drawBotDrawingTool._addToNamespace(namespace)

        def mockSaveImage(path, **options):
            fileName = "example_mockSaveImage_" + os.path.basename(path)
            path = os.path.join(tempTestDataDir, fileName)
            drawBot.saveImage(path, **options)

        namespace["saveImage"] = mockSaveImage
        namespace["image"] = mockImage
        namespace["imageSize"] = mockImageSize
        namespace["imagePixelColor"] = mockImagePixelColor
        namespace["Variable"] = mockVariable
        namespace["printImage"] = mockPrintImage
        namespace["installFont"] = mockInstallFont
        namespace["uninstallFont"] = mockUninstallFont
        namespace["randint"] = mockRandInt

        randomSeed(0)
        drawBot.newDrawing()
        with StdOutCollector(captureStdErr=True):
            exec(code, namespace)
        fileName = "example_%s.png" % exampleName
        imagePath = os.path.join(tempTestDataDir, fileName)
        expectedImagePath = os.path.join(testDataDir, fileName)
        if doSaveImage:
            drawBot.saveImage(imagePath)
            self.assertImagesSimilar(imagePath, expectedImagePath)
Ejemplo n.º 2
0
 def makeTestAnimation(self, numFrames=25, pageWidth=500, pageHeight=500):
     randomSeed(0)
     drawBot.newDrawing()
     for i in range(numFrames):
         drawBot.newPage(pageWidth, pageHeight)
         drawBot.frameDuration(1/25)
         drawBot.fill(1)
         drawBot.rect(0, 0, pageWidth, pageHeight)
         drawBot.fill(0)
         drawBot.rect(random.randint(0, 100), random.randint(0, 100), 400, 400)
Ejemplo n.º 3
0
    def test(self):
        import __future__
        from drawBot.drawBotDrawingTools import _drawBotDrawingTool

        compileFlags = __future__.CO_FUTURE_DIVISION
        code = compile(source,
                       "<%s>" % exampleName,
                       "exec",
                       flags=compileFlags,
                       dont_inherit=True)

        namespace = {}
        _drawBotDrawingTool._addToNamespace(namespace)

        def mockSaveImage(path, **options):
            fileName = "example_mockSaveImage_" + os.path.basename(path)
            path = os.path.join(tempTestDataDir, fileName)
            drawBot.saveImage(path, **options)

        namespace["saveImage"] = mockSaveImage
        namespace["image"] = mockImage
        namespace["imageSize"] = mockImageSize
        namespace["imagePixelColor"] = mockImagePixelColor
        namespace["Variable"] = mockVariable
        namespace["printImage"] = mockPrintImage
        namespace["installFont"] = mockInstallFont
        namespace["uninstallFont"] = mockUninstallFont
        namespace["randint"] = mockRandInt

        randomSeed(0)
        drawBot.newDrawing()
        with StdOutCollector(captureStdErr=True):
            exec(code, namespace)
        fileName = "example_%s.png" % exampleName
        imagePath = os.path.join(tempTestDataDir, fileName)
        expectedImagePath = os.path.join(testDataDir, fileName)
        if doSaveImage:
            drawBot.saveImage(imagePath)
            if allowFuzzyImageComparison:
                self.assertImagesSimilar(imagePath, expectedImagePath)
            else:
                self.assertFilesEqual(imagePath, expectedImagePath)
Ejemplo n.º 4
0
    def test(self):
        import __future__
        from drawBot.drawBotDrawingTools import _drawBotDrawingTool

        compileFlags = __future__.CO_FUTURE_DIVISION
        code = compile(source, "<%s>" % exampleName, "exec", flags=compileFlags, dont_inherit=True)

        namespace = {}
        _drawBotDrawingTool._addToNamespace(namespace)
        def mockSaveImage(path, **options):
            fileName = "example_mockSaveImage_" + os.path.basename(path)
            path = os.path.join(tempTestDataDir, fileName)
            drawBot.saveImage(path, **options)
        namespace["saveImage"] = mockSaveImage
        namespace["image"] = mockImage
        namespace["imageSize"] = mockImageSize
        namespace["imagePixelColor"] = mockImagePixelColor
        namespace["Variable"] = mockVariable
        namespace["printImage"] = mockPrintImage
        namespace["installFont"] = mockInstallFont
        namespace["uninstallFont"] = mockUninstallFont
        namespace["randint"] = mockRandInt

        randomSeed(0)
        drawBot.newDrawing()
        with StdOutCollector(captureStdErr=True):
            exec(code, namespace)
        fileName = "example_%s.png" % exampleName
        imagePath = os.path.join(tempTestDataDir, fileName)
        expectedImagePath = os.path.join(testDataDir, fileName)
        if doSaveImage:
            drawBot.saveImage(imagePath)
            if allowFuzzyImageComparison:
                self.assertImagesSimilar(imagePath, expectedImagePath)
            else:
                self.assertFilesEqual(imagePath, expectedImagePath)