Skip to content

Commit

Permalink
ImageObject tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-arista committed Jun 12, 2024
1 parent 6fa0107 commit 4b67c8f
Show file tree
Hide file tree
Showing 2 changed files with 955 additions and 7 deletions.
33 changes: 26 additions & 7 deletions scripting/imageObjectCodeExtractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def header(self):
self.add("import drawBot")
self.add("from testSupport import DrawBotBaseTest")
self.newline()
self.add('sampleImage = drawBot.ImageObject("tests/data/drawBot.png")')
self.add('fs = drawBot.FormattedString("Hello World")')
self.newline()
self.newline()
self.add("class ImageObjectTest(DrawBotBaseTest):")
self.indent()
self.newline()
Expand Down Expand Up @@ -349,6 +353,7 @@ def pythonifyDescription(description):
doc.add(AppKit.CIFilter.localizedDescriptionForFilterName_(filterName)) # type: ignore

args = []
unitTestsArgs = []
inputCode = CodeWriter()

inputKeys = [
Expand All @@ -372,6 +377,7 @@ def pythonifyDescription(description):
doc.indent()
if filterName in generators:
args.append("size: Size")
unitTestsArgs.append("size=(100, 100)")
doc.add(f"`size` {variableValues['size']}")
for inputKey in inputKeys:
info = ciFilterAttributes.get(inputKey)
Expand Down Expand Up @@ -453,6 +459,22 @@ def pythonifyDescription(description):
doc.add(f"`{inputKey}` {docValue}. {pythonifyDescription(description)}")
args.append(arg)


match inputKey:
case inputKey if inputKey.endswith("Image"):
value = "sampleImage"
case "gainMap" | "texture" | "mask":
value = "sampleImage"
case "text":
value = "fs"
case "message":
value = "b'Hello World'"
case "topLeft" | "topRight" | "bottomRight" | "bottomLeft":
value = "(2, 2)"
case _:
value = default
unitTestsArgs.append(f"{inputKey}={value}")

doc.dedent()
drawBotFilterName = camelCase(filterName[2:])
code.add(
Expand All @@ -477,15 +499,12 @@ def pythonifyDescription(description):

code.add("self._addFilter(filterDict)")
code.dedent()
code.newline()

code.newline()
unitTests.add(f"def test_{drawBotFilterName}(self):")
unitTests.indent()
if filterName in generators:
unitTests.add("img = drawBot.ImageObject()")
unitTests.add(f"img.{drawBotFilterName}((100, 100), b'hello world')")
else:
unitTests.add("pass")
unitTests.add("img = drawBot.ImageObject()")
unitTests.add(f"img.{drawBotFilterName}({', '.join(unitTestsArgs)})")
unitTests.newline()
unitTests.dedent()

Expand Down
Loading

0 comments on commit 4b67c8f

Please sign in to comment.