# Path: gridded/grids.py
# class Grid_U(GridBase, UGrid):
# 
#     @classmethod
#     def _find_required_grid_attrs(cls, filename, dataset=None, grid_topology=None):
# 
#         gf_vars = dataset.variables if dataset is not None else get_dataset(filename).variables
#         gf_vars = dict([(k.lower(), v) for k, v in gf_vars.items()])
#         # Get superset attributes
#         init_args, gt = super(Grid_U, cls)._find_required_grid_attrs(filename=filename,
#                                                                      dataset=dataset,
#                                                                      grid_topology=grid_topology)
# 
#         face_attrs = ['faces']
#         face_var_names = ['faces', 'tris', 'nv', 'ele']
#         if grid_topology is None:
#             for n in face_var_names:
#                 if n in gf_vars:
#                     init_args[face_attrs[0]] = gf_vars[n][:]
#                     gt[face_attrs[0]] = n
#                     break
#             if face_attrs[0] not in init_args:
#                 raise ValueError('Unable to find face connectivity array.')
# 
#         else:
#             for n, v in grid_topology.items():
#                 if n in face_attrs:
#                     init_args[n] = gf_vars[v][:]
#                     break
#         if init_args['faces'].shape[0] == 3:
#             init_args['faces'] = np.ascontiguousarray(np.array(init_args['faces']).T - 1)
# 
#         return init_args, gt
# 
#     @classmethod
#     def gen_from_quads(cls, nodes):
#         if not len(nodes.shape) == 3:
#             raise ValueError('Nodes of a quad grid must be 2 dimensional')
#         lin_nodes = None
#         if isinstance(nodes, np.ma.MaskedArray):
#             lin_nodes = nodes.reshape(-1, 2)[nodes]
# 
# Path: gridded/pyugrid/ugrid.py
# IND_DT = np.int32
# 
# NODE_DT = np.float64  # datatype used for node coordinates.


import numpy as np
import pytest
from gridded.grids import Grid_U as UGrid
from gridded.pyugrid.ugrid import IND_DT, NODE_DT

faces = [(0, 1, 2),
         (1, 3, 2)]

edges = [(0, 1),
         (1, 3),
         (3, 2),
         (2, 0),
         (1, 2)]

boundaries = [(0, 1),
              (0, 2),
              (1, 3),
              (2, 3)]


def test_full_set():
    grid = UGrid(nodes=nodes,
                 faces=faces,
                 edges=edges,
                 boundaries=boundaries,
                 )

    # Check the dtype of key objects.
    # Implicitly makes sure they are numpy arrays (or array-like).
    assert grid.num_vertices == 3

    assert grid.nodes.dtype == NODE_DT
    assert grid.faces.dtype == IND_DT
    assert grid.edges.dtype == IND_DT

# Path: gridded/grids.py
# class Grid_U(GridBase, UGrid):
# 
#     @classmethod
#     def _find_required_grid_attrs(cls, filename, dataset=None, grid_topology=None):
# 
#         gf_vars = dataset.variables if dataset is not None else get_dataset(filename).variables
#         gf_vars = dict([(k.lower(), v) for k, v in gf_vars.items()])
#         # Get superset attributes
#         init_args, gt = super(Grid_U, cls)._find_required_grid_attrs(filename=filename,
#                                                                      dataset=dataset,
#                                                                      grid_topology=grid_topology)
# 
#         face_attrs = ['faces']
#         face_var_names = ['faces', 'tris', 'nv', 'ele']
#         if grid_topology is None:
#             for n in face_var_names:
#                 if n in gf_vars:
#                     init_args[face_attrs[0]] = gf_vars[n][:]
#                     gt[face_attrs[0]] = n
#                     break
#             if face_attrs[0] not in init_args:
#                 raise ValueError('Unable to find face connectivity array.')
# 
#         else:
#             for n, v in grid_topology.items():
#                 if n in face_attrs:
#                     init_args[n] = gf_vars[v][:]
#                     break
#         if init_args['faces'].shape[0] == 3:
#             init_args['faces'] = np.ascontiguousarray(np.array(init_args['faces']).T - 1)
# 
#         return init_args, gt
# 
#     @classmethod
#     def gen_from_quads(cls, nodes):
#         if not len(nodes.shape) == 3:
#             raise ValueError('Nodes of a quad grid must be 2 dimensional')
#         lin_nodes = None
#         if isinstance(nodes, np.ma.MaskedArray):
#             lin_nodes = nodes.reshape(-1, 2)[nodes]
# 
# Path: gridded/pyugrid/ugrid.py
# IND_DT = np.int32
# 
# NODE_DT = np.float64  # datatype used for node coordinates.


# Path: gridded/tests/test_ugrid/test_ugrid.py
import numpy as np
import pytest
from gridded.grids import Grid_U as UGrid
from gridded.pyugrid.ugrid import IND_DT, NODE_DT


faces = [(0, 1, 2),
         (1, 3, 2)]

edges = [(0, 1),
         (1, 3),
         (3, 2),
         (2, 0),
         (1, 2)]

boundaries = [(0, 1),
              (0, 2),
              (1, 3),
              (2, 3)]


def test_full_set():
    grid = UGrid(nodes=nodes,
                 faces=faces,
                 edges=edges,
                 boundaries=boundaries,
                 )

    # Check the dtype of key objects.
    # Implicitly makes sure they are numpy arrays (or array-like).
    assert grid.num_vertices == 3

    assert grid.nodes.dtype == NODE_DT
    assert grid.faces.dtype == IND_DT
    assert grid.edges.dtype == IND_DT

    assert grid.boundaries.dtype == IND_DT