|
3 | 3 | import json |
4 | 4 | import os |
5 | 5 | import re |
| 6 | +import warnings |
6 | 7 | from shutil import copyfile |
7 | 8 | from unittest.mock import patch |
8 | 9 |
|
@@ -566,36 +567,91 @@ def test_mast_query(patch_post): |
566 | 567 | assert "Please provide at least one filter." in str(invalid_query.value) |
567 | 568 |
|
568 | 569 |
|
569 | | -def test_resolve_object(patch_post): |
| 570 | +def test_resolve_object_single(patch_post): |
570 | 571 | obj = "TIC 307210830" |
571 | 572 | tic_coord = SkyCoord(124.531756290083, -68.3129998725044, unit="deg") |
572 | 573 | simbad_coord = SkyCoord(124.5317560026638, -68.3130014904408, unit="deg") |
| 574 | + |
| 575 | + # Resolve without a specific resolver |
573 | 576 | obj_loc = mast.Mast.resolve_object(obj) |
| 577 | + assert isinstance(obj_loc, SkyCoord) |
574 | 578 | assert round(obj_loc.separation(tic_coord).value, 10) == 0 |
575 | 579 |
|
576 | | - # resolve using a specific resolver and an object that belongs to a MAST catalog |
| 580 | + # Resolve using a specific resolver and an object that belongs to a MAST catalog |
577 | 581 | obj_loc_simbad = mast.Mast.resolve_object(obj, resolver="SIMBAD") |
578 | 582 | assert round(obj_loc_simbad.separation(simbad_coord).value, 10) == 0 |
579 | 583 |
|
580 | | - # resolve using a specific resolver and an object that does not belong to a MAST catalog |
581 | | - obj_loc_simbad = mast.Mast.resolve_object("M101", resolver="SIMBAD") |
582 | | - assert round(obj_loc_simbad.separation(simbad_coord).value, 10) == 0 |
| 584 | + # Resolve using a specific resolver and an object that does not belong to a MAST catalog |
| 585 | + m1_coord = SkyCoord(83.6324, 22.0174, unit="deg") |
| 586 | + obj_loc_simbad = mast.Mast.resolve_object("M1", resolver="SIMBAD") |
| 587 | + assert isinstance(obj_loc_simbad, SkyCoord) |
| 588 | + assert round(obj_loc_simbad.separation(m1_coord).value, 10) == 0 |
583 | 589 |
|
584 | | - # resolve using all resolvers |
| 590 | + # Resolve using all resolvers |
585 | 591 | obj_loc_dict = mast.Mast.resolve_object(obj, resolve_all=True) |
586 | 592 | assert isinstance(obj_loc_dict, dict) |
587 | 593 | assert round(obj_loc_dict["SIMBAD"].separation(simbad_coord).value, 10) == 0 |
| 594 | + assert round(obj_loc_dict["TIC"].separation(tic_coord).value, 10) == 0 |
588 | 595 |
|
589 | | - # error with invalid resolver |
| 596 | + # Error with invalid resolver |
590 | 597 | with pytest.raises(ResolverError, match="Invalid resolver"): |
591 | 598 | mast.Mast.resolve_object(obj, resolver="invalid") |
592 | 599 |
|
593 | | - # warn if specifying both resolver and resolve_all |
| 600 | + # Error if single object cannot be resolved |
| 601 | + with pytest.raises(ResolverError, match='Could not resolve "nonexisting" to a sky position.'): |
| 602 | + mast.Mast.resolve_object("nonexisting") |
| 603 | + |
| 604 | + # Error if single object cannot be resolved with given resolver |
| 605 | + with pytest.raises(ResolverError, match='Could not resolve "Barnard\'s Star" to a sky position using ' |
| 606 | + 'resolver "NED".'): |
| 607 | + mast.Mast.resolve_object("Barnard's Star", resolver="NED") |
| 608 | + |
| 609 | + # Warn if specifying both resolver and resolve_all |
594 | 610 | with pytest.warns(InputWarning, match="The resolver parameter is ignored when resolve_all is True"): |
595 | 611 | loc = mast.Mast.resolve_object(obj, resolver="NED", resolve_all=True) |
596 | 612 | assert isinstance(loc, dict) |
597 | 613 |
|
598 | 614 |
|
| 615 | +def test_resolve_object_multi(patch_post): |
| 616 | + objects = ["TIC 307210830", "M1", "Barnard's Star"] |
| 617 | + |
| 618 | + # No resolver specified |
| 619 | + coord_dict = mast.Mast.resolve_object(objects) |
| 620 | + assert isinstance(coord_dict, dict) |
| 621 | + for obj in objects: |
| 622 | + assert obj in coord_dict |
| 623 | + assert isinstance(coord_dict[obj], SkyCoord) |
| 624 | + |
| 625 | + # Warn if one of the objects cannot be resolved |
| 626 | + with pytest.warns(InputWarning, match='Could not resolve "nonexisting" to a sky position.'): |
| 627 | + coord_dict = mast.Mast.resolve_object(["M1", "nonexisting"]) |
| 628 | + |
| 629 | + # Resolver specified |
| 630 | + coord_dict = mast.Mast.resolve_object(objects, resolver="SIMBAD") |
| 631 | + assert isinstance(coord_dict, dict) |
| 632 | + for obj in objects: |
| 633 | + assert obj in coord_dict |
| 634 | + assert isinstance(coord_dict[obj], SkyCoord) |
| 635 | + |
| 636 | + # Warn if one of the objects can't be resolved with given resolver |
| 637 | + with pytest.warns(InputWarning, match='Could not resolve "TIC 307210830" to a sky position using resolver "NED"'): |
| 638 | + mast.Mast.resolve_object(objects[:2], resolver="NED") |
| 639 | + |
| 640 | + # Resolve all |
| 641 | + coord_dict = mast.Mast.resolve_object(objects, resolve_all=True) |
| 642 | + assert isinstance(coord_dict, dict) |
| 643 | + for obj in objects: |
| 644 | + assert obj in coord_dict |
| 645 | + obj_dict = coord_dict[obj] |
| 646 | + assert isinstance(obj_dict, dict) |
| 647 | + assert isinstance(obj_dict["SIMBAD"], SkyCoord) |
| 648 | + |
| 649 | + # Error if none of the objects can be resolved |
| 650 | + warnings.simplefilter("ignore", category=InputWarning) # ignore warnings |
| 651 | + with pytest.raises(ResolverError, match='Could not resolve any of the given object names to sky positions.'): |
| 652 | + mast.Mast.resolve_object(["nonexisting1", "nonexisting2"]) |
| 653 | + |
| 654 | + |
599 | 655 | def test_login_logout(patch_post): |
600 | 656 | test_token = "56a9cf3df4c04052atest43feb87f282" |
601 | 657 |
|
|
0 commit comments