Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim output from tests #37

Merged
merged 4 commits into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 37 additions & 24 deletions tests/tests_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#
# ### Run Against DEV Server.
# usrpw='' serverurl=http://localhost:8050 python -m unittest tests.tests_api
# usrpw='' serverurl=http://sparcdev2.csdc.noirlab.edu:8050 python -m unittest tests.tests_api # noqa: E501
# showact=1 usrpw='' serverurl=http://localhost:8050 python -m unittest tests.tests_api # noqa: E501
#
# python -m unittest -v tests.tests_api # VERBOSE (show what is skipped)
Expand Down Expand Up @@ -55,6 +56,7 @@
import numpy
import logging
import sys
import warnings

# Local Packages
from tests.utils import tic, toc
Expand All @@ -77,7 +79,7 @@
_STAGE = "https://sparclstage.datalab.noirlab.edu" # noqa: E221
_PROD = "https://astrosparcl.datalab.noirlab.edu" # noqa: E221

serverurl = os.environ.get("serverurl", _PAT1)
serverurl = os.environ.get("serverurl", _PROD)
#!DEV_SERVERS = [_DEV1,]
DEV_SERVERS = []

Expand All @@ -102,6 +104,7 @@

usrpw = os.environ.get("usrpw")

show_run_context = True

@contextmanager
def streamhandler_to_console(lggr):
Expand Down Expand Up @@ -165,14 +168,18 @@ def setUpClass(cls):
cls.doc = dict()
cls.count = dict()

print(
f"Running Client tests\n"
f' against Server: "{urlparse(serverurl).netloc}"\n'
f" comparing to: {exp.__name__}\n"
f" showact={showact}\n"
f" showcurl={showcurl}\n"
f" client={cls.client}\n"
)
global show_run_context

if show_run_context:
print(
f"Running Client Tests\n"
f' against Server: "{urlparse(serverurl).netloc}"\n'
f" comparing to: {exp.__name__}\n"
f" showact={showact}\n"
f" showcurl={showcurl}\n"
f" client={cls.client}\n"
)
show_run_context = False

# Get some id_lists to use in tests
found = cls.client.find(
Expand All @@ -182,8 +189,9 @@ def setUpClass(cls):
zip(*[(r["sparcl_id"], r["specid"]) for r in found.records])
)
sparc_ids, spec_ids = list(sparc_tups), list(spec_tups)
print(f"sparc_ids={sparc_ids}")
print(f"spec_ids={spec_ids}")
if showact:
print(f"sparc_ids={sparc_ids}")
print(f"spec_ids={spec_ids}")

# Lists of SPECID
cls.specid_list0 = spec_ids[:2]
Expand Down Expand Up @@ -275,7 +283,7 @@ def test_missing_specids_1(self):
"""Specids (not UUID) missing"""
badid = "NOT_SPEC_ID"
specids = set([badid] + self.specid_list0[:1])
missing = set(self.client.missing_specids(specids, verbose=True))
missing = set(self.client.missing_specids(specids, verbose=False))
if showact:
print(f"missing_specids_1: specids={specids}")
print(f"missing_specids_1: missing={missing}")
Expand Down Expand Up @@ -472,13 +480,10 @@ def test_reorder_1a(self):
"""Reorder retrieved records by sparcl_id."""
name = "reorder_1a"
ids = self.uuid_list2
print(f"ids: {ids}")

tic()
drs = ["SDSS-DR16", "BOSS-DR16", "DESI-EDR"]
res = self.client.retrieve(ids, dataset_list=drs)
res_ids = [r["sparcl_id"] for r in res.records]
print(f"retrieved: {res_ids}")
self.timing[name] = toc()
res_reorder = res.reorder(ids)
actual = [f["sparcl_id"] for f in res_reorder.records]
Expand Down Expand Up @@ -600,7 +605,7 @@ def test_dls_468(self):
uuid_list=idss,
include=["ra", "dec"],
dataset_list=["SDSS-DR16"],
verbose=True,
verbose=False,
)
self.assertEqual(1, re.count)

Expand Down Expand Up @@ -733,14 +738,18 @@ def setUpClass(cls):
url=serverurl, verbose=clverb, show_curl=showcurl
)

print(
jacquesalice marked this conversation as resolved.
Show resolved Hide resolved
f"Running Client tests\n"
f' against Server: "{urlparse(serverurl).netloc}"\n'
f" comparing to: {exp.__name__}\n"
f" {showact=}\n"
f" {showcurl=}\n"
f" {cls.client=}\n"
)
global show_run_context

if show_run_context:
print(
f"Running Client Tests\n"
f' against Server: "{urlparse(serverurl).netloc}"\n'
f" comparing to: {exp.__name__}\n"
f" showact={showact}\n"
f" showcurl={showcurl}\n"
f" client={cls.client}\n"
)
show_run_context = False

cls.outflds = ["sparcl_id", "data_release"]
cls.inc = ["data_release", "flux"]
Expand Down Expand Up @@ -969,12 +978,14 @@ def test_auth_retrieve_3(self):
# retrieve from authorized datasets (Public, in this case)
def test_auth_retrieve_4(self):
"""Retrieve method with unauthorized user; no datasets specified"""
warnings.filterwarnings("ignore")
exp = "exp.auth_retrieve_4"
self.auth_retrieve(self.unauth_user, None, exp)

# | retrieve | Unauth | Pub | PASS |
def test_auth_retrieve_5(self):
"""Retrieve method with unauthorized user; public datasets specified"""
warnings.filterwarnings("ignore")
exp = "exp.auth_retrieve_5"
self.auth_retrieve(self.unauth_user, self.Pub, exp)

Expand All @@ -991,11 +1002,13 @@ def test_auth_retrieve_6(self):
# retrieve from authorized datasets (Public, in this case)
def test_auth_retrieve_7(self):
"""Retrieve method with anonymous user; no data sets specified"""
warnings.filterwarnings("ignore")
exp = "exp.auth_retrieve_7"
self.auth_retrieve(None, None, exp)

# | retrieve | Anon | Pub | PASS |
def test_auth_retrieve_8(self):
"""Retrieve method with anonymous user; public data sets specified"""
warnings.filterwarnings("ignore")
exp = "exp.auth_retrieve_8"
self.auth_retrieve(None, self.Pub, exp)
Loading