forked from eclipse-basyx/basyx-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path_test_helper.py
More file actions
56 lines (43 loc) · 1.86 KB
/
Copy path_test_helper.py
File metadata and controls
56 lines (43 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import datetime
import io
import logging
from typing import Literal, Optional, Type
import pyecma376_2
from basyx.aas.examples.data import TEST_PDF_FILE, create_example_aas_binding
def create_example_aas_core_properties() -> pyecma376_2.OPCCoreProperties:
"""Create core properties similar to the example AASX file."""
cp = pyecma376_2.OPCCoreProperties()
cp.created = datetime.datetime(2020, 1, 1, 0, 0, 0)
cp.creator = "Eclipse BaSyx Python Testing Framework"
cp.description = "Test_Description"
cp.lastModifiedBy = "Eclipse BaSyx Python Testing Framework Compliance Tool"
cp.modified = datetime.datetime(2020, 1, 1, 0, 0, 1)
cp.revision = "1.0"
cp.version = "2.0.1"
cp.title = "Test Title"
return cp
def create_read_into_mock(file: Literal['TestFile', 'TestFileWrong', None]):
""""Creates side effect function for the AASXReader.read_into mock"""
def fill_stores(store, file_store, **kwargs) -> None:
for item in create_example_aas_binding():
store.add(item)
if file == 'TestFile':
with open(TEST_PDF_FILE, 'rb') as f:
file_store.add_file("/TestFile.pdf", f, "application/pdf")
elif file == 'TestFileWrong':
file_store.add_file("/TestFile.pdf", io.BytesIO(b"dummy"), "application/pdf")
return fill_stores
def create_mock_effect(
module: str,
level: Literal['error', 'warning', 'info', 'debug'],
error_cls: Type[Exception] = ValueError,
error_msg: Optional[str] = None
):
"""Create mock function, that raises or logs error (based on `failsafe` argument)"""
error_msg = error_msg or f"Test {level}!"
def mock_error(*args, **kwargs):
if kwargs.get('failsafe', True):
getattr(logging.getLogger(module), level)(error_msg)
else:
raise error_cls(error_msg)
return mock_error