[AstroPy] Revert to astropy 1.3 constants (for testing) in astropy 2.0

Duncan Macleod duncan.macleod at ligo.org
Mon Jul 10 10:01:52 EDT 2017


Hi Derek,

Unfortunately, I don't want to change the imports in my module, but only in
the test suite. Essentially I want to mock the constants module back to
astropy-1.3 values.

In the end I ended up with the following in my test module:

from astropy import __version__ as astropy_version
if astropy_version >= '2.0':
    from astropy import constants
    from astropy.constants import (si, astropyconst13)
    units.M_sun._represents = units.Unit(astropyconst13.M_sun)
    constants.M_sun = si.M_sun = astropyconst13.M_sun
    constants.G = si.G = astropyconst13.G
    constants.c = si.c = astropyconst13.c
    constants.pc = si.pc = astropyconst13.pc

to just fix the constants I need without editing the module code that
actually uses them. This is after the module import, but before any
function calls. A bit messy, but does the job.


D

On 10 July 2017 at 14:56, Derek Homeier <
derek at astro.physik.uni-goettingen.de> wrote:

> On 10 Jul 2017, at 2:34 pm, Duncan Macleod <duncan.macleod at ligo.org>
> wrote:
> >
> > Is there a way to tell astropy.constants to use the version 1.3
> constants (from astropy.constants.astropyconst13) when using the v2.0
> package? i.e. have astropy.constants.M_sun come from iau2012 and not
> iau2015?
> >
> > I have a bunch of unit tests are now failing because of the relatively
> large changes in some constants.*
> >
> Depends on how you currently import them, but replacing e.g.
>
> from astropy import constants as const
>
> with
>
> from astropy.constants import astropyconst13 as const
>
> should have the desired effect.
>
> HTH
>                                                 Derek
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>



-- 
Duncan Macleod
duncan.macleod at ligo.org
Sêr Cymru Cofund Fellow
School of Physics and Astronomy
Cardiff University
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20170710/5ee98f20/attachment.html>


More information about the AstroPy mailing list