Skip to content
Snippets Groups Projects
Commit f9f879ef authored by Eva Bardou's avatar Eva Bardou :frog: Committed by Yoann Schneider
Browse files

Officially support `Python 3.12` in both the base and the template

parent b20d19a5
No related tags found
1 merge request!601Officially support `Python 3.12` in both the base and the template
Pipeline #201026 passed
......@@ -32,6 +32,7 @@ classifiers = [
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
[project.urls]
......
import logging
import math
import unittest
import uuid
from io import BytesIO
from operator import attrgetter
......@@ -219,74 +218,33 @@ def test_open_image_rotate_mirror(rotation_angle, mirrored, expected_path):
assert _root_mean_square(expected, actual) <= 15.0
class TestTrimPolygon(unittest.TestCase):
def test_trim_polygon_partially_outside_image(self):
bad_polygon = [
[99, 200],
[197, 224],
[120, 251],
[232, 350],
[312, 364],
[325, 310],
[318, 295],
[296, 260],
[352, 259],
[106, 210],
[197, 206],
[99, 200],
]
expected_polygon = [
[99, 200],
[197, 224],
[120, 251],
[232, 300],
[312, 300],
[325, 300],
[318, 295],
[296, 260],
[352, 259],
[106, 210],
[197, 206],
[99, 200],
]
assert (
trim_polygon(bad_polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
== expected_polygon
)
def test_trim_polygon_good_polygon(self):
good_polygon = (
(12, 56),
(29, 60),
(35, 61),
(42, 59),
(58, 57),
(65, 61),
(72, 57),
(12, 56),
)
expected_polygon = [
[12, 56],
[29, 60],
[35, 61],
[42, 59],
[58, 57],
[65, 61],
[72, 57],
[12, 56],
]
assert (
trim_polygon(good_polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
== expected_polygon
)
def test_trim_polygon_invalid_polygon(self):
"""
An assertion error is raised the polygon input isn't a list or tuple
"""
bad_polygon = {
"polygon": [
[99, 200],
@pytest.mark.parametrize(
("polygon", "error"),
[
# Polygon input isn't a list or tuple
(
{
"polygon": [
[99, 200],
[25, 224],
[0, 0],
[0, 300],
[102, 300],
[260, 300],
[288, 295],
[296, 260],
[352, 259],
[106, 210],
[197, 206],
[99, 208],
]
},
"Input polygon must be a valid list or tuple of points.",
),
# Point coordinates are not integers
(
[
[9.9, 200],
[25, 224],
[0, 0],
[0, 300],
......@@ -297,136 +255,161 @@ class TestTrimPolygon(unittest.TestCase):
[352, 259],
[106, 210],
[197, 206],
[99, 208],
]
}
with pytest.raises(
AssertionError,
match="Input polygon must be a valid list or tuple of points.",
):
trim_polygon(bad_polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
def test_trim_polygon_negative_coordinates(self):
"""
Negative coordinates are ignored and replaced by 0 with no error being thrown
"""
bad_polygon = [
[99, 200],
[25, 224],
[-8, -52],
[-12, 350],
[102, 364],
[260, 310],
[288, 295],
[296, 260],
[352, 259],
[106, 210],
[197, 206],
[99, 200],
]
expected_polygon = [
[99, 200],
[25, 224],
[0, 0],
[0, 300],
[102, 300],
[260, 300],
[288, 295],
[296, 260],
[352, 259],
[106, 210],
[197, 206],
[99, 200],
]
assert (
trim_polygon(bad_polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
== expected_polygon
)
[99, 20.8],
],
"Polygon point coordinates must be integers.",
),
# Point coordinates are not lists or tuples
(
[
[12, 56],
[29, 60],
[35, 61],
"[42, 59]",
[58, 57],
[65, 61],
[72, 57],
[12, 56],
],
"Polygon points must be tuples or lists.",
),
# Point coordinates are not lists or tuples of length 2
(
[
[12, 56],
[29, 60, 3],
[35, 61],
[42, 59],
[58, 57],
[65, 61],
[72, 57],
[12, 56],
],
"Polygon points must be tuples or lists of 2 elements.",
),
# None of the polygon's points are inside the image
(
[
[999, 200],
[1097, 224],
[1020, 251],
[1232, 350],
[1312, 364],
[1325, 310],
[1318, 295],
[1296, 260],
[1352, 259],
[1006, 210],
[997, 206],
[999, 200],
],
"This polygon is entirely outside the image's bounds.",
),
],
)
def test_trim_polygon_errors(polygon, error):
with pytest.raises(AssertionError, match=error):
trim_polygon(polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
def test_trim_polygon_outside_image_error(self):
"""
An assertion error is raised when none of the polygon's points are inside the image
"""
bad_polygon = [
[999, 200],
[1097, 224],
[1020, 251],
[1232, 350],
[1312, 364],
[1325, 310],
[1318, 295],
[1296, 260],
[1352, 259],
[1006, 210],
[997, 206],
[999, 200],
]
with pytest.raises(
AssertionError, match="This polygon is entirely outside the image's bounds."
):
trim_polygon(bad_polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
def test_trim_polygon_float_coordinates(self):
"""
An assertion error is raised when point coordinates are not integers
"""
bad_polygon = [
[9.9, 200],
[25, 224],
[0, 0],
[0, 300],
[102, 300],
[260, 300],
[288, 295],
[296, 260],
[352, 259],
[106, 210],
[197, 206],
[99, 20.8],
]
with pytest.raises(
AssertionError, match="Polygon point coordinates must be integers."
):
trim_polygon(bad_polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
def test_trim_polygon_invalid_points_1(self):
"""
An assertion error is raised when point coordinates are not lists or tuples
"""
bad_polygon = [
[12, 56],
[29, 60],
[35, 61],
"[42, 59]",
[58, 57],
[65, 61],
[72, 57],
[12, 56],
]
with pytest.raises(
AssertionError, match="Polygon points must be tuples or lists."
):
trim_polygon(bad_polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
def test_trim_polygon_invalid_points_2(self):
"""
An assertion error is raised when point coordinates are not lists or tuples of length 2
"""
bad_polygon = [
[12, 56],
[29, 60, 3],
[35, 61],
[42, 59],
[58, 57],
[65, 61],
[72, 57],
[12, 56],
]
with pytest.raises(
AssertionError,
match="Polygon points must be tuples or lists of 2 elements.",
):
trim_polygon(bad_polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
def test_trim_polygon_negative_coordinates():
"""
Negative coordinates are ignored and replaced by 0 with no error being thrown
"""
polygon = [
[99, 200],
[25, 224],
[-8, -52],
[-12, 350],
[102, 364],
[260, 310],
[288, 295],
[296, 260],
[352, 259],
[106, 210],
[197, 206],
[99, 200],
]
expected_polygon = [
[99, 200],
[25, 224],
[0, 0],
[0, 300],
[102, 300],
[260, 300],
[288, 295],
[296, 260],
[352, 259],
[106, 210],
[197, 206],
[99, 200],
]
assert (
trim_polygon(polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
== expected_polygon
)
def test_trim_polygon_partially_outside_image():
polygon = [
[99, 200],
[197, 224],
[120, 251],
[232, 350],
[312, 364],
[325, 310],
[318, 295],
[296, 260],
[352, 259],
[106, 210],
[197, 206],
[99, 200],
]
expected_polygon = [
[99, 200],
[197, 224],
[120, 251],
[232, 300],
[312, 300],
[325, 300],
[318, 295],
[296, 260],
[352, 259],
[106, 210],
[197, 206],
[99, 200],
]
assert (
trim_polygon(polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
== expected_polygon
)
def test_trim_polygon():
polygon = (
(12, 56),
(29, 60),
(35, 61),
(42, 59),
(58, 57),
(65, 61),
(72, 57),
(12, 56),
)
expected_polygon = [
[12, 56],
[29, 60],
[35, 61],
[42, 59],
[58, 57],
[65, 61],
[72, 57],
[12, 56],
]
assert (
trim_polygon(polygon, TEST_IMAGE["width"], TEST_IMAGE["height"])
== expected_polygon
)
@pytest.mark.parametrize(
......
......@@ -14,7 +14,7 @@ variables:
DEBIAN_FRONTEND: non-interactive
test:
image: python:slim
image: python:3.12-slim
stage: test
cache:
......@@ -41,7 +41,7 @@ test:
- tox -- --junitxml=test-report.xml --durations=50
lint:
image: python:slim
image: python:3.12-slim
cache:
paths:
......
FROM python:3.11-slim
FROM python:3.12-slim
WORKDIR /src
......
......@@ -23,6 +23,7 @@ classifiers = [
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
[project.scripts]
......@@ -33,6 +34,7 @@ find = {}
[tool.ruff]
exclude = [".git", "__pycache__"]
target-version = "py312"
[tool.ruff.lint]
ignore = ["E501"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment