Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienChampagnol committed Oct 29, 2024
1 parent f9a547c commit 0371651
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/opengeodeweb_viewer/rpc/schemas/take_screenshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"type": "string"
},
"output_extension": {
"type": "string"
"type": "string",
"enum": [
"png",
"jpg"
]
},
"include_background": {
"type": "boolean"
Expand Down
16 changes: 11 additions & 5 deletions src/opengeodeweb_viewer/vtk_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,8 @@ def takeScreenshot(self, params):
w2if = vtkWindowToImageFilter()

if not include_background:
# renderer.SetBackground([255,255,255])
# renderer.SetLayer(1)
renderWindow.SetAlphaBitPlanes(1)

w2if.SetInput(renderWindow)
w2if.SetInputBufferTypeToRGBA()
w2if.ReadFrontBufferOff()
Expand All @@ -308,12 +307,19 @@ def takeScreenshot(self, params):
writer = vtkPNGWriter()
elif output_extension == "jpg":
writer = vtkJPEGWriter()
else:
raise Exception("output_extension not supported")

writer.SetFileName(os.path.join(self.DATA_FOLDER_PATH, filename + '.' + output_extension))
new_filename = filename + '.' + output_extension
file_path = os.path.join(self.DATA_FOLDER_PATH, new_filename)
writer.SetFileName(file_path)
writer.SetInputConnection(w2if.GetOutputPort())
writer.Write()
# renderer.SetLayer(0)
return

with open(file_path, "rb") as file:
file_content = file.read()

return {"blob": self.addAttachment(file_content)}

def get_data_base(self):
return self.getSharedObject("db")
Expand Down
3 changes: 2 additions & 1 deletion src/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def print_log(self):
print(output)

def get_response(self):
response = eval(self.ws.recv())
return self.ws.recv()
response = json.loads(self.ws.recv())
return response

def compare_image(self, nb_messages, filename):
Expand Down
23 changes: 23 additions & 0 deletions src/tests/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,26 @@ def test_set_color(server):

server.call("set_color", [{"id": "123456789", "red": 50, "green": 2, "blue": 250}])
assert server.compare_image(3, "set_color.jpeg") == True



def test_take_screenshot(server):

server.call(
"create_object_pipeline",
[{"id": "123456789", "file_name": "hat.vtp"}],
)
assert server.compare_image(3, "create_object_pipeline.jpeg") == True

server.call(
"take_screenshot",
[{"filename": "screenshot", "output_extension": "png", "include_background": False}],
)

response1 = server.get_response()
print(f"{response1=}", flush=True)
response2 = server.get_response()
print(f"{response2=}", flush=True)

blob = response2
assert type(blob) is bytes
Binary file modified src/tests/tests_output/test.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0371651

Please sign in to comment.