Skip to content

Commit e4f73c1

Browse files
Adding tests (#2)
adding tests
1 parent b7412e1 commit e4f73c1

16 files changed

Lines changed: 2052 additions & 77 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ dask-worker-space
4141
# Example for local test
4242
example/
4343
utils/
44+
45+
# Other files
46+
requirements.txt
47+
doc/

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,19 @@ simply run
5858
```
5959
to have pre-commit install the new version.
6060

61-
To bump a new version of the project simply run:
61+
To bump a new version of the project simply publish a release name 'vX.X.X' with X replaced by your numbers
62+
63+
Test
64+
----------
65+
66+
Run tests with poetry
6267
```console
63-
poetry version [patch, minor, major]
68+
poetry run pytest -v --cache-clear -rf --cov=etpproto/ --cov-report=term --cov-report=html --maxfail=10
6469
```
65-
You must choose between the semver rules [patch, minor, major]
70+
71+
Test the code validity :
72+
```console
73+
poetry run black .
74+
poetry run flake8 .
75+
poetry run mypy etpproto
76+
```

etpproto/client_info.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from typing import Any, ClassVar, Dict, Union
22

3+
from dataclasses import dataclass, field
4+
35
from etptypes.energistics.etp.v12.protocol.core.open_session import OpenSession
46
from etptypes.energistics.etp.v12.protocol.core.request_session import (
57
RequestSession,
@@ -8,25 +10,22 @@
810
from etpproto.endpoint_capability_kind import kind_from_name
911

1012

13+
@dataclass
1114
class ClientInfo:
1215
count_instance: ClassVar[int] = 0
1316

14-
endpoint_capabilities: Dict[str, Any] = {}
15-
16-
def __init__(
17-
self,
18-
ip: str = "0.0.0.0",
19-
login: str = "anonymousUser",
20-
endpoint_capabilities: Dict[str, Any] = {
17+
endpoint_capabilities: Dict[str, Any] = field(
18+
default_factory=lambda: {
2119
"MaxWebSocketFramePayloadSize": 10000,
2220
"MaxWebSocketMessagePayloadSize": 10000,
23-
},
24-
):
21+
}
22+
)
23+
login: str = field(default="anonymousUser")
24+
ip: str = field(default="0.0.0.0")
25+
26+
def __post_init__(self):
2527
self._id = self.count_instance
2628
ClientInfo.count_instance = ClientInfo.count_instance + 1
27-
self.ip = ip
28-
self.login = login
29-
self.endpoint_capabilities = endpoint_capabilities
3029

3130
def getCapability(self, name: str) -> Any:
3231
if name in self.endpoint_capabilities:
@@ -52,6 +51,7 @@ def negotiate(self, msg: Union[OpenSession, RequestSession]):
5251
val = max(val, cap_class._min)
5352
if cap_class._max is not None:
5453
val = min(val, cap_class._max)
54+
5555
self.endpoint_capabilities[k] = val
5656

5757
print("Negotiated capa : ", self.endpoint_capabilities)

etpproto/connection.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ class ETPConnection:
141141
# \____/\__,_/\___/_/ /_/\___/ / .___/\____/\__,_/_/ /_/\___/____/ \____/_/ /_/\__,_/_/ /_/_/|_/____/ /_/ /_/ /_/\___/____/____/\__,_/\__, /\___/
142142
# /_/ /____/
143143

144-
chunk_msg_cache: ClassVar[dict] = field(
145-
default={}
146-
) #: Dict[int, Message] = field(default_factory={})
144+
chunk_msg_cache: Dict[int, List[Message]] = field(
145+
default_factory=lambda: {}
146+
)
147147

148-
error_msg_cache: ClassVar[dict] = field(
149-
default={}
150-
) #: Dict[int, List[Optional[Message]]] = field(default_factory={})
148+
error_msg_cache: Dict[int, List[Optional[Message]]] = field(
149+
default_factory=lambda: {}
150+
)
151151

152152
client_info: ClientInfo = field(default=ClientInfo())
153153

etpproto/endpoint_capability_kind.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class SupportsAlternateRequestUris(EndpointCapabilityKind):
234234

235235
_default = False
236236
_unit = None
237-
value: Optional[int] = field(default=False)
237+
value: Optional[bool] = field(default=False)
238238

239239

240240
@dataclass
@@ -245,7 +245,7 @@ class SupportsMessageHeaderExtensions(EndpointCapabilityKind):
245245

246246
_default = False
247247
_unit = None
248-
value: Optional[int] = field(default=False)
248+
value: Optional[bool] = field(default=False)
249249

250250

251251
def kind_from_name(classname):

etpproto/messages.py

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,19 @@ def decode_binary_message(
388388
return_record_name_override=True,
389389
)
390390

391+
print("HEADER", recMH, flush=True)
392+
391393
print(
392394
"classmethod decode_binary_message", object_res, flush=True
393395
)
396+
print(" ==> object_class ", object_class)
394397

395398
return Message(
396399
mh.MessageHeader.parse_obj(recMH),
397400
object_class.parse_obj(object_res),
398401
)
399-
except Exception:
402+
except Exception as e:
403+
print(e)
400404
# error, now we try to read it as an error, because error has now the protocol of the message send by the clien
401405
# try:
402406
object_class = dict_map_pro_to_class["0"][
@@ -486,34 +490,6 @@ def decode_binary_message(
486490
)
487491

488492

489-
# Ecrit un message complet a partir d'un objet ETP dans un BytesIO
490-
# Retourne le nouveau msg_id
491-
def write_etp_message(
492-
bio: BytesIO,
493-
msg_id: int,
494-
etp_object: ETPModel,
495-
message_flags: int = 0,
496-
) -> int:
497-
header_schema = json.loads(avro_schema(mh.MessageHeader))
498-
objSchema = json.loads(avro_schema(type(etp_object)))
499-
500-
header = mh.MessageHeader(
501-
protocol=int(objSchema["protocol"]),
502-
messageType=int(objSchema["messageType"]),
503-
correlationId=0,
504-
messageId=msg_id,
505-
messageFlags=message_flags,
506-
)
507-
508-
objectDict = etp_object.dict(by_alias=True)
509-
510-
print("write_etp_message", objectDict, flush=True)
511-
512-
schemaless_writer(bio, header_schema, header.dict(by_alias=True))
513-
schemaless_writer(bio, objSchema, objectDict)
514-
return msg_id + 1
515-
516-
517493
# When calling thins function we are supposed to have only one entry in the data_objects map/list
518494
async def _encode_message_generator_chunk(
519495
chunkable_msg: Message,

etpproto/uri.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def validate(uri: str) -> bool:
7676
return re.match(CANONICAL_DATA_OBJECT_URIS, uri) is not None
7777

7878

79-
def findUuid(input: str) -> Optional[str]:
79+
def find_uuid(input: str) -> Optional[str]:
8080
p = re.compile(UUID_REGEX)
8181
result = p.search(input)
8282
if result is not None:

poetry.lock

Lines changed: 8 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,36 @@ maintainers = [
1515
]
1616
license = "Apache-2.0"
1717
readme = "README.md"
18-
repository = "https://github.com/bp/resqpy"
18+
repository = "https://github.com/geosiris-technologies/etpproto-python"
1919
homepage = "http://www.geosiris.com"
2020
classifiers = [
21-
"Programming Language :: Python :: 3.9",
21+
"Development Status :: 4 - Beta",
22+
"Environment :: Web Environment",
23+
"Intended Audience :: Developers",
24+
"Intended Audience :: Information Technology",
25+
"License :: OSI Approved :: Apache Software License",
2226
"License :: OSI Approved :: Apache Software License",
27+
"Operating System :: OS Independent",
28+
"Programming Language :: Python :: 3",
29+
"Programming Language :: Python :: 3.10",
30+
"Programming Language :: Python :: 3.8",
31+
"Programming Language :: Python :: 3.9",
32+
"Programming Language :: Python",
33+
"Topic :: Internet :: WWW/HTTP",
34+
"Topic :: Internet",
35+
"Topic :: Software Development :: Libraries :: Application Frameworks",
36+
"Topic :: Software Development :: Libraries :: Python Modules",
37+
"Topic :: Software Development :: Libraries",
38+
"Topic :: Software Development",
39+
"Typing :: Typed",
2340
]
2441
keywords = ["ETP"]
2542

2643
[tool.poetry.dependencies]
2744
python = "^3.9,<3.11"
28-
fastavro = "1.5.3"
45+
fastavro = "^1.6.1"
2946
coverage = {extras = ["toml"], version = "^6.2"}
30-
etptypes = "^1.0.0"
47+
etptypes = "^1.0.1"
3148

3249
[tool.poetry.dev-dependencies]
3350
pytest = "^7.0.0"

0 commit comments

Comments
 (0)