Skip to content

Commit

Permalink
add images check tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gounux committed Jul 4, 2024
1 parent e29d2d9 commit 2a2d1a0
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions tests/test_yaml_header_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
check_author_md,
check_existing_tags,
check_image_extension,
check_image_ratio,
check_image_size,
check_license,
check_missing_mandatory_keys,
check_tags_order,
download_image_sizes,
)

# -- GLOBALS
TEAM_FOLDER = Path("tests/fixtures/team")
URL_TEST_VERTICAL_IMAGE = "https://cdn.geotribu.fr/img/articles-blog-rdp/articles/2024/mise_en_place_qfieldcloud_custom/screenshot_qfield_qfc_project.webp"
URL_TEST_HORIZONTAL_IMAGE = "https://cdn.geotribu.fr/img/articles-blog-rdp/capture-ecran/carte_trains_europe.png"


class TestYamlHeaderCheck(unittest.TestCase):
Expand Down Expand Up @@ -95,3 +100,70 @@ def test_image_extension_nok(self):
self.assertFalse(check_image_extension("https://mon.image.webp"))
self.assertFalse(check_image_extension("https://mon.image.gif"))
self.assertFalse(check_image_extension("https://mon.image.tiff"))

def test_image_size_ok(self):
sizes = download_image_sizes()
self.assertTrue(
check_image_size(
URL_TEST_VERTICAL_IMAGE, sizes, max_width=800, max_height=800
)
)
self.assertTrue(
check_image_size(
URL_TEST_HORIZONTAL_IMAGE, sizes, max_width=800, max_height=800
)
)

def test_image_size_nok(self):
sizes = download_image_sizes()
self.assertFalse(
check_image_size(
URL_TEST_VERTICAL_IMAGE, sizes, max_width=380, max_height=800
)
)
self.assertFalse(
check_image_size(
URL_TEST_VERTICAL_IMAGE, sizes, max_width=800, max_height=799
)
)
self.assertFalse(
check_image_size(
URL_TEST_HORIZONTAL_IMAGE, sizes, max_width=799, max_height=800
)
)
self.assertFalse(
check_image_size(
URL_TEST_HORIZONTAL_IMAGE, sizes, max_width=800, max_height=532
)
)

def test_image_ratio_ok(self):
sizes = download_image_sizes()
self.assertTrue(
check_image_ratio(
URL_TEST_VERTICAL_IMAGE, sizes, min_ratio=0.45, max_ratio=0.5
)
)
self.assertTrue(
check_image_ratio(
URL_TEST_HORIZONTAL_IMAGE, sizes, min_ratio=1.45, max_ratio=1.55
)
)
self.assertTrue(
check_image_ratio(
URL_TEST_HORIZONTAL_IMAGE, sizes, min_ratio=1.49, max_ratio=1.51
)
)

def test_image_ratio_nok(self):
sizes = download_image_sizes()
self.assertFalse(
check_image_ratio(
URL_TEST_VERTICAL_IMAGE, sizes, min_ratio=1.45, max_ratio=1.55
)
)
self.assertFalse(
check_image_ratio(
URL_TEST_HORIZONTAL_IMAGE, sizes, min_ratio=1.2, max_ratio=1.3
)
)

0 comments on commit 2a2d1a0

Please sign in to comment.