# Path: gridded/pysgrid/read_netcdf.py
# def parse_axes(axes_attr):
#     p = re.compile('([a-zA-Z]: [a-zA-Z_]+)')
#     matches = p.findall(axes_attr)
#     x_axis = None
#     y_axis = None
#     z_axis = None
#     for match in matches:
#         axis_split = match.split(':')
#         axis_name = axis_split[0].strip()
#         axis_coordinate = axis_split[1].strip()
#         if axis_name.lower() == 'x':
#             x_axis = axis_coordinate
#         elif axis_name.lower() == 'y':
#             y_axis = axis_coordinate
#         elif axis_name.lower() == 'z':
#             z_axis = axis_coordinate
#     return x_axis, y_axis, z_axis
# 
# def parse_padding(padding_str, mesh_topology_var):
#     """
#     Use regex expressions to break apart an
#     attribute string containing padding types
#     for each variable with a cf_role of
#     'grid_topology'.
# 
#     Padding information is returned within a named tuple
#     for each node dimension of an edge, face, or vertical
#     dimension. The named tuples have the following attributes:
#     mesh_topology_var, dim_name, dim_var, and padding.
#     Padding information is returned as a list
#     of these named tuples.
# 
#     :param str padding_str: string containing padding types from
#                             a netCDF attribute.
#     :return: named tuples with padding information.
#     :rtype: list.
# 
#     """
#     p = re.compile('([a-zA-Z0-9_]+:) ([a-zA-Z0-9_]+) (\(padding: [a-zA-Z]+\))')
#     padding_matches = p.findall(padding_str)
#     padding_type_list = []
#     for padding_match in padding_matches:
#         raw_dim, raw_sub_dim, raw_padding_var = padding_match
#         dim = raw_dim.split(':')[0]
#         sub_dim = raw_sub_dim
#         # Remove parentheses. (That is why regular expressions are bad!
#         # You need a commend to explain what is going on!!)
#         cleaned_padding_var = re.sub('[\(\)]', '', raw_padding_var)
#         # Get the padding value and remove spaces.
#         padding_type = cleaned_padding_var.split(':')[1].strip()
#         grid_padding = GridPadding(mesh_topology_var=mesh_topology_var,
#                                    face_dim=dim,
#                                    node_dim=sub_dim,
#                                    padding=padding_type
#                                    )
#         padding_type_list.append(grid_padding)
#     if len(padding_type_list) > 0:
#         final_padding_types = padding_type_list
#     else:
#         final_padding_types = None
#         msg = ('The netCDF file appears to have conform to SGRID conventions, '
#                'but padding values cannot be found.')
#         raise ValueError(msg)
#     return final_padding_types
# 
# def parse_vector_axis(variable_standard_name):
#     p = re.compile('[a-z_]+_[xyz]_[a-z_]+')
#     match = p.match(variable_standard_name)
#     if match is not None:
#         direction_pattern = re.compile('_[xyz]_')
#         direction_substr = direction_pattern.search(match.string).group()
#         vector_direction = direction_substr.replace('_', '').upper()
#     else:
#         vector_direction = None
#     return vector_direction


import pytest
from gridded.pysgrid.read_netcdf import (parse_axes, parse_padding, parse_vector_axis)
    expected_sub_dim = 'xi_psi'
    expected_dim = 'xi_v'
    assert len(result) == expected_len
    assert padding_type == expected_padding_type
    assert sub_dim == expected_sub_dim
    assert dim == expected_dim


def test_no_padding(parse_pad):
    grid_topology, pad_1, pad_2, pad_no = parse_pad
    with pytest.raises(ValueError):
        parse_padding(padding_str=pad_no,
                      mesh_topology_var=grid_topology)


def test_std_name_with_velocity_direction():
    standard_name_1 = 'sea_water_y_velocity'
    direction = parse_vector_axis(standard_name_1)
    expected_direction = 'Y'
    assert direction == expected_direction


def test_std_name_without_direction():
    standard_name_2 = 'atmosphere_optical_thickness_due_to_cloud'
    direction = parse_vector_axis(standard_name_2)
    assert direction is None


def test_std_name_with_transport_direction():
    standard_name_3 = 'ocean_heat_x_transport_due_to_diffusion'

# Path: gridded/pysgrid/read_netcdf.py
# def parse_axes(axes_attr):
#     p = re.compile('([a-zA-Z]: [a-zA-Z_]+)')
#     matches = p.findall(axes_attr)
#     x_axis = None
#     y_axis = None
#     z_axis = None
#     for match in matches:
#         axis_split = match.split(':')
#         axis_name = axis_split[0].strip()
#         axis_coordinate = axis_split[1].strip()
#         if axis_name.lower() == 'x':
#             x_axis = axis_coordinate
#         elif axis_name.lower() == 'y':
#             y_axis = axis_coordinate
#         elif axis_name.lower() == 'z':
#             z_axis = axis_coordinate
#     return x_axis, y_axis, z_axis
# 
# def parse_padding(padding_str, mesh_topology_var):
#     """
#     Use regex expressions to break apart an
#     attribute string containing padding types
#     for each variable with a cf_role of
#     'grid_topology'.
# 
#     Padding information is returned within a named tuple
#     for each node dimension of an edge, face, or vertical
#     dimension. The named tuples have the following attributes:
#     mesh_topology_var, dim_name, dim_var, and padding.
#     Padding information is returned as a list
#     of these named tuples.
# 
#     :param str padding_str: string containing padding types from
#                             a netCDF attribute.
#     :return: named tuples with padding information.
#     :rtype: list.
# 
#     """
#     p = re.compile('([a-zA-Z0-9_]+:) ([a-zA-Z0-9_]+) (\(padding: [a-zA-Z]+\))')
#     padding_matches = p.findall(padding_str)
#     padding_type_list = []
#     for padding_match in padding_matches:
#         raw_dim, raw_sub_dim, raw_padding_var = padding_match
#         dim = raw_dim.split(':')[0]
#         sub_dim = raw_sub_dim
#         # Remove parentheses. (That is why regular expressions are bad!
#         # You need a commend to explain what is going on!!)
#         cleaned_padding_var = re.sub('[\(\)]', '', raw_padding_var)
#         # Get the padding value and remove spaces.
#         padding_type = cleaned_padding_var.split(':')[1].strip()
#         grid_padding = GridPadding(mesh_topology_var=mesh_topology_var,
#                                    face_dim=dim,
#                                    node_dim=sub_dim,
#                                    padding=padding_type
#                                    )
#         padding_type_list.append(grid_padding)
#     if len(padding_type_list) > 0:
#         final_padding_types = padding_type_list
#     else:
#         final_padding_types = None
#         msg = ('The netCDF file appears to have conform to SGRID conventions, '
#                'but padding values cannot be found.')
#         raise ValueError(msg)
#     return final_padding_types
# 
# def parse_vector_axis(variable_standard_name):
#     p = re.compile('[a-z_]+_[xyz]_[a-z_]+')
#     match = p.match(variable_standard_name)
#     if match is not None:
#         direction_pattern = re.compile('_[xyz]_')
#         direction_substr = direction_pattern.search(match.string).group()
#         vector_direction = direction_substr.replace('_', '').upper()
#     else:
#         vector_direction = None
#     return vector_direction


# Path: gridded/tests/test_pysgrid/test_sgrid_parsing.py
import pytest
from gridded.pysgrid.read_netcdf import (parse_axes, parse_padding, parse_vector_axis)

    expected_sub_dim = 'xi_psi'
    expected_dim = 'xi_v'
    assert len(result) == expected_len
    assert padding_type == expected_padding_type
    assert sub_dim == expected_sub_dim
    assert dim == expected_dim


def test_no_padding(parse_pad):
    grid_topology, pad_1, pad_2, pad_no = parse_pad
    with pytest.raises(ValueError):
        parse_padding(padding_str=pad_no,
                      mesh_topology_var=grid_topology)


def test_std_name_with_velocity_direction():
    standard_name_1 = 'sea_water_y_velocity'
    direction = parse_vector_axis(standard_name_1)
    expected_direction = 'Y'
    assert direction == expected_direction


def test_std_name_without_direction():
    standard_name_2 = 'atmosphere_optical_thickness_due_to_cloud'
    direction = parse_vector_axis(standard_name_2)
    assert direction is None


def test_std_name_with_transport_direction():
    standard_name_3 = 'ocean_heat_x_transport_due_to_diffusion'

    direction = parse_vector_axis(standard_name_3)