示例#1
0
def test_present_set():
    # GIVEN

    # WHEN formatting None
    presentable_string = Presenter().process_set(None)

    # THEN we should get 'N/A' back
    assert presentable_string == Presenter().DEFAULT_NA
示例#2
0
def test_present_dict():
    # GIVEN a dict to present
    dict_to_present = {
        "nested_dict": {"string_key": "string_value", "none_key": None, "empty_key": ""}
    }

    # WHEN formatting dict
    presentable_dict = Presenter().process_dict(dict_to_present)

    # THEN we should get 'N/A' back
    assert presentable_dict["nested_dict"]["string_key"] == "string_value"
    assert presentable_dict["nested_dict"]["none_key"] == Presenter().DEFAULT_NA
    assert presentable_dict["nested_dict"]["empty_key"] == Presenter().DEFAULT_NA
示例#3
0
    def _make_data_presentable(delivery_data: dict) -> dict:
        """Replace db values with what a human might expect"""

        presenter = Presenter(precision=2)

        _presentable_dict = presenter.process_dict(delivery_data)

        for sample in delivery_data["samples"]:
            sample["mapped_reads"] = presenter.process_float_string(sample["mapped_reads"], 2)
            sample["target_coverage"] = presenter.process_float_string(sample["target_coverage"], 1)
            sample["target_completeness"] = presenter.process_float_string(
                sample["target_completeness"], 2
            )
            sample["duplicates"] = presenter.process_float_string(sample["duplicates"], 1)

        return _presentable_dict