refactor FloatImg class method to function imported in floatimg module. add tests for file dump / load : coverage of exixting python code is 100%, yeah
This commit is contained in:
@@ -1,37 +1,105 @@
|
||||
from floatimg import FloatImg
|
||||
"""test of core functions """
|
||||
|
||||
import floatimg
|
||||
|
||||
|
||||
def test_create():
|
||||
width = 640
|
||||
height = 480
|
||||
img = FloatImg.create(width, height, FloatImg.RGB)
|
||||
img = floatimg.create(width, height, floatimg.RGB)
|
||||
assert img.width == width
|
||||
assert img.height == height
|
||||
assert img.type_id == FloatImg.RGB
|
||||
assert img.type_id == floatimg.RGB
|
||||
|
||||
img = FloatImg.create_rgb(width, height)
|
||||
img = floatimg.create_rgb(width, height)
|
||||
|
||||
assert img.type_id == FloatImg.RGB
|
||||
assert img.type_id == floatimg.RGB
|
||||
# TODO inspect RVB
|
||||
|
||||
|
||||
def test_clone():
|
||||
width = 640
|
||||
height = 480
|
||||
img = FloatImg.create(width, height, FloatImg.RGB)
|
||||
width = 5
|
||||
height = 5
|
||||
img = floatimg.create(width, height, floatimg.RGB)
|
||||
img.rgb_constant(127.0, 127.0, 127.0)
|
||||
|
||||
# clone without copying pixel values
|
||||
img2 = img.clone()
|
||||
assert img.width == img2.width
|
||||
assert img.height == img2.height
|
||||
assert img.type_id == img2.type_id
|
||||
# TODO inspect RVB and do pixel per pixel comparison
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
assert img.get_rgb(x, y) != img2.get_rgb(x, y)
|
||||
|
||||
img2 = img.clone(1)
|
||||
assert img.width == img2.width
|
||||
assert img.height == img2.height
|
||||
assert img.type_id == img2.type_id
|
||||
# TODO inspect RVB and do pixel per pixel comparison
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
assert img.get_rgb(x, y) == img2.get_rgb(x, y)
|
||||
|
||||
|
||||
def test_rgb_constant():
|
||||
width = 5
|
||||
height = 5
|
||||
color = [127.0, 127.0, 127.0]
|
||||
img = FloatImg.create_rgb(width, height)
|
||||
img = floatimg.create_rgb(width, height)
|
||||
img.rgb_constant(*color)
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
assert img.get_rgb(x, y) == color
|
||||
|
||||
|
||||
def test_copy_data():
|
||||
width = 5
|
||||
height = 5
|
||||
color = [127.0, 127.0, 127.0]
|
||||
img = floatimg.create_rgb(width, height)
|
||||
img.rgb_constant(*color)
|
||||
|
||||
img2 = floatimg.create_rgb(width, height)
|
||||
img2.rgb_constant(64.0, 64.0, 64.0)
|
||||
|
||||
img.copy_data(img2)
|
||||
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
assert img.get_rgb(x, y) == img2.get_rgb(x, y)
|
||||
|
||||
|
||||
def test_clear():
|
||||
width, height = 5, 5
|
||||
color = [127.0, 127.0, 127.0]
|
||||
img = floatimg.create_rgb(width, height)
|
||||
img.rgb_constant(*color)
|
||||
img.clear()
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
assert img.get_rgb(x, y) == [0.0, 0.0, 0.0]
|
||||
|
||||
|
||||
def test_str_type():
|
||||
width, height = 5, 5
|
||||
img = floatimg.create_rgb(width, height)
|
||||
assert img.str_type == "rgb"
|
||||
|
||||
|
||||
def test__str__():
|
||||
width, height = 5, 5
|
||||
img = floatimg.create_rgb(width, height)
|
||||
img_str = str(img)
|
||||
assert " width=5 " in img_str
|
||||
assert " height=5 " in img_str
|
||||
assert " type=rgb>" in img_str
|
||||
|
||||
|
||||
def test_put_rgb():
|
||||
width, height = 5, 5
|
||||
img = floatimg.create_rgb(width, height)
|
||||
assert img.get_rgb(0, 0) == [0.0, 0.0, 0.0]
|
||||
img.put_rgb(0, 0, [127.0, 127.0, 127.0])
|
||||
assert img.get_rgb(0, 0) == [127.0, 127.0, 127.0]
|
||||
|
||||
50
tests/dumps.py
Normal file
50
tests/dumps.py
Normal file
@@ -0,0 +1,50 @@
|
||||
"""test of file dump functions """
|
||||
import os
|
||||
|
||||
import floatimg
|
||||
|
||||
TEST_PATH = os.path.join(os.path.dirname(__file__), "test.dump")
|
||||
|
||||
# TODO refactor to fixture
|
||||
def create_dump():
|
||||
width, height = 5, 5
|
||||
img = floatimg.create_rgb(width, height)
|
||||
# fill it to have something to compare
|
||||
img.rgb_constant(64.0, 64.0, 64.0)
|
||||
img.dump_to_file(TEST_PATH)
|
||||
|
||||
|
||||
def test_dump_to_file():
|
||||
create_dump()
|
||||
|
||||
assert os.path.exists(TEST_PATH)
|
||||
assert os.path.isfile(TEST_PATH)
|
||||
assert os.path.getsize(TEST_PATH) == 320
|
||||
|
||||
os.remove(TEST_PATH)
|
||||
|
||||
|
||||
def test_infos():
|
||||
create_dump()
|
||||
floatimg.fileinfos(TEST_PATH) == 5, 5, floatimg.RGB
|
||||
os.remove(TEST_PATH)
|
||||
|
||||
|
||||
def test_load():
|
||||
create_dump()
|
||||
width, height = 5, 5
|
||||
img = floatimg.create_rgb(width, height)
|
||||
img.load_from_dump(TEST_PATH)
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
assert img.get_rgb(x, y) == [64.0, 64.0, 64.0]
|
||||
os.remove(TEST_PATH)
|
||||
|
||||
|
||||
def test_create():
|
||||
create_dump()
|
||||
img = floatimg.create_from_dump(TEST_PATH)
|
||||
for y in range(img.height):
|
||||
for x in range(img.width):
|
||||
assert img.get_rgb(x, y) == [64.0, 64.0, 64.0]
|
||||
os.remove(TEST_PATH)
|
||||
Reference in New Issue
Block a user