diff --git a/.gitignore b/.gitignore index c2c6052..544a83d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ env/ dist/ build/ *.egg-info +*.pyc # IDEs **/.idea diff --git a/.gitmodules b/.gitmodules index 9806184..ee2b235 100644 --- a/.gitmodules +++ b/.gitmodules @@ -5,3 +5,4 @@ [submodule "tests/images"] path = tests/images url = https://git.pileof.rocks/drewcassidy/python-rgbcx-images.git + commit = 0ade526dd1070e6f5b43e0bd58b26828abff86b7 diff --git a/tests/images b/tests/images index dc0dfa9..0ade526 160000 --- a/tests/images +++ b/tests/images @@ -1 +1 @@ -Subproject commit dc0dfa948994cc05501b544e8f3c396dad69897e +Subproject commit 0ade526dd1070e6f5b43e0bd58b26828abff86b7 diff --git a/tests/test_rgbcx.py b/tests/test_BC1.py similarity index 81% rename from tests/test_rgbcx.py rename to tests/test_BC1.py index 3b29d2b..ca6bb82 100644 --- a/tests/test_rgbcx.py +++ b/tests/test_BC1.py @@ -1,22 +1,7 @@ import unittest -import os -import rgbcx import s3tc -from PIL import Image - -dir_path = os.path.dirname(os.path.realpath(__file__)) -image_path = dir_path + "/images" - -# A block that should always encode greyscale, where every row of pixels is identical, and the left side is lighter than the right side -greyscale = Image.open(image_path + "/blocks/greyscale.png").tobytes("raw", "RGBX") - -# A block that should always encode 3-color when available. -# from left to right: red, yellow, yellow, green -three_color = Image.open(image_path + "/blocks/3color.png").tobytes("raw", "RGBX") - -# A block that should always encode 3-color with black when available -# from left to right: black, red, yellow, green -three_color_black = Image.open(image_path + "/blocks/3color black.png").tobytes("raw", "RGBX") +import rgbcx +from images import Blocks class TestBC1Encoder(unittest.TestCase): @@ -27,7 +12,7 @@ class TestBC1Encoder(unittest.TestCase): def test_block_size(self): """Ensure encoded block size is 8 bytes.""" - out = self.bc1_encoder.encode_image(greyscale, 4, 4) + out = self.bc1_encoder.encode_image(Blocks.greyscale, 4, 4) self.assertEqual(self.bc1_encoder.block_width, 4, 'incorrect reported block width') self.assertEqual(self.bc1_encoder.block_height, 4, 'incorrect reported block height') @@ -36,13 +21,13 @@ class TestBC1Encoder(unittest.TestCase): def test_block_4color(self): """Ensure encoding the greyscale test block results in a 4 color block.""" - out = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(greyscale, 4, 4)) + out = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(Blocks.greyscale, 4, 4)) self.assertFalse(out.is_3color(), "returned 3 color block for greyscale test block") def test_block_greyscale_selectors(self): """Ensure encoding the greyscale test block results in the correct selectors.""" - out = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(greyscale, 4, 4)) + out = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(Blocks.greyscale, 4, 4)) first_row = out.selectors[0] expected_row = [0, 2, 3, 1] @@ -51,8 +36,8 @@ class TestBC1Encoder(unittest.TestCase): def test_block_3color(self): """Ensure encoder doesn't output a 3 color block.""" - out1 = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(three_color, 4, 4)) - out2 = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(three_color_black, 4, 4)) + out1 = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(Blocks.three_color, 4, 4)) + out2 = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(Blocks.three_color_black, 4, 4)) self.assertFalse(out1.is_3color(), "returned 3 color block with use_3color disabled") self.assertFalse(out2.is_3color(), "returned 3 color block with use_3color disabled") @@ -66,26 +51,26 @@ class TestBC1Encoder3Color(unittest.TestCase): def test_block_4color(self): """Ensure encoding the greyscale test block results in a 4 color block.""" - out = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(greyscale, 4, 4)) + out = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(Blocks.greyscale, 4, 4)) self.assertFalse(out.is_3color(), "returned 3 color block for greyscale test block") def test_block_3color(self): """Ensure encoding the 3 color test block results in a 3 color block.""" - out = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(three_color, 4, 4)) + out = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(Blocks.three_color, 4, 4)) self.assertTrue(out.is_3color(), "returned 4 color block with use_3color enabled") def test_block_3color_black(self): """Ensure encoder doesn't output a 3 color block with black pixels.""" - out = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(three_color_black, 4, 4)) + out = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(Blocks.three_color_black, 4, 4)) self.assertFalse(out.is_3color() and any(3 in row for row in out.selectors), "returned 3 color block with black pixels with use_3color_black disabled") def test_block_selectors(self): """Ensure encoding the 3 color test block results in the correct selectors.""" - out = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(three_color, 4, 4)) + out = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(Blocks.three_color, 4, 4)) first_row = out.selectors[0] expected_row = [1, 2, 2, 0] @@ -100,18 +85,21 @@ class TestBC1Encoder3ColorBlack(unittest.TestCase): self.bc1_encoder = rgbcx.BC1Encoder(rgbcx.InterpolatorType.Ideal, 5, True, True) def test_block_3color(self): - out = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(three_color, 4, 4)) + """Ensure encoding the 3 color test block results in a 3 color block.""" + out = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(Blocks.three_color, 4, 4)) self.assertTrue(out.is_3color(), "returned 4 color block with use_3color enabled") def test_block_3color_black(self): - out = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(three_color_black, 4, 4)) + """Ensure encoder outputs a 3 color block with black pixels.""" + out = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(Blocks.three_color_black, 4, 4)) self.assertTrue(out.is_3color(), "returned 4 color block with use_3color enabled") self.assertTrue(any(3 in row for row in out.selectors), "returned block without black pixels with use_3color_black enabled") def test_block_selectors(self): - out = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(three_color_black, 4, 4)) + """Ensure encoding the 3 color with black test block results in the correct selectors.""" + out = s3tc.BC1Block.frombytes(self.bc1_encoder.encode_image(Blocks.three_color_black, 4, 4)) first_row = out.selectors[0] expected_row = [3, 1, 2, 0]