51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
"""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)
|