Skip to content

TST: Minimize calls to remote sites.json for testing - #10304

Merged
mhvk merged 2 commits into
astropy:masterfrom
pllim:local-sites-json
May 5, 2020
Merged

mhvk merged 2 commits into
astropy:masterfrom
pllim:local-sites-json

Conversation

@pllim

@pllim pllim commented May 5, 2020 •

Copy link
Copy Markdown
Member

Description

This pull request is to expose force_builtin option in EarthLocation when looking up sites.json to minimize calls to sites.json that resides on the remote data server.

The portion of the tests that require IERS leap seconds table download still are marked as remote data.

Fixes #10298

Address part of #10255 (Nope, removing call to of_site did not change anything for this one.)

TODO

  • Add change log when new section is available.
  • Check remote data job. There will still be failures if astropy data server blacklisted the CI but not as many.
  • Squash commits?

@pllim pllim added this to the v4.2 milestone May 5, 2020
@pllim pllim mentioned this pull request May 5, 2020
1 task done
@bsipocz

bsipocz commented May 5, 2020

Copy link
Copy Markdown
Member

I'm 👎 for expanding sites.json. Why these obs, why not others. What to do with update PRs to this builtin file. This file started its life in astropy core, but exactly for these reasons got moved out.

@pllim

This comment has been minimized.

Comment thread docs/coordinates/index.rst Outdated

>>> from astropy.coordinates import EarthLocation, SkyCoord
>>> loc = EarthLocation.of_site('Royal Observatory Greenwich', force_builtin=True)
>>> keck = EarthLocation.of_site('Keck', force_builtin=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of relying on of_site() here, you could use it's coordinates hard wired (or append the local sites.json on the fly if Keck is missing from it during doctest)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, I guess hardcoding lon/lat at testsetup would be even better.

Hmmm! This means maybe I don't need to expose force_builtin after all...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I think if that's an acceptable hack we can avoid both force_builtin and the extension of the files. It's a bit of a cheat as the users will see different code than what's tested, but I suppose this one instance it's forgivable.

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the use of test setup, but am not that keen on the added keyword argument and wonder whether cannot be cleverer still. Inline a suggestion for the sites (untested...).

For the sky coordinates, since caching was just implemented for them, would it be possible to check the URL that gets created by name_resolve.get_icrs_coordinates and simply insert that in the cache as part of the test setup? The advantage is that there will not be any need for doctest skip (and the doctest is thus much closer to reality)

Actually, a related alternative would be to populate the site registry with 'Keck', etc., inside the test setup, so that you can leave the built-in file alone.

Anyway, not sure if it is worth the extra work - though getting rid of these remote_data tests is definitely nice!

Comment thread docs/coordinates/index.rst Outdated
.. testsetup::

>>> from astropy.coordinates import EarthLocation, SkyCoord
>>> loc = EarthLocation.of_site('Royal Observatory Greenwich', force_builtin=True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea of a test setup, but couldn't for the locations at least it be done simpler with:

from astropy.coordinates import EarthLocation
EarthLocation._get_site_registry(force_builtin=True)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: caching -- I don't think #9162 affects of_site?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EarthLocation._get_site_registry(force_builtin=True) is problematic because I need to use force_download to undo it, which defeats the purpose of not hitting data server.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in the other thread you're converging on hard-coding, which would be OK, though how about even more cheekily setting EarthLocation._site_registry = None at the end of tests? Probably overkill...

p.s. Yes, caching is only for SkyCoord. But only useful if the sites works too. My sense: go with @bsipocz suggestion and have an issue about perhaps prepopulating the cache instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to pre-populate cache on CI. I was under the impression that we need to store the tarball of the cache somewhere and then have the CI pull it but I have no idea how to set up the tarball in the first place.

Yes, I am in the works to hardcode stuff. Will push a commit soon.

@pllim

pllim commented May 5, 2020

Copy link
Copy Markdown
Member Author

So it seems like I shouldn't been exposing force_builtin and changing sites.json? Okay, I'll ponder a bit more. Thanks!

>>> target.radial_velocity_correction(obstime=obstime, location=keck).to('km/s') # doctest: +REMOTE_DATA +FLOAT_CMP
>>> target = SkyCoord.from_name('M31') # doctest: +SKIP
>>> keck = EarthLocation.of_site('Keck') # doctest: +SKIP
>>> target.radial_velocity_correction(obstime=obstime, location=keck).to('km/s') # doctest: +FLOAT_CMP +REMOTE_DATA

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can figure out the IERS stuff, we can remove +REMOTE_DATA here too but that is a battle for another day.

... observer=alma, target=ttau) # doctest: +IGNORE_WARNINGS +REMOTE_DATA
>>> sc_ttau # doctest: +REMOTE_DATA +FLOAT_CMP
... observer=alma, target=ttau) # doctest: +IGNORE_WARNINGS
>>> sc_ttau # doctest: +FLOAT_CMP +REMOTE_DATA

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the other example above, +REMOTE_DATA here is due to IERS leap seconds table, not of_site anymore.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we cannot set tests to execute with an offline or auto_download=False config - really, the bundled IERS is good enough for these tests so it should not download anything. But obviously Time cannot know this... Anyway, separate issue!

@bsipocz

bsipocz commented May 5, 2020

Copy link
Copy Markdown
Member

Now, that this is rescoped to test refactoring only, I think it can even go back to 4.0.2. What do you think?

Comment thread docs/coordinates/index.rst Resolved
@pllim pllim changed the title Expose force_builtin to minimize calls to remote sites.json for testing TST: Minimize calls to remote sites.json for testing May 5, 2020
@pllim pllim added the testing label May 5, 2020
@pllim pllim modified the milestones: v4.0.2, v4.1.1 May 5, 2020
@pllim

pllim commented May 5, 2020

Copy link
Copy Markdown
Member Author

@bsipocz , I moved the milestone to 4.1.1 because half the stuff I touched here were added for 4.1.

@pllim

This comment has been minimized.

Satellites example need remote data after all.
@pllim
pllim force-pushed the local-sites-json branch from bcca834 to 0bc0f4e Compare May 5, 2020 02:33
@pllim

pllim commented May 5, 2020

Copy link
Copy Markdown
Member Author

Weird, the coordinates failures are completely gone in the remote data job. I was expecting at least one to still fail. I can't tell if this patch is too successful or if GitHub stopped blacklisting CI.

The wcsapi failure is already handled in a different PR.

@StuartLittlefair StuartLittlefair left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me; a very tedious job of going through and coding everything by hand so thanks!

tree = dict(location=rog)
assert_roundtrip_tree(tree, tmpdir)
finally:
EarthLocation._site_registry = orig_sites

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should just make this a context manager as it seems like a useful thing to have?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly just as a setup_class, teardown_class, though for now this would seem good enough.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I briefly thought about turning it into a test class but decided that the line count would blow up and maybe not worth it. 🤷

I thought I opened an issue a long time ago to request changes to API allowing user to specify their own local sites.json but I cannot find that anymore. I think changing the API to context manager is out of scope here.

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be quite happy to get this in - only two small comments that may be good to address.

Comment thread astropy/coordinates/earth.py Resolved
Comment thread astropy/coordinates/earth.py Resolved
tree = dict(location=rog)
assert_roundtrip_tree(tree, tmpdir)
finally:
EarthLocation._site_registry = orig_sites

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly just as a setup_class, teardown_class, though for now this would seem good enough.

Comment thread docs/coordinates/index.rst Resolved
... observer=alma, target=ttau) # doctest: +IGNORE_WARNINGS +REMOTE_DATA
>>> sc_ttau # doctest: +REMOTE_DATA +FLOAT_CMP
... observer=alma, target=ttau) # doctest: +IGNORE_WARNINGS
>>> sc_ttau # doctest: +FLOAT_CMP +REMOTE_DATA

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we cannot set tests to execute with an offline or auto_download=False config - really, the bundled IERS is good enough for these tests so it should not download anything. But obviously Time cannot know this... Anyway, separate issue!

@mhvk

mhvk commented May 5, 2020

Copy link
Copy Markdown
Contributor

@pllim - if it would help clarify the other PRs, go ahead and merge, I think this is a good solution for now!

@pllim

pllim commented May 5, 2020

Copy link
Copy Markdown
Member Author

Hmm, I'll leave the merging to others. I try not to merge my own PR unless it is trivial. 😬

@mhvk
mhvk merged commit 220ee75 into astropy:master May 5, 2020
@pllim
pllim deleted the local-sites-json branch May 5, 2020 18:03
astrofrog pushed a commit that referenced this pull request May 19, 2020
TST: Minimize calls to remote sites.json for testing
@astrofrog astrofrog modified the milestones: v4.1.1, v4.1 May 22, 2020
@pllim pllim mentioned this pull request Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TST: Consider using a local copy of sites.json for testing

5 participants