Esempio n. 1
0
def test_intersections_from_intersection_find_metadata():
    with tempfile.TemporaryDirectory() as dirpath:
        shutil.copy(inter_res, dirpath)
        new_fp = os.path.join(dirpath, "intersection_result.geojson")

        shutil.copy(inter_res_md, dirpath)

        fp1, _ = intersections_from_intersection(new_fp, dirpath=dirpath)
        data = json_importer(fp1)
        result = [
            # Order from geojson file
            [0, 'grid cell 3', 3097248058.207057],
            [1, 'grid cell 2', 3097719886.041353],
            [2, 'grid cell 0', 3097719886.0413523],
            [3, 'grid cell 1', 3097248058.207055],
        ]
        assert data['data'] == result

    with tempfile.TemporaryDirectory() as dirpath:
        shutil.copy(inter_res, dirpath)
        new_fp = os.path.join(dirpath, "intersection_result.geojson")

        shutil.copy(inter_res_decompressed,
                    os.path.join(dirpath, 'intersection_result.json'))

        fp1, _ = intersections_from_intersection(new_fp, dirpath=dirpath)
        data = json_importer(fp1)
        result = [
            # Order from geojson file
            [0, 'grid cell 3', 3097248058.207057],
            [1, 'grid cell 2', 3097719886.041353],
            [2, 'grid cell 0', 3097719886.0413523],
            [3, 'grid cell 1', 3097248058.207055],
        ]
        assert data['data'] == result
Esempio n. 2
0
def test_intersections_from_intersection():
    with tempfile.TemporaryDirectory() as dirpath:
        fp1, fp2 = intersections_from_intersection(inter_res, dirpath=dirpath)
        data = json_importer(fp1)
        result = [
            # Order from geojson file
            [0, 'grid cell 3', 3097248058.207057],
            [1, 'grid cell 2', 3097719886.041353],
            [2, 'grid cell 0', 3097719886.0413523],
            [3, 'grid cell 1', 3097248058.207055],
        ]
        assert data['data'] == result
        assert data['metadata'].keys() == {'first', 'second', 'when'}
        assert data['metadata']['first'].keys() == {
            'field', 'filename', 'path', 'sha256'
        }
        assert data['metadata']['second'].keys() == {
            'field', 'filename', 'path', 'sha256'
        }

        data = json_importer(fp2)
        result = [
            [0, 'single', 3097248058.207057],
            [1, 'single', 3097719886.041353],
            [2, 'single', 3097719886.0413523],
            [3, 'single', 3097248058.207055],
        ]
        assert data['data'] == result
        assert data['metadata'].keys() == {'first', 'second', 'when'}
        assert data['metadata']['first'].keys() == {
            'field', 'filename', 'path', 'sha256'
        }
        assert data['metadata']['second'].keys() == {
            'field', 'filename', 'path', 'sha256'
        }
Esempio n. 3
0
def test_json_roundtrip():
    data = {'d': [1, 2, 3], 'e': {'foo': 'bar'}}

    with tempfile.TemporaryDirectory() as dirpath:
        new_fp = os.path.join(dirpath, 'testfile')

        fp = json_exporter(data, new_fp, False)
        assert json_importer(fp) == data

        fp = json_exporter(data, new_fp)
        assert json_importer(fp) == data
Esempio n. 4
0
def test_json_importing():
    fp = os.path.join(dirpath, "json_test.json")
    assert json_importer(fp) == {'d': [1, 2, 3], 'e': {'foo': 'bar'}}

    fp = os.path.join(dirpath, "json_test.json.bz2")
    assert json_importer(fp) == {'d': [1, 2, 3], 'e': {'foo': 'bar'}}