Skip to content

Commit 59c7290

Browse files
committed
Downgrade requirements to protobuf>=4.23.4; add tests
1 parent 1fa409e commit 59c7290

File tree

6 files changed

+402
-2
lines changed

6 files changed

+402
-2
lines changed

python/pyproject.toml

Lines changed: 135 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ classifiers = [
2828
"Topic :: Software Development",
2929
]
3030
dependencies = [
31-
"protobuf>=4.24.3",
31+
"protobuf>=4.23.4",
3232
]
3333

3434
[project.urls]
@@ -51,3 +51,137 @@ include = ["src"]
5151

5252
[tool.hatch.build.targets.wheel]
5353
packages = ["src/firebird"]
54+
55+
[tool.hatch.envs.test]
56+
dependencies = [
57+
"coverage[toml]>=6.5",
58+
"pytest",
59+
]
60+
[tool.hatch.envs.test.scripts]
61+
test = "pytest {args:tests}"
62+
test-cov = "coverage run -m pytest {args:tests}"
63+
cov-report = [
64+
"- coverage combine",
65+
"coverage report",
66+
]
67+
cov = [
68+
"test-cov",
69+
"cov-report",
70+
]
71+
version = "python --version"
72+
73+
[[tool.hatch.envs.test.matrix]]
74+
python = ["3.8", "3.9", "3.10", "3.11"]
75+
76+
[tool.hatch.envs.doc]
77+
detached = false
78+
platforms = ["linux"]
79+
dependencies = [
80+
"Sphinx>=7.1",
81+
"sphinx-bootstrap-theme>=0.8.1",
82+
"sphinx-autodoc-typehints>=1.24.0",
83+
]
84+
[tool.hatch.envs.doc.scripts]
85+
build = "cd docs ; make html"
86+
87+
[tool.hatch.envs.lint]
88+
detached = true
89+
dependencies = [
90+
"black>=23.1.0",
91+
"mypy>=1.0.0",
92+
"ruff>=0.0.243",
93+
]
94+
[tool.hatch.envs.lint.scripts]
95+
typing = "mypy --install-types --non-interactive {args:src/firebird/uuid tests}"
96+
style = [
97+
"ruff {args:.}",
98+
"black --check --diff {args:.}",
99+
]
100+
fmt = [
101+
"black {args:.}",
102+
"ruff --fix {args:.}",
103+
"style",
104+
]
105+
all = [
106+
"style",
107+
"typing",
108+
]
109+
110+
[tool.black]
111+
target-version = ["py38"]
112+
line-length = 120
113+
skip-string-normalization = true
114+
115+
[tool.ruff]
116+
target-version = "py38"
117+
line-length = 120
118+
select = [
119+
"A",
120+
"ARG",
121+
"B",
122+
"C",
123+
"DTZ",
124+
"E",
125+
"EM",
126+
"F",
127+
"FBT",
128+
"I",
129+
"ICN",
130+
"ISC",
131+
"N",
132+
"PLC",
133+
"PLE",
134+
"PLR",
135+
"PLW",
136+
"Q",
137+
"RUF",
138+
"S",
139+
"T",
140+
"TID",
141+
"UP",
142+
"W",
143+
"YTT",
144+
]
145+
ignore = [
146+
# Allow non-abstract empty methods in abstract base classes
147+
"B027",
148+
# Allow boolean positional values in function calls, like `dict.get(... True)`
149+
"FBT003",
150+
# Ignore checks for possible passwords
151+
"S105", "S106", "S107",
152+
# Ignore complexity
153+
"C901", "PLR0911", "PLR0912", "PLR0913", "PLR0915",
154+
]
155+
unfixable = [
156+
# Don't touch unused imports
157+
"F401",
158+
]
159+
160+
[tool.ruff.isort]
161+
known-first-party = ["firebird.uuid"]
162+
163+
[tool.ruff.flake8-tidy-imports]
164+
ban-relative-imports = "all"
165+
166+
[tool.ruff.per-file-ignores]
167+
# Tests can use magic values, assertions, and relative imports
168+
"tests/**/*" = ["PLR2004", "S101", "TID252"]
169+
170+
[tool.coverage.run]
171+
source_pkgs = ["firebird.uuid", "tests"]
172+
branch = true
173+
parallel = true
174+
omit = [
175+
"src/firebird/uuid/__about__.py",
176+
]
177+
178+
[tool.coverage.paths]
179+
firebird_uuid = ["src/python", "*/python/src/firebird/uuid"]
180+
tests = ["tests", "*/python/tests"]
181+
182+
[tool.coverage.report]
183+
exclude_lines = [
184+
"no cov",
185+
"if __name__ == .__main__.:",
186+
"if TYPE_CHECKING:",
187+
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# SPDX-FileCopyrightText: 2018-present Pavel Cisar <[email protected]>
22
#
33
# SPDX-License-Identifier: MIT
4-
__version__ = "1.0.0"
4+
__version__ = "1.0.1"

python/tests/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-FileCopyrightText: 2022-present The Firebird Projects <www.firebirdsql.org>
2+
#
3+
# SPDX-License-Identifier: MIT

python/tests/test_fbdp.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# SPDX-FileCopyrightText: 2018-present Pavel Cisar <[email protected]>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
ID: butler-fbdp-protobuf
7+
TITLE: FDBP protobuf
8+
DESCRIPTION:
9+
NOTES:
10+
"""
11+
12+
import pytest
13+
import firebird.butler.fbdp_pb2 as fbdp
14+
15+
def test_FBDPOpenDataframe():
16+
DATA_PIPE = 'Data Pipe Identification'
17+
PIPE_SOCKET = 1
18+
DATA_FORMAT = 'Specification of format for transmitted user data'
19+
PARAM1_KEY = 'param1'
20+
PARAM1_VAL = 'value1'
21+
proto = fbdp.FBDPOpenDataframe()
22+
proto.data_pipe = DATA_PIPE
23+
proto.pipe_socket = PIPE_SOCKET
24+
proto.data_format = DATA_FORMAT
25+
proto.parameters[PARAM1_KEY] = PARAM1_VAL
26+
msg = proto.SerializeToString()
27+
proto.Clear()
28+
proto.ParseFromString(msg)
29+
assert proto.data_pipe == DATA_PIPE
30+
assert proto.pipe_socket == PIPE_SOCKET
31+
assert proto.data_format == DATA_FORMAT
32+
assert proto.parameters[PARAM1_KEY] == PARAM1_VAL

python/tests/test_fbsd.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# SPDX-FileCopyrightText: 2018-present Pavel Cisar <[email protected]>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
ID: butler-fbsd-protobuf
7+
TITLE: FDSD protobuf
8+
DESCRIPTION:
9+
NOTES:
10+
"""
11+
12+
import pytest
13+
import uuid
14+
import firebird.butler.fbsd_pb2 as fbsd
15+
16+
_PEER_UID = uuid.uuid1().bytes
17+
_PID = 100
18+
_HOST = 'host'
19+
_AGENT_UID = uuid.uuid1().bytes
20+
_NAME = 'Agent name'
21+
_AGENT_VERSION = 'agent version'
22+
_VENDOR_ID = uuid.uuid1().bytes
23+
_PLATFORM_ID = uuid.uuid1().bytes
24+
_PLATFORM_VERSION = 'platform version'
25+
_CLASSIFICATION = 'classification'
26+
_API_NUM = 1
27+
_API_ID = uuid.uuid1().bytes
28+
_ERR_CODE = 100
29+
_ERR_DESCRIPTION = "Fatal error"
30+
_ERR_CONTEXT_KEY = "Context key"
31+
_ERR_CONTEXT_VALUE = "Context value"
32+
_ERR_ANNOTATION_KEY = "Annotation key"
33+
_ERR_ANNOTATION_VALUE = "Annotation value"
34+
35+
def test_StateEnum():
36+
assert fbsd.StateEnum.STATE_RUNNING is fbsd.STATE_RUNNING
37+
38+
def test_AddressDomainEnum():
39+
assert fbsd.AddressDomainEnum.DOMAIN_LOCAL is fbsd.DOMAIN_LOCAL
40+
41+
def test_TransportProtocolEnum():
42+
assert fbsd.TransportProtocolEnum.PROTOCOL_INPROC is fbsd.PROTOCOL_INPROC
43+
44+
def test_SocketTypeEnum():
45+
assert fbsd.SocketTypeEnum.SOCKET_TYPE_ROUTER is fbsd.SOCKET_TYPE_ROUTER
46+
47+
def test_SocketUseEnum():
48+
assert fbsd.SocketUseEnum.SOCKET_USE_PRODUCER is fbsd.SOCKET_USE_PRODUCER
49+
50+
def test_DependencyTypeEnum():
51+
assert fbsd.DependencyTypeEnum.DEPTYPE_REQUIRED is fbsd.DEPTYPE_REQUIRED
52+
53+
def test_PlatformId():
54+
proto = fbsd.PlatformId()
55+
proto.uid = _PLATFORM_ID
56+
proto.version = _PLATFORM_VERSION
57+
msg = proto.SerializeToString()
58+
proto.Clear()
59+
proto.ParseFromString(msg)
60+
assert proto.uid == _PLATFORM_ID
61+
assert proto.version == _PLATFORM_VERSION
62+
63+
def test_VendorId():
64+
proto = fbsd.VendorId()
65+
proto.uid = _VENDOR_ID
66+
msg = proto.SerializeToString()
67+
proto.Clear()
68+
proto.ParseFromString(msg)
69+
assert proto.uid == _VENDOR_ID
70+
71+
def test_AgentIdentification():
72+
proto = fbsd.AgentIdentification()
73+
proto.uid = _AGENT_UID
74+
proto.name = _NAME
75+
proto.version = _AGENT_VERSION
76+
proto.vendor.uid = _VENDOR_ID
77+
proto.platform.uid = _PLATFORM_ID
78+
proto.platform.version = _PLATFORM_VERSION
79+
proto.classification = _CLASSIFICATION
80+
msg = proto.SerializeToString()
81+
proto.Clear()
82+
proto.ParseFromString(msg)
83+
assert proto.uid == _AGENT_UID
84+
assert proto.name == _NAME
85+
assert proto.version == _AGENT_VERSION
86+
assert proto.vendor.uid == _VENDOR_ID
87+
assert proto.platform.uid == _PLATFORM_ID
88+
assert proto.platform.version == _PLATFORM_VERSION
89+
assert proto.classification == _CLASSIFICATION
90+
91+
def test_PeerIdentification():
92+
proto = fbsd.PeerIdentification()
93+
proto.uid = _PEER_UID
94+
proto.host = _HOST
95+
proto.pid = _PID
96+
msg = proto.SerializeToString()
97+
proto.Clear()
98+
proto.ParseFromString(msg)
99+
assert proto.uid == _PEER_UID
100+
assert proto.host == _HOST
101+
assert proto.pid == _PID
102+
103+
def test_InterfaceSpec():
104+
proto = fbsd.InterfaceSpec(number=_API_NUM, uid=_API_ID)
105+
msg = proto.SerializeToString()
106+
proto.Clear()
107+
proto.ParseFromString(msg)
108+
assert proto.number == _API_NUM
109+
assert proto.uid == _API_ID
110+
111+
def test_ErrorDescription():
112+
proto = fbsd.ErrorDescription()
113+
proto.code = _ERR_CODE
114+
proto.description = _ERR_DESCRIPTION
115+
proto.context[_ERR_CONTEXT_KEY] = _ERR_CONTEXT_VALUE
116+
proto.annotation[_ERR_ANNOTATION_KEY] = _ERR_ANNOTATION_VALUE
117+
msg = proto.SerializeToString()
118+
proto.Clear()
119+
proto.ParseFromString(msg)
120+
assert proto.code == _ERR_CODE
121+
assert proto.description == _ERR_DESCRIPTION
122+
assert proto.context[_ERR_CONTEXT_KEY] == _ERR_CONTEXT_VALUE
123+
assert proto.annotation[_ERR_ANNOTATION_KEY] == _ERR_ANNOTATION_VALUE

0 commit comments

Comments
 (0)