Example #1
0
def _handle_hook_results(hook_results, filepath):
    plug.log.warning(
        "Storing hook results to file is an alpha feature, the file format "
        "is not final")
    output_file = pathlib.Path(filepath)
    util.atomic_write(plug.result_mapping_to_json(hook_results), output_file)
    plug.echo("Hook results stored to {}".format(filepath))
Example #2
0
def test_lossless_serialization(hook_result_mapping):
    """Test that serializing and then deserializing results in all data being
    recovered.
    """
    expected = dict(hook_result_mapping)

    serialized = plug.result_mapping_to_json(hook_result_mapping)
    deserialized = plug.json_to_result_mapping(serialized)
    actual = {
        repo_name: sorted(results)
        for repo_name, results in deserialized.items()
    }

    assert actual == expected
Example #3
0
    def test_writes_hook_results_correctly(
        self,
        tmpdir,
        hook_result_mapping,
        dummyapi_instance,
        action,
        command_func,
    ):
        expected_filepath = pathlib.Path(".").resolve() / "results.json"
        expected_json = plug.result_mapping_to_json(hook_result_mapping)
        args_dict = dict(VALID_PARSED_ARGS)
        args_dict["hook_results_file"] = str(expected_filepath)
        with mock.patch(
            "_repobee.fileutil.atomic_write", autospec=True
        ) as write, mock.patch(
            command_func, autospec=True, return_value=hook_result_mapping
        ):
            args = argparse.Namespace(**action.asdict(), **args_dict)
            _repobee.cli.dispatch.dispatch_command(
                args, dummyapi_instance, EMPTY_PATH
            )

        write.assert_called_once_with(expected_json, expected_filepath)
Example #4
0
def testplug_empty_mapping():
    assert plug.result_mapping_to_json({}) == "{}"