# Path: gridded/tests/test_ugrid/utilities.py
# @contextlib.contextmanager
# def chdir(dirname=None):
#     curdir = os.getcwd()
#     try:
#         if dirname is not None:
#             os.chdir(dirname)
#         yield
#     finally:
#         os.chdir(curdir)
# 
# Path: gridded/pyugrid/ugrid.py
# IND_DT = np.int32
# NODE_DT = np.float64  # datatype used for node coordinates.
# class UGrid(object):
#     def __init__(self,
#                  nodes=None,
#                  node_lon=None,
#                  node_lat=None,
#                  faces=None,
#                  edges=None,
#                  boundaries=None,
#                  face_face_connectivity=None,
#                  face_edge_connectivity=None,
#                  edge_coordinates=None,
#                  face_coordinates=None,
#                  boundary_coordinates=None,
#                  data=None,
#                  mesh_name="mesh",
#                  ):
#     def from_ncfile(klass, nc_url, mesh_name=None):  # , load_data=False):
#     def from_nc_dataset(klass, nc, mesh_name=None):  # , load_data=False):
#     def info(self):
#     def check_consistent(self):
#     def num_vertices(self):
#     def nodes(self):
#     def node_lon(self):
#     def node_lat(self):
#     def nodes(self, nodes_coords):
#     def nodes(self):
#     def faces(self):
#     def faces(self, faces_indexes):
#     def faces(self):
#     def edges(self):
#     def edges(self, edges_indexes):
#     def edges(self):
#     def boundaries(self):
#     def boundaries(self, boundaries_indexes):
#     def boundaries(self):
#     def face_face_connectivity(self):
#     def face_face_connectivity(self, face_face_connectivity):
#     def face_face_connectivity(self):
#     def face_edge_connectivity(self):
#     def face_edge_connectivity(self, face_edge_connectivity):
#     def face_edge_connectivity(self):
#     def infer_location(self, data):
#     def locate_nodes(self, points):
#     def _build_kdtree(self):
#     def _hash_of_pts(self, points):
#     def _add_memo(self, points, item, D, _copy=False, _hash=None):
#     def _get_memoed(self, points, D, _copy=False, _hash=None):
#     def locate_faces(self, points, method='celltree', _copy=False, _memo=True, _hash=None):
#     def build_celltree(self):
#     def interpolation_alphas(self, points, indices=None, _copy=False, _memo=True, _hash=None):
#     def interpolate_var_to_points(self,
#                                   points,
#                                   variable,
#                                   location=None,
#                                   fill_value=0,
#                                   indices=None,
#                                   alphas=None,
#                                   slices=None,
#                                   _copy=False,
#                                   _memo=True,
#                                   _hash=None):
#     def build_face_face_connectivity(self):
#     def get_lines(self):
#     def build_edges(self):
#     def build_boundaries(self):
#     def build_face_edge_connectivity(self):
#     def build_face_coordinates(self):
#     def build_edge_coordinates(self):
#     def build_boundary_coordinates(self):
#     def save_as_netcdf(self, filename, format='netcdf4'):
#     def save(self, filepath, format='netcdf4', variables={}):
#     def _save_variables(self, nclocal, variables):
# 
# Path: gridded/pyugrid/read_netcdf.py
# def find_mesh_names(nc):
# def is_valid_mesh(nc, varname):
# def load_grid_from_nc_dataset(nc, grid, mesh_name=None):  # , load_data=True):
# def load_grid_from_ncfilename(filename, grid, mesh_name=None):  # , load_data=True):


import os
import pytest
import numpy as np
import netCDF4
from .utilities import chdir
from gridded.pyugrid import ugrid
from gridded.pyugrid import read_netcdf

def test_read_face_coordinates():
    """Do we get the right face_coordinates array?"""

    with chdir(files):
        grid = UGrid.from_ncfile('ElevenPoints_UGRIDv0.9.nc')
    assert grid.face_coordinates.shape == (13, 2)

    # Not ideal to pull specific values out, but how else to test?
    assert np.array_equal(grid.face_coordinates[0],
                          (-37.1904106666667, 30.57093))
    assert np.array_equal(grid.face_coordinates[-1],
                          (-38.684412, 27.7132626666667))


def test_read_none_edge_coordinates():
    """Do we get the right edge_coordinates array?"""
    with chdir(files):
        grid = UGrid.from_ncfile('ElevenPoints_UGRIDv0.9.nc')
    assert grid.edge_coordinates is None


def test_read_none_boundary_coordinates():
    """Do we get the right boundary_coordinates array?"""
    with chdir(files):
        grid = UGrid.from_ncfile('ElevenPoints_UGRIDv0.9.nc')
    assert grid.boundary_coordinates is None


def test_read_longitude_no_standard_name():

# Path: gridded/tests/test_ugrid/utilities.py
# @contextlib.contextmanager
# def chdir(dirname=None):
#     curdir = os.getcwd()
#     try:
#         if dirname is not None:
#             os.chdir(dirname)
#         yield
#     finally:
#         os.chdir(curdir)
# 
# Path: gridded/pyugrid/ugrid.py
# IND_DT = np.int32
# NODE_DT = np.float64  # datatype used for node coordinates.
# class UGrid(object):
#     def __init__(self,
#                  nodes=None,
#                  node_lon=None,
#                  node_lat=None,
#                  faces=None,
#                  edges=None,
#                  boundaries=None,
#                  face_face_connectivity=None,
#                  face_edge_connectivity=None,
#                  edge_coordinates=None,
#                  face_coordinates=None,
#                  boundary_coordinates=None,
#                  data=None,
#                  mesh_name="mesh",
#                  ):
#     def from_ncfile(klass, nc_url, mesh_name=None):  # , load_data=False):
#     def from_nc_dataset(klass, nc, mesh_name=None):  # , load_data=False):
#     def info(self):
#     def check_consistent(self):
#     def num_vertices(self):
#     def nodes(self):
#     def node_lon(self):
#     def node_lat(self):
#     def nodes(self, nodes_coords):
#     def nodes(self):
#     def faces(self):
#     def faces(self, faces_indexes):
#     def faces(self):
#     def edges(self):
#     def edges(self, edges_indexes):
#     def edges(self):
#     def boundaries(self):
#     def boundaries(self, boundaries_indexes):
#     def boundaries(self):
#     def face_face_connectivity(self):
#     def face_face_connectivity(self, face_face_connectivity):
#     def face_face_connectivity(self):
#     def face_edge_connectivity(self):
#     def face_edge_connectivity(self, face_edge_connectivity):
#     def face_edge_connectivity(self):
#     def infer_location(self, data):
#     def locate_nodes(self, points):
#     def _build_kdtree(self):
#     def _hash_of_pts(self, points):
#     def _add_memo(self, points, item, D, _copy=False, _hash=None):
#     def _get_memoed(self, points, D, _copy=False, _hash=None):
#     def locate_faces(self, points, method='celltree', _copy=False, _memo=True, _hash=None):
#     def build_celltree(self):
#     def interpolation_alphas(self, points, indices=None, _copy=False, _memo=True, _hash=None):
#     def interpolate_var_to_points(self,
#                                   points,
#                                   variable,
#                                   location=None,
#                                   fill_value=0,
#                                   indices=None,
#                                   alphas=None,
#                                   slices=None,
#                                   _copy=False,
#                                   _memo=True,
#                                   _hash=None):
#     def build_face_face_connectivity(self):
#     def get_lines(self):
#     def build_edges(self):
#     def build_boundaries(self):
#     def build_face_edge_connectivity(self):
#     def build_face_coordinates(self):
#     def build_edge_coordinates(self):
#     def build_boundary_coordinates(self):
#     def save_as_netcdf(self, filename, format='netcdf4'):
#     def save(self, filepath, format='netcdf4', variables={}):
#     def _save_variables(self, nclocal, variables):
# 
# Path: gridded/pyugrid/read_netcdf.py
# def find_mesh_names(nc):
# def is_valid_mesh(nc, varname):
# def load_grid_from_nc_dataset(nc, grid, mesh_name=None):  # , load_data=True):
# def load_grid_from_ncfilename(filename, grid, mesh_name=None):  # , load_data=True):


# Path: gridded/tests/test_ugrid/test_read.py
import os
import pytest
import numpy as np
import netCDF4
from .utilities import chdir
from gridded.pyugrid import ugrid
from gridded.pyugrid import read_netcdf


def test_read_face_coordinates():
    """Do we get the right face_coordinates array?"""

    with chdir(files):
        grid = UGrid.from_ncfile('ElevenPoints_UGRIDv0.9.nc')
    assert grid.face_coordinates.shape == (13, 2)

    # Not ideal to pull specific values out, but how else to test?
    assert np.array_equal(grid.face_coordinates[0],
                          (-37.1904106666667, 30.57093))
    assert np.array_equal(grid.face_coordinates[-1],
                          (-38.684412, 27.7132626666667))


def test_read_none_edge_coordinates():
    """Do we get the right edge_coordinates array?"""
    with chdir(files):
        grid = UGrid.from_ncfile('ElevenPoints_UGRIDv0.9.nc')
    assert grid.edge_coordinates is None


def test_read_none_boundary_coordinates():
    """Do we get the right boundary_coordinates array?"""
    with chdir(files):
        grid = UGrid.from_ncfile('ElevenPoints_UGRIDv0.9.nc')
    assert grid.boundary_coordinates is None


def test_read_longitude_no_standard_name():

    with chdir(files):