# Path: crosscompute/exceptions.py
# class CrossComputeExecutionError(CrossComputeError):
#     pass


import json
from collections import defaultdict
from pytest import raises
from crosscompute.exceptions import (
    CrossComputeExecutionError)
from crosscompute.routines import (
    load_image_png,
    load_map_geojson,
    load_markdown_md,
    load_number_json,
    load_table_csv,
    load_text_json,
    load_text_txt,
    load_value_json,
    render_object,
    save_image_png,
    save_map_geojson,
    save_markdown_md,
    save_number_json,
    save_table_csv,
    save_text_json,
    save_text_txt)
    with raises(CrossComputeExecutionError):
        save_table_csv(target_path, {}, variable_id, value_by_id_by_path)
    with raises(CrossComputeExecutionError):
        save_table_csv(target_path, {
            'columns': 1, 'rows': 1}, variable_id, value_by_id_by_path)
    save_table_csv(target_path, value, variable_id, value_by_id_by_path)
    assert load_table_csv(target_path, variable_id) == value


def test_save_map_geojson(tmpdir):
    target_path = tmpdir.join('map.geojson').strpath
    value = {
        'type': 'FeatureCollection',
        'features': [{
            'type': 'Feature',
            'properties': {
                'population': 200,
            },
            'geometry': {
                'type': 'Point',
                'coordinates': [-112.0372, 46.608058],
            },
        }],
    }
    variable_id = 'a'
    value_by_id_by_path = defaultdict(dict)
    save_map_geojson(target_path, value, variable_id, value_by_id_by_path)
    assert load_map_geojson(target_path, variable_id) == value



# Path: crosscompute/exceptions.py
# class CrossComputeExecutionError(CrossComputeError):
#     pass


# Path: experiments/0.8/tests/test_routines_serialization.py
import json
from collections import defaultdict
from pytest import raises
from crosscompute.exceptions import (
    CrossComputeExecutionError)
from crosscompute.routines import (
    load_image_png,
    load_map_geojson,
    load_markdown_md,
    load_number_json,
    load_table_csv,
    load_text_json,
    load_text_txt,
    load_value_json,
    render_object,
    save_image_png,
    save_map_geojson,
    save_markdown_md,
    save_number_json,
    save_table_csv,
    save_text_json,
    save_text_txt)

    with raises(CrossComputeExecutionError):
        save_table_csv(target_path, {}, variable_id, value_by_id_by_path)
    with raises(CrossComputeExecutionError):
        save_table_csv(target_path, {
            'columns': 1, 'rows': 1}, variable_id, value_by_id_by_path)
    save_table_csv(target_path, value, variable_id, value_by_id_by_path)
    assert load_table_csv(target_path, variable_id) == value


def test_save_map_geojson(tmpdir):
    target_path = tmpdir.join('map.geojson').strpath
    value = {
        'type': 'FeatureCollection',
        'features': [{
            'type': 'Feature',
            'properties': {
                'population': 200,
            },
            'geometry': {
                'type': 'Point',
                'coordinates': [-112.0372, 46.608058],
            },
        }],
    }
    variable_id = 'a'
    value_by_id_by_path = defaultdict(dict)
    save_map_geojson(target_path, value, variable_id, value_by_id_by_path)
    assert load_map_geojson(target_path, variable_id) == value



def test_load_value_json(tmpdir):