Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# -*- coding: utf-8 -*- | ||
# Licensed under a 3-clause BSD style license - see LICENSE.rst | ||
"""This package defines deprecated units. | ||
These units are not available in the top-level `astropy.units` | ||
namespace. To use these units, you must import the `astropy.units.deprecated` | ||
module:: | ||
>>> from astropy.units import deprecated | ||
>>> q = 10. * deprecated.emu # doctest: +SKIP | ||
To include them in `~astropy.units.UnitBase.compose` and the results of | ||
`~astropy.units.UnitBase.find_equivalent_units`, do:: | ||
>>> from astropy.units import deprecated | ||
>>> deprecated.enable() # doctest: +SKIP | ||
""" | ||
from __future__ import (absolute_import, division, print_function, | ||
unicode_literals) | ||
|
||
_ns = globals() | ||
|
||
|
||
def _initialize_module(): | ||
# Local imports to avoid polluting top-level namespace | ||
from . import cgs | ||
from .core import def_unit | ||
|
||
def_unit(['emu'], cgs.Bi, namespace=_ns, | ||
doc='Biot: CGS (EMU) unit of current') | ||
|
||
|
||
_initialize_module() | ||
|
||
|
||
########################################################################### | ||
# DOCSTRING | ||
|
||
# This generates a docstring for this module that describes all of the | ||
# standard units defined here. | ||
from .utils import generate_unit_summary as _generate_unit_summary # noqa | ||
if __doc__ is not None: | ||
__doc__ += _generate_unit_summary(globals()) | ||
|
||
|
||
def enable(): | ||
""" | ||
Enable deprecated units so they appear in results of | ||
`~astropy.units.UnitBase.find_equivalent_units` and | ||
`~astropy.units.UnitBase.compose`. This will disable | ||
all of the "default" `astropy.units` units, since there | ||
are some namespace clashes between the two. | ||
This may be used with the ``with`` statement to enable deprecated | ||
units only temporarily. | ||
""" | ||
# Local import to avoid cyclical import | ||
from .core import set_enabled_units | ||
# Local import to avoid polluting namespace | ||
import inspect | ||
return set_enabled_units(inspect.getmodule(enable)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
# Licensed under a 3-clause BSD style license - see LICENSE.rst | ||
|
||
# TEST_UNICODE_LITERALS | ||
|
||
"""Regression tests for deprecated units.""" | ||
from __future__ import (absolute_import, unicode_literals, division, | ||
print_function) | ||
|
||
from .. import deprecated | ||
from ... import units as u | ||
from ...tests.helper import pytest # TODO: Stop using bundled pytest | ||
|
||
|
||
def test_emu(): | ||
with pytest.raises(AttributeError): | ||
u.emu | ||
|
||
assert u.Bi.to(deprecated.emu, 1) == 1 | ||
|
||
with deprecated.enable(): | ||
assert u.Bi.compose()[0] == deprecated.emu | ||
|
||
assert u.Bi.compose()[0] == u.Bi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters