Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.

Commit a752861

Browse files
Test CIDR directly
1 parent ab473ef commit a752861

2 files changed

Lines changed: 38 additions & 15 deletions

File tree

pyproject.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ dependencies = [
4444
"greenlet>=3.0.0a1",
4545
"sqlalchemy>=1.4",
4646
"sqlean-py>=0.21.5.1",
47-
'typing-extensions; python_version < "3.10"',
4847
]
4948
[project.optional-dependencies]
5049
dev = [
5150
"pytest",
51+
'typing-extensions; python_version < "3.10"',
5252
]
5353
[project.urls]
5454
Changelog = "https://github.com/edgarrmondragon/sqlean-driver/blob/main/CHANGELOG.md"
@@ -64,10 +64,10 @@ source = "vcs"
6464
[tool.hatch.envs.test]
6565
dependencies = [
6666
"coverage[toml]>=6.5",
67-
"pytest",
6867
"pytest-github-actions-annotate-failures",
6968
"sqlalchemy=={matrix:sqlalchemy:2}.*",
7069
]
70+
features = ["dev"]
7171
matrix-name-format = "{variable}_{value}"
7272
[tool.hatch.envs.test.env-vars]
7373
SQLALCHEMY_WARN_20 = "1"
@@ -89,7 +89,8 @@ xml = "coverage xml"
8989
report = ["coverage combine", "coverage report --show-missing"]
9090

9191
[tool.hatch.envs.typing]
92-
dependencies = ["mypy>=1.0.0", "pytest"]
92+
dependencies = ["mypy>=1.0.0"]
93+
features = ["dev"]
9394
[tool.hatch.envs.typing.scripts]
9495
check = "mypy --strict --install-types --non-interactive {args:src/sqlean_driver tests}"
9596

@@ -209,6 +210,7 @@ select = [
209210
target-version = "py38"
210211
unfixable = [
211212
"ERA",
213+
"F401",
212214
]
213215

214216
[tool.ruff.isort]

tests/test_types.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,34 @@
22

33
from __future__ import annotations
44

5-
import ipaddress
65
import sys
76
import typing as t
87
import uuid
8+
from ipaddress import IPv4Interface, IPv4Network, IPv6Interface
99

1010
import pytest
11-
from sqlalchemy import Column, Integer, MetaData, Table, create_engine, func, select
11+
from sqlalchemy import (
12+
Column,
13+
Integer,
14+
MetaData,
15+
Table,
16+
create_engine,
17+
func,
18+
select,
19+
)
1220

13-
from sqlean_driver.custom_types import INET, UUID
21+
from sqlean_driver.custom_types import CIDR, INET, UUID
1422

1523
if t.TYPE_CHECKING:
1624
from sqlalchemy import Select
1725

1826
metadata = MetaData()
1927
table = Table(
20-
"table",
28+
"test_table",
2129
metadata,
2230
Column("id", Integer, primary_key=True),
2331
Column("ip", INET),
32+
Column("cidr", CIDR),
2433
Column("uuid_col", UUID),
2534
)
2635

@@ -39,34 +48,46 @@
3948
id="nullable",
4049
),
4150
pytest.param(
42-
[{"ip": ipaddress.IPv4Network("192.168.1.1")}],
51+
[{"cidr": None}],
52+
select(table.c.cidr),
53+
(None,),
54+
id="nullable_cidr",
55+
),
56+
pytest.param(
57+
[{"cidr": IPv4Network("192.168.16.3/32")}],
58+
select(table.c.cidr),
59+
(IPv4Network("192.168.16.3/32"),),
60+
id="cidr",
61+
),
62+
pytest.param(
63+
[{"ip": IPv4Network("192.168.1.1")}],
4364
select(func.ipfamily(table.c.ip), table.c.ip.ipfamily()),
4465
(4, 4),
4566
id="ipfamily",
4667
),
4768
pytest.param(
48-
[{"ip": ipaddress.IPv6Interface("2001:db8::123/64")}],
69+
[{"ip": IPv6Interface("2001:db8::123/64")}],
4970
select(func.iphost(table.c.ip), table.c.ip.iphost()),
5071
("2001:db8::123", "2001:db8::123"),
5172
id="iphost",
5273
),
5374
pytest.param(
54-
[{"ip": ipaddress.IPv4Interface("192.168.16.12/24")}],
75+
[{"ip": IPv4Interface("192.168.16.12/24")}],
5576
select(func.ipmasklen(table.c.ip), table.c.ip.ipmasklen()),
5677
(24, 24),
5778
id="ipmasklen",
5879
),
5980
pytest.param(
60-
[{"ip": ipaddress.IPv4Interface("192.168.16.12/24")}],
81+
[{"ip": IPv4Interface("192.168.16.12/24")}],
6182
select(func.ipnetwork(table.c.ip), table.c.ip.ipnetwork()),
6283
(
63-
ipaddress.IPv4Network("192.168.16.0/24"),
64-
ipaddress.IPv4Network("192.168.16.0/24"),
84+
IPv4Network("192.168.16.0/24"),
85+
IPv4Network("192.168.16.0/24"),
6586
),
6687
id="ipnetwork",
6788
),
6889
pytest.param(
69-
[{"ip": ipaddress.IPv4Interface("192.168.16.0/24")}],
90+
[{"ip": IPv4Interface("192.168.16.0/24")}],
7091
select(
7192
func.ipcontains(table.c.ip, "192.168.16.3"),
7293
table.c.ip.ipcontains("192.168.16.3"),
@@ -75,7 +96,7 @@
7596
id="ipcontains_lhs",
7697
),
7798
pytest.param(
78-
[{"ip": ipaddress.IPv4Interface("192.168.16.3")}],
99+
[{"ip": IPv4Interface("192.168.16.3")}],
79100
select(
80101
func.ipcontains("192.168.16.0/24", table.c.ip),
81102
),

0 commit comments

Comments
 (0)