# Path: lib/cartopy/tests/crs/helpers.py
# def check_proj_params(name, crs, other_args):
#     expected = other_args | {f'proj={name}', 'no_defs'}
#     proj_params = set(crs.proj4_init.lstrip('+').split(' +'))
#     assert expected == proj_params


import numpy as np
import pytest
import cartopy.crs as ccrs
from numpy.testing import assert_almost_equal
from .helpers import check_proj_params

def test_default():
    gnom = ccrs.Gnomonic()
    other_args = {'a=6378137.0', 'lon_0=0.0', 'lat_0=0.0'}
    check_proj_params('gnom', gnom, other_args)

    assert_almost_equal(np.array(gnom.x_limits),
                        [-5e7, 5e7])
    assert_almost_equal(np.array(gnom.y_limits),
                        [-5e7, 5e7])


def test_sphere_globe():
    globe = ccrs.Globe(semimajor_axis=1000, ellipse=None)
    gnom = ccrs.Gnomonic(globe=globe)
    other_args = {'a=1000', 'lon_0=0.0', 'lat_0=0.0'}
    check_proj_params('gnom', gnom, other_args)

    assert_almost_equal(gnom.x_limits, [-5e7, 5e7])
    assert_almost_equal(gnom.y_limits, [-5e7, 5e7])


def test_ellipse_globe():
    globe = ccrs.Globe(ellipse='WGS84')
    with pytest.warns(UserWarning,
                      match='does not handle elliptical globes.') as w:
        gnom = ccrs.Gnomonic(globe=globe)
        assert len(w) == 1

    other_args = {'ellps=WGS84', 'lon_0=0.0', 'lat_0=0.0'}

# Path: lib/cartopy/tests/crs/helpers.py
# def check_proj_params(name, crs, other_args):
#     expected = other_args | {f'proj={name}', 'no_defs'}
#     proj_params = set(crs.proj4_init.lstrip('+').split(' +'))
#     assert expected == proj_params


# Path: lib/cartopy/tests/crs/test_gnomonic.py
import numpy as np
import pytest
import cartopy.crs as ccrs
from numpy.testing import assert_almost_equal
from .helpers import check_proj_params


def test_default():
    gnom = ccrs.Gnomonic()
    other_args = {'a=6378137.0', 'lon_0=0.0', 'lat_0=0.0'}
    check_proj_params('gnom', gnom, other_args)

    assert_almost_equal(np.array(gnom.x_limits),
                        [-5e7, 5e7])
    assert_almost_equal(np.array(gnom.y_limits),
                        [-5e7, 5e7])


def test_sphere_globe():
    globe = ccrs.Globe(semimajor_axis=1000, ellipse=None)
    gnom = ccrs.Gnomonic(globe=globe)
    other_args = {'a=1000', 'lon_0=0.0', 'lat_0=0.0'}
    check_proj_params('gnom', gnom, other_args)

    assert_almost_equal(gnom.x_limits, [-5e7, 5e7])
    assert_almost_equal(gnom.y_limits, [-5e7, 5e7])


def test_ellipse_globe():
    globe = ccrs.Globe(ellipse='WGS84')
    with pytest.warns(UserWarning,
                      match='does not handle elliptical globes.') as w:
        gnom = ccrs.Gnomonic(globe=globe)
        assert len(w) == 1

    other_args = {'ellps=WGS84', 'lon_0=0.0', 'lat_0=0.0'}

    check_proj_params('gnom', gnom, other_args)