enapter 0.6.3__py3-none-any.whl → 0.12.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- enapter/__init__.py +4 -4
- enapter/async_/__init__.py +1 -4
- enapter/async_/generator.py +5 -2
- enapter/async_/routine.py +21 -53
- enapter/http/__init__.py +3 -0
- enapter/http/api/__init__.py +5 -0
- enapter/http/api/client.py +31 -0
- enapter/http/api/config.py +23 -0
- enapter/http/api/devices/__init__.py +21 -0
- enapter/http/api/devices/authorized_role.py +11 -0
- enapter/http/api/devices/client.py +25 -0
- enapter/http/api/devices/communication_config.py +45 -0
- enapter/http/api/devices/device.py +32 -0
- enapter/http/api/devices/device_type.py +10 -0
- enapter/http/api/devices/mqtt_credentials.py +13 -0
- enapter/http/api/devices/mqtt_protocol.py +7 -0
- enapter/http/api/devices/mqtts_credentials.py +18 -0
- enapter/http/api/devices/time_sync_protocol.py +6 -0
- enapter/log/json_formatter.py +14 -4
- enapter/mdns/resolver.py +14 -11
- enapter/mqtt/__init__.py +5 -12
- enapter/mqtt/api/__init__.py +6 -0
- enapter/mqtt/api/client.py +62 -0
- enapter/mqtt/api/config.py +77 -0
- enapter/mqtt/api/device/__init__.py +21 -0
- enapter/mqtt/api/device/channel.py +56 -0
- enapter/mqtt/api/device/command_request.py +38 -0
- enapter/mqtt/api/device/command_response.py +28 -0
- enapter/mqtt/api/device/command_state.py +8 -0
- enapter/mqtt/api/device/log.py +31 -0
- enapter/mqtt/api/device/log_severity.py +9 -0
- enapter/mqtt/api/device/message.py +24 -0
- enapter/mqtt/api/device/properties.py +24 -0
- enapter/mqtt/api/device/telemetry.py +28 -0
- enapter/mqtt/client.py +88 -119
- enapter/mqtt/errors.py +3 -0
- enapter/mqtt/message.py +3 -0
- enapter/standalone/__init__.py +25 -0
- enapter/standalone/config.py +218 -0
- enapter/standalone/device.py +59 -0
- enapter/standalone/device_protocol.py +33 -0
- enapter/standalone/logger.py +21 -0
- enapter/standalone/mqtt_adapter.py +134 -0
- enapter/standalone/run.py +39 -0
- enapter/standalone/ucm.py +28 -0
- enapter-0.12.1.dist-info/METADATA +74 -0
- enapter-0.12.1.dist-info/RECORD +52 -0
- {enapter-0.6.3.dist-info → enapter-0.12.1.dist-info}/WHEEL +1 -1
- {enapter-0.6.3.dist-info → enapter-0.12.1.dist-info}/top_level.txt +0 -1
- enapter/mqtt/command.py +0 -45
- enapter/mqtt/config.py +0 -48
- enapter/mqtt/device_channel.py +0 -83
- enapter/types.py +0 -3
- enapter/vucm/__init__.py +0 -12
- enapter/vucm/app.py +0 -48
- enapter/vucm/config.py +0 -59
- enapter/vucm/device.py +0 -92
- enapter/vucm/logger.py +0 -39
- enapter/vucm/ucm.py +0 -30
- enapter-0.6.3.dist-info/METADATA +0 -111
- enapter-0.6.3.dist-info/RECORD +0 -27
- tests/test_async.py +0 -152
- tests/test_log.py +0 -69
- /tests/__init__.py → /enapter/py.typed +0 -0
tests/test_async.py
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
|
|
3
|
-
import pytest
|
|
4
|
-
|
|
5
|
-
import enapter
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class TestGenerator:
|
|
9
|
-
async def test_aclose(self):
|
|
10
|
-
@enapter.async_.generator
|
|
11
|
-
async def agen():
|
|
12
|
-
yield 1
|
|
13
|
-
yield 2
|
|
14
|
-
yield 3
|
|
15
|
-
|
|
16
|
-
async with agen() as g:
|
|
17
|
-
assert await g.__anext__() == 1
|
|
18
|
-
assert await g.__anext__() == 2
|
|
19
|
-
|
|
20
|
-
with pytest.raises(StopAsyncIteration):
|
|
21
|
-
await g.__anext__()
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class TestRoutine:
|
|
25
|
-
async def test_run_not_implemented(self):
|
|
26
|
-
class R(enapter.async_.Routine):
|
|
27
|
-
pass
|
|
28
|
-
|
|
29
|
-
with pytest.raises(TypeError):
|
|
30
|
-
R()
|
|
31
|
-
|
|
32
|
-
async def test_context_manager(self):
|
|
33
|
-
done = asyncio.Event()
|
|
34
|
-
|
|
35
|
-
class R(enapter.async_.Routine):
|
|
36
|
-
async def _run(self):
|
|
37
|
-
self._started.set()
|
|
38
|
-
await asyncio.sleep(0)
|
|
39
|
-
done.set()
|
|
40
|
-
|
|
41
|
-
async with R():
|
|
42
|
-
await asyncio.sleep(0)
|
|
43
|
-
|
|
44
|
-
await asyncio.wait_for(done.wait(), 1)
|
|
45
|
-
|
|
46
|
-
async def test_task_getter(self):
|
|
47
|
-
can_exit = asyncio.Event()
|
|
48
|
-
|
|
49
|
-
class R(enapter.async_.Routine):
|
|
50
|
-
async def _run(self):
|
|
51
|
-
self._started.set()
|
|
52
|
-
await asyncio.wait_for(can_exit.wait(), 1)
|
|
53
|
-
|
|
54
|
-
async with R() as r:
|
|
55
|
-
assert not r.task().done()
|
|
56
|
-
can_exit.set()
|
|
57
|
-
|
|
58
|
-
assert r.task().done()
|
|
59
|
-
|
|
60
|
-
async def test_started_fine(self):
|
|
61
|
-
done = asyncio.Event()
|
|
62
|
-
|
|
63
|
-
class R(enapter.async_.Routine):
|
|
64
|
-
async def _run(self):
|
|
65
|
-
await asyncio.sleep(0)
|
|
66
|
-
self._started.set()
|
|
67
|
-
await asyncio.sleep(0)
|
|
68
|
-
done.set()
|
|
69
|
-
await asyncio.sleep(10)
|
|
70
|
-
|
|
71
|
-
r = R()
|
|
72
|
-
await r.start(cancel_parent_task_on_exception=False)
|
|
73
|
-
try:
|
|
74
|
-
await asyncio.wait_for(done.wait(), 1)
|
|
75
|
-
finally:
|
|
76
|
-
await r.stop()
|
|
77
|
-
|
|
78
|
-
async def test_finished_after_started(self):
|
|
79
|
-
class R(enapter.async_.Routine):
|
|
80
|
-
async def _run(self):
|
|
81
|
-
self._started.set()
|
|
82
|
-
await asyncio.sleep(0)
|
|
83
|
-
|
|
84
|
-
r = R()
|
|
85
|
-
await r.start(cancel_parent_task_on_exception=False)
|
|
86
|
-
await asyncio.wait_for(r.join(), 1)
|
|
87
|
-
|
|
88
|
-
async def test_finished_before_started(self):
|
|
89
|
-
class R(enapter.async_.Routine):
|
|
90
|
-
async def _run(self):
|
|
91
|
-
await asyncio.sleep(0)
|
|
92
|
-
|
|
93
|
-
r = R()
|
|
94
|
-
await r.start(cancel_parent_task_on_exception=False)
|
|
95
|
-
await asyncio.wait_for(r.join(), 1)
|
|
96
|
-
|
|
97
|
-
async def test_failed_before_started(self):
|
|
98
|
-
class R(enapter.async_.Routine):
|
|
99
|
-
async def _run(self):
|
|
100
|
-
await asyncio.sleep(0)
|
|
101
|
-
raise RuntimeError()
|
|
102
|
-
|
|
103
|
-
r = R()
|
|
104
|
-
with pytest.raises(RuntimeError):
|
|
105
|
-
await r.start(cancel_parent_task_on_exception=False)
|
|
106
|
-
|
|
107
|
-
async def test_failed_after_started(self):
|
|
108
|
-
can_fail = asyncio.Event()
|
|
109
|
-
|
|
110
|
-
class R(enapter.async_.Routine):
|
|
111
|
-
async def _run(self):
|
|
112
|
-
self._started.set()
|
|
113
|
-
await asyncio.wait_for(can_fail.wait(), 1)
|
|
114
|
-
raise RuntimeError()
|
|
115
|
-
|
|
116
|
-
r = R()
|
|
117
|
-
await r.start(cancel_parent_task_on_exception=False)
|
|
118
|
-
can_fail.set()
|
|
119
|
-
with pytest.raises(RuntimeError):
|
|
120
|
-
await r.join()
|
|
121
|
-
|
|
122
|
-
async def test_cancel_parent_task_on_exception_after_started(self):
|
|
123
|
-
can_fail = asyncio.Event()
|
|
124
|
-
|
|
125
|
-
class R(enapter.async_.Routine):
|
|
126
|
-
async def _run(self):
|
|
127
|
-
self._started.set()
|
|
128
|
-
await asyncio.wait_for(can_fail.wait(), 1)
|
|
129
|
-
raise RuntimeError()
|
|
130
|
-
|
|
131
|
-
r = R()
|
|
132
|
-
|
|
133
|
-
async def parent():
|
|
134
|
-
await r.start()
|
|
135
|
-
can_fail.set()
|
|
136
|
-
with pytest.raises(asyncio.CancelledError):
|
|
137
|
-
await asyncio.wait_for(asyncio.sleep(2), 1)
|
|
138
|
-
|
|
139
|
-
parent_task = asyncio.create_task(parent())
|
|
140
|
-
await parent_task
|
|
141
|
-
|
|
142
|
-
with pytest.raises(RuntimeError):
|
|
143
|
-
await r.join()
|
|
144
|
-
|
|
145
|
-
async def test_do_not_cancel_parent_task_on_exception_before_started(self):
|
|
146
|
-
class R(enapter.async_.Routine):
|
|
147
|
-
async def _run(self):
|
|
148
|
-
raise RuntimeError()
|
|
149
|
-
|
|
150
|
-
r = R()
|
|
151
|
-
with pytest.raises(RuntimeError):
|
|
152
|
-
await r.start()
|
tests/test_log.py
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import contextlib
|
|
2
|
-
import io
|
|
3
|
-
import json
|
|
4
|
-
import re
|
|
5
|
-
|
|
6
|
-
import enapter
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class TestJSONFormat:
|
|
10
|
-
def test_record_ends_with_newline(self):
|
|
11
|
-
buf = io.StringIO()
|
|
12
|
-
|
|
13
|
-
with self.configure(level="info", stream=buf):
|
|
14
|
-
enapter.log.LOGGER.info("hello")
|
|
15
|
-
|
|
16
|
-
assert buf.getvalue().endswith("\n")
|
|
17
|
-
|
|
18
|
-
def test_record_fields(self):
|
|
19
|
-
buf = io.StringIO()
|
|
20
|
-
|
|
21
|
-
with self.configure(level="info", stream=buf):
|
|
22
|
-
enapter.log.LOGGER.info("hello")
|
|
23
|
-
|
|
24
|
-
record = json.loads(buf.getvalue())
|
|
25
|
-
|
|
26
|
-
time = record.pop("time")
|
|
27
|
-
assert re.match(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+", time) is not None
|
|
28
|
-
|
|
29
|
-
assert record == {
|
|
30
|
-
"level": "INFO",
|
|
31
|
-
"name": "enapter",
|
|
32
|
-
"message": "hello",
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
def test_exc_info(self):
|
|
36
|
-
buf = io.StringIO()
|
|
37
|
-
|
|
38
|
-
with self.configure(level="info", stream=buf):
|
|
39
|
-
try:
|
|
40
|
-
raise RuntimeError("oops")
|
|
41
|
-
except RuntimeError:
|
|
42
|
-
enapter.log.LOGGER.exception("boom")
|
|
43
|
-
|
|
44
|
-
record = json.loads(buf.getvalue())
|
|
45
|
-
|
|
46
|
-
assert record["message"] == "boom"
|
|
47
|
-
assert "Traceback (most recent call last)" in record["exc_info"]
|
|
48
|
-
assert 'RuntimeError("oops")' in record["exc_info"]
|
|
49
|
-
|
|
50
|
-
def test_stack_info(self):
|
|
51
|
-
buf = io.StringIO()
|
|
52
|
-
|
|
53
|
-
with self.configure(level="info", stream=buf):
|
|
54
|
-
enapter.log.LOGGER.info("hello", stack_info=True)
|
|
55
|
-
|
|
56
|
-
record = json.loads(buf.getvalue())
|
|
57
|
-
|
|
58
|
-
assert record["message"] == "hello"
|
|
59
|
-
assert "Stack (most recent call last)" in record["stack_info"]
|
|
60
|
-
assert "test_stack_info" in record["stack_info"]
|
|
61
|
-
|
|
62
|
-
@staticmethod
|
|
63
|
-
@contextlib.contextmanager
|
|
64
|
-
def configure(*args, **kwargs):
|
|
65
|
-
enapter.log.configure(*args, **kwargs)
|
|
66
|
-
try:
|
|
67
|
-
yield
|
|
68
|
-
finally:
|
|
69
|
-
enapter.log.configure(level=None)
|
|
File without changes
|