Skip to content

import_measurement

A simple measurement class derived from ExternalMeasurement, to import data.

ImportMeasurement

Bases: ExternalMeasurement

Simple class derived from ExternalMeasurement that loads data from a JSON file and wraps it in an Opaque evidence type.

Source code in mlte/measurement/import_measurement.py
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
class ImportMeasurement(ExternalMeasurement):
    """Simple class derived from ExternalMeasurement that loads data from a JSON file and wraps it in an Opaque evidence type."""

    def __init__(
        self,
        test_case_id: Optional[str] = None,
    ):
        """
        Initialize a new ImportMeasurement measurement.

        :param test_case_id: A unique identifier for the test case associated to this.
        """
        self.output_evidence_type: type = Opaque
        """The output Evidence type that calls to evaluate will return."""

        self.function: Optional[Callable[..., Any]] = _load_json
        """Store the callable function itself."""

        # Call base constructor.
        super().__init__(test_case_id=test_case_id, function=self.function)

    # Overriden.
    def __call__(self, import_path: str) -> Evidence:
        """Evaluate a measurement and return values without semantics."""
        return super().__call__(import_path)

function = _load_json instance-attribute

Store the callable function itself.

output_evidence_type = Opaque instance-attribute

The output Evidence type that calls to evaluate will return.

__call__(import_path)

Evaluate a measurement and return values without semantics.

Source code in mlte/measurement/import_measurement.py
34
35
36
def __call__(self, import_path: str) -> Evidence:
    """Evaluate a measurement and return values without semantics."""
    return super().__call__(import_path)

__init__(test_case_id=None)

Initialize a new ImportMeasurement measurement.

Parameters:

Name Type Description Default
test_case_id Optional[str]

A unique identifier for the test case associated to this.

None
Source code in mlte/measurement/import_measurement.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def __init__(
    self,
    test_case_id: Optional[str] = None,
):
    """
    Initialize a new ImportMeasurement measurement.

    :param test_case_id: A unique identifier for the test case associated to this.
    """
    self.output_evidence_type: type = Opaque
    """The output Evidence type that calls to evaluate will return."""

    self.function: Optional[Callable[..., Any]] = _load_json
    """Store the callable function itself."""

    # Call base constructor.
    super().__init__(test_case_id=test_case_id, function=self.function)