Spaces:
Configuration error
Configuration error
Danila-Pechenev
commited on
Commit
·
9bd7d18
1
Parent(s):
13ddc8a
Rename `test.py` to `test_model.py`
Browse files- test/test.py +0 -1
- test/test_model.py +50 -0
test/test.py
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
import pytest
|
|
|
|
test/test_model.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from PIL import Image
|
2 |
+
from tensorflow import keras
|
3 |
+
import sys
|
4 |
+
import io
|
5 |
+
|
6 |
+
sys.path.append("./../app")
|
7 |
+
import model
|
8 |
+
|
9 |
+
model_instance: keras.Model = model.create_model()
|
10 |
+
|
11 |
+
|
12 |
+
def template(filename: str) -> (int, int, Image.Image):
|
13 |
+
image: Image.Image = Image.open(filename)
|
14 |
+
width: int
|
15 |
+
height: int
|
16 |
+
width, height = image.size
|
17 |
+
image_bytes: io.BytesIO = io.BytesIO()
|
18 |
+
image.save(image_bytes, format=image.format)
|
19 |
+
output_image: Image.Image = model.run_model(image_bytes, model_instance)
|
20 |
+
return width, height, output_image
|
21 |
+
|
22 |
+
|
23 |
+
def test_image_jpg():
|
24 |
+
width: int
|
25 |
+
height: int
|
26 |
+
output_image: Image.Image
|
27 |
+
width, height, output_image = template("test_images/test1.jpg")
|
28 |
+
|
29 |
+
assert width == output_image.size[0]
|
30 |
+
assert height == output_image.size[1]
|
31 |
+
|
32 |
+
|
33 |
+
def test_image_png():
|
34 |
+
width: int
|
35 |
+
height: int
|
36 |
+
output_image: Image.Image
|
37 |
+
width, height, output_image = template("test_images/test2.png")
|
38 |
+
|
39 |
+
assert width == output_image.size[0]
|
40 |
+
assert height == output_image.size[1]
|
41 |
+
|
42 |
+
|
43 |
+
def test_image_jpeg():
|
44 |
+
width: int
|
45 |
+
height: int
|
46 |
+
output_image: Image.Image
|
47 |
+
width, height, output_image = template("test_images/test3.jpeg")
|
48 |
+
|
49 |
+
assert width == output_image.size[0]
|
50 |
+
assert height == output_image.size[1]
|