breaking changes: more pythonic api (still allowed because of the very begining state of the project

This commit is contained in:
2021-05-12 13:57:49 +02:00
parent 6fccc1b6cf
commit e57d63f562
4 changed files with 48 additions and 34 deletions

View File

@@ -21,26 +21,26 @@ def test_clone():
width = 5
height = 5
img = floatimg.create(width, height, floatimg.RGB)
img.rgb_constant(127.0, 127.0, 127.0)
img.fill((127.0, 127.0, 127.0))
# clone without copying pixel values
img2 = img.clone()
img2 = img.clone(False)
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)
assert img.get(x, y) != img2.get(x, y)
img2 = img.clone(1)
img2 = img.clone(True)
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)
assert img.get(x, y) == img2.get(x, y)
def test_rgb_constant():
@@ -48,10 +48,11 @@ def test_rgb_constant():
height = 5
color = [127.0, 127.0, 127.0]
img = floatimg.create_rgb(width, height)
img.rgb_constant(*color)
img.fill(color)
for y in range(height):
for x in range(width):
assert img.get_rgb(x, y) == color
assert img.get(x, y) == color
def test_copy_data():
@@ -59,27 +60,27 @@ def test_copy_data():
height = 5
color = [127.0, 127.0, 127.0]
img = floatimg.create_rgb(width, height)
img.rgb_constant(*color)
img.fill(color)
img2 = floatimg.create_rgb(width, height)
img2.rgb_constant(64.0, 64.0, 64.0)
img2.fill((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)
assert img.get(x, y) == img2.get(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.fill(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]
assert img.get(x, y) == [0.0, 0.0, 0.0]
def test_str_type():
@@ -100,6 +101,6 @@ def test__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]
assert img.get(0, 0) == [0.0, 0.0, 0.0]
img.put(0, 0, (127.0, 127.0, 127.0))
assert img.get(0, 0) == [127.0, 127.0, 127.0]

View File

@@ -10,8 +10,8 @@ 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)
img.fill((64.0, 64.0, 64.0))
img.dump(TEST_PATH)
def test_dump_to_file():
@@ -34,10 +34,11 @@ def test_load():
create_dump()
width, height = 5, 5
img = floatimg.create_rgb(width, height)
img.load_from_dump(TEST_PATH)
img.load(TEST_PATH)
for y in range(height):
for x in range(width):
assert img.get_rgb(x, y) == [64.0, 64.0, 64.0]
assert img.get(x, y) == [64.0, 64.0, 64.0]
os.remove(TEST_PATH)
@@ -46,5 +47,5 @@ def test_create():
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]
assert img.get(x, y) == [64.0, 64.0, 64.0]
os.remove(TEST_PATH)