from __future__ import (division, unicode_literals, print_function,
                        absolute_import)
from pytest import raises, yield_fixture, mark

from lantz_core import unit
from lantz_core.unit import (set_unit_registry, get_unit_registry,
                             to_float, to_quantity)

try:
    from pint import UnitRegistry
except ImportError:
    pass


@yield_fixture
def teardown():
    unit.UNIT_REGISTRY = None
    yield
    unit.UNIT_REGISTRY = None


@mark.skipif(unit.UNIT_SUPPORT is False, reason="Requires Pint")
def test_set_unit_registry(teardown):
    ureg = UnitRegistry()
    set_unit_registry(ureg)

    assert get_unit_registry() is ureg


@mark.skipif(unit.UNIT_SUPPORT is False, reason="Requires Pint")
def test_reset_unit_registry(teardown):
    ureg = UnitRegistry()
    set_unit_registry(ureg)
    with raises(ValueError):
        set_unit_registry(ureg)


def test_converters(teardown):
    """Test to_quantity and to_float utility functions.

    """
    val = 1.0
    assert to_float(to_quantity(val, 'A')) == val

from __future__ import (division, unicode_literals, print_function,
                        absolute_import)
from pytest import raises, yield_fixture, mark

from lantz_core import unit
from lantz_core.unit import (set_unit_registry, get_unit_registry,
                             to_float, to_quantity)

try:
    from pint import UnitRegistry
except ImportError:
    pass


@yield_fixture
def teardown():
    unit.UNIT_REGISTRY = None
    yield
    unit.UNIT_REGISTRY = None


@mark.skipif(unit.UNIT_SUPPORT is False, reason="Requires Pint")
def test_set_unit_registry(teardown):
    ureg = UnitRegistry()
    set_unit_registry(ureg)

    assert get_unit_registry() is ureg


@mark.skipif(unit.UNIT_SUPPORT is False, reason="Requires Pint")
def test_reset_unit_registry(teardown):
    ureg = UnitRegistry()
    set_unit_registry(ureg)
    with raises(ValueError):
        set_unit_registry(ureg)


def test_converters(teardown):
    """Test to_quantity and to_float utility functions.

    """
    val = 1.0
    assert to_float(val) == val
    assert to_float(to_quantity(val, 'A')) == val

Add missing test for to_float applied on a float (when pint is present).
Add missing test for to_float applied on a float (when pint is present).

  from __future__ import (division, unicode_literals, print_function,
                          absolute_import)
  from pytest import raises, yield_fixture, mark
  
  from lantz_core import unit
  from lantz_core.unit import (set_unit_registry, get_unit_registry,
                               to_float, to_quantity)
  
  try:
      from pint import UnitRegistry
  except ImportError:
      pass
  
  
  @yield_fixture
  def teardown():
      unit.UNIT_REGISTRY = None
      yield
      unit.UNIT_REGISTRY = None
  
  
  @mark.skipif(unit.UNIT_SUPPORT is False, reason="Requires Pint")
  def test_set_unit_registry(teardown):
      ureg = UnitRegistry()
      set_unit_registry(ureg)
  
      assert get_unit_registry() is ureg
  
  
  @mark.skipif(unit.UNIT_SUPPORT is False, reason="Requires Pint")
  def test_reset_unit_registry(teardown):
      ureg = UnitRegistry()
      set_unit_registry(ureg)
      with raises(ValueError):
          set_unit_registry(ureg)
  
  
  def test_converters(teardown):
      """Test to_quantity and to_float utility functions.
  
      """
      val = 1.0
+     assert to_float(val) == val
      assert to_float(to_quantity(val, 'A')) == val
  
Add missing test for to_float applied on a float (when pint is present).
## Code Before:
from __future__ import (division, unicode_literals, print_function,
                        absolute_import)
from pytest import raises, yield_fixture, mark

from lantz_core import unit
from lantz_core.unit import (set_unit_registry, get_unit_registry,
                             to_float, to_quantity)

try:
    from pint import UnitRegistry
except ImportError:
    pass


@yield_fixture
def teardown():
    unit.UNIT_REGISTRY = None
    yield
    unit.UNIT_REGISTRY = None


@mark.skipif(unit.UNIT_SUPPORT is False, reason="Requires Pint")
def test_set_unit_registry(teardown):
    ureg = UnitRegistry()
    set_unit_registry(ureg)

    assert get_unit_registry() is ureg


@mark.skipif(unit.UNIT_SUPPORT is False, reason="Requires Pint")
def test_reset_unit_registry(teardown):
    ureg = UnitRegistry()
    set_unit_registry(ureg)
    with raises(ValueError):
        set_unit_registry(ureg)


def test_converters(teardown):
    """Test to_quantity and to_float utility functions.

    """
    val = 1.0
    assert to_float(to_quantity(val, 'A')) == val

## Instruction:
Add missing test for to_float applied on a float (when pint is present).
## Code After:
from __future__ import (division, unicode_literals, print_function,
                        absolute_import)
from pytest import raises, yield_fixture, mark

from lantz_core import unit
from lantz_core.unit import (set_unit_registry, get_unit_registry,
                             to_float, to_quantity)

try:
    from pint import UnitRegistry
except ImportError:
    pass


@yield_fixture
def teardown():
    unit.UNIT_REGISTRY = None
    yield
    unit.UNIT_REGISTRY = None


@mark.skipif(unit.UNIT_SUPPORT is False, reason="Requires Pint")
def test_set_unit_registry(teardown):
    ureg = UnitRegistry()
    set_unit_registry(ureg)

    assert get_unit_registry() is ureg


@mark.skipif(unit.UNIT_SUPPORT is False, reason="Requires Pint")
def test_reset_unit_registry(teardown):
    ureg = UnitRegistry()
    set_unit_registry(ureg)
    with raises(ValueError):
        set_unit_registry(ureg)


def test_converters(teardown):
    """Test to_quantity and to_float utility functions.

    """
    val = 1.0
    assert to_float(val) == val
    assert to_float(to_quantity(val, 'A')) == val
