qass.tools.analyzer.testing
Classes:
| Name | Description |
|---|---|
MockBuffer |
Mock buffer class that is able to parse JSON encoded files. |
MockBuffer
dataclass
Mock buffer class that is able to parse JSON encoded files. All attributes in the JSON are added as fields in the object.
Note
Currently this only allows the mocking of header attributes
Example
Example
# By writing the desired attributes to a json file
import json
from pathlib import Path
from qass.tools.analyzer.testing import MockBuffer
file = Path("testfile.json")
with open("file", "w") as f:
json.dump({"header_hash": "0", "process": 1})
buffer = MockBuffer(file)
# this step will load the json file into the dataclass
with buffer:
pass
Methods:
| Name | Description |
|---|---|
__enter__ |
Opens the file specified by |
__exit__ |
|
__init__ |
|
Attributes:
| Name | Type | Description |
|---|---|---|
filepath |
|
Source code in src/qass/tools/analyzer/testing.py
__enter__
Opens the file specified by self.filepath, parses its JSON content,
and populates the instance attributes with the loaded data. All key-value
pairs from the JSON file are dynamically set as attributes on this instance.
:returns: The instance itself with attributes populated from the file. :rtype: self
Raises:
| Type | Description |
|---|---|
InvalidFileError
|
If the file is not a valid Buffer JSON file. |
FileNotFoundError
|
If the specified filepath does not exist. |
PermissionError
|
If there are insufficient permissions to read the file. |
Note
This method is automatically called when entering a with statement.