コード例 #1
0
def test_write_raster(tmpdir):
    grid = RasterModelGrid((3, 3), xy_spacing=2.0)
    z = grid.add_zeros("topographic__elevation", at="node")
    z[4] = 1.0

    with tmpdir.as_cwd():
        write_obj("test_quad.obj", grid)
        with open("test_quad.obj", "r") as fp:
            assert fp.read() == LITTLE_RAST_OBJ
コード例 #2
0
def test_field_name(tmpdir):
    grid = RasterModelGrid((3, 3), xy_spacing=2.0)
    z = grid.add_zeros("z", at="node")
    z[4] = 1.0

    with tmpdir.as_cwd():
        write_obj("test_quad.obj", grid, field_for_z="z")
        with open("test_quad.obj", "r") as fp:
            assert fp.read() == LITTLE_RAST_OBJ
コード例 #3
0
def test_clobber(tmpdir):
    grid = RasterModelGrid((3, 3), xy_spacing=2.0)
    z = grid.add_zeros("topographic__elevation", at="node")
    z[4] = 1.0

    with tmpdir.as_cwd():
        with open("test_quad.obj", "w") as fp:
            pass

        with pytest.raises(ValueError):
            write_obj("test_quad.obj", grid)

        write_obj("test_quad.obj", grid, clobber=True)
        with open("test_quad.obj", "r") as fp:
            assert fp.read() == LITTLE_RAST_OBJ
コード例 #4
0
def test_write_hex_to_path(tmpdir, fname):
    grid = HexModelGrid((3, 2), spacing=2.0)
    z = grid.add_zeros("topographic__elevation", at="node")
    z[3] = 1.0

    with tmpdir.as_cwd():
        actual = write_obj(fname, grid)
        assert actual == fname
        with open(fname, "r") as fp:
            assert fp.read() == LITTLE_HEX_OBJ