Skip to content

Commit

Permalink
added tests for cli availability
Browse files Browse the repository at this point in the history
  • Loading branch information
dchaddock committed Feb 4, 2025
1 parent 8e10a46 commit 5745f0f
Show file tree
Hide file tree
Showing 13 changed files with 347 additions and 62 deletions.
74 changes: 37 additions & 37 deletions COVERAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,58 @@ Current coverage report:
Name Stmts Miss Cover Missing
--------------------------------------------------------------------------------------------
pyaurorax/__init__.py 9 0 100%
pyaurorax/_util.py 5 0 100%
pyaurorax/cli/cli.py 41 41 0% 15-93
pyaurorax/cli/search/__init__.py 16 16 0% 15-35
pyaurorax/cli/search/availability/commands.py 138 138 0% 15-241
pyaurorax/cli/search/conjunctions/commands.py 184 184 0% 15-370
pyaurorax/cli/search/data_products/commands.py 175 175 0% 15-337
pyaurorax/cli/search/ephemeris/commands.py 173 173 0% 15-323
pyaurorax/cli/search/helpers.py 158 158 0% 15-276
pyaurorax/cli/search/sources/commands.py 315 315 0% 15-544
pyaurorax/cli/search/util/commands.py 124 124 0% 15-294
pyaurorax/cli/templates.py 3 3 0% 19-90
pyaurorax/_util.py 5 3 40% 25-27
pyaurorax/cli/cli.py 37 0 100%
pyaurorax/cli/search/__init__.py 16 0 100%
pyaurorax/cli/search/availability/commands.py 127 0 100%
pyaurorax/cli/search/conjunctions/commands.py 184 114 38% 62-79, 84, 102-113, 137-154, 168-184, 201, 215-241, 252-257, 285-340, 355-370
pyaurorax/cli/search/data_products/commands.py 175 111 37% 36-58, 63, 81-92, 115-129, 143-159, 176, 190-216, 227-232, 252-297, 322-337
pyaurorax/cli/search/ephemeris/commands.py 173 109 37% 36-56, 61, 79-90, 113-127, 141-157, 174, 188-214, 225-230, 250-293, 308-323
pyaurorax/cli/search/helpers.py 158 140 11% 32-35, 46-86, 97-148, 160-276
pyaurorax/cli/search/sources/commands.py 315 240 24% 40-51, 60-114, 118-167, 172-255, 260, 282-304, 326-382, 405-416, 435-442, 456-463, 485-497, 515-526, 539-544
pyaurorax/cli/search/util/commands.py 124 81 35% 29-108, 113, 142-153, 182-193, 244-281, 293-294
pyaurorax/cli/templates.py 3 0 100%
pyaurorax/data/__init__.py 81 64 21% 49, 78-90, 125-164, 187-201, 233-245, 280-319
pyaurorax/data/ucalgary/__init__.py 110 81 26% 35, 68, 96-104, 126-129, 160-163, 172, 193, 311-329, 419-433, 494-504, 586, 639-675, 719-755, 799-835
pyaurorax/data/ucalgary/read/__init__.py 43 21 51% 22, 41, 62, 141-155, 224-236, 305, 383, 462, 541, 619, 667, 711, 786
pyaurorax/exceptions.py 28 0 100%
pyaurorax/models/__init__.py 10 1 90% 49
pyaurorax/models/atm/__init__.py 22 9 59% 38, 168-189, 279-297
pyaurorax/pyaurorax.py 222 75 66% 147, 173, 180, 187, 207, 211, 259, 296-301, 308, 312, 339-347, 426, 459-537
pyaurorax/search/__init__.py 93 0 100%
pyaurorax/pyaurorax.py 222 114 49% 147, 173, 180, 187, 202, 207, 211, 223-233, 244-248, 270-272, 283-285, 292, 296-301, 308, 312, 318, 321, 339-347, 391-401, 421-431, 459-537
pyaurorax/search/__init__.py 93 6 94% 169, 197, 204, 211, 218, 225
pyaurorax/search/api/__init__.py 20 0 100%
pyaurorax/search/api/classes/request.py 73 26 64% 70-71, 79, 111-112, 116-123, 133-135, 139, 143-147, 151, 155-159, 165, 169, 183, 186
pyaurorax/search/api/classes/request.py 73 32 56% 70-71, 79, 111-112, 116-123, 127-135, 139, 143-147, 151, 155-159, 165, 169-174, 183, 186
pyaurorax/search/api/classes/response.py 11 2 82% 43, 46
pyaurorax/search/availability/__init__.py 14 0 100%
pyaurorax/search/availability/_availability.py 21 0 100%
pyaurorax/search/availability/classes/availability_result.py 8 0 100%
pyaurorax/search/conjunctions/__init__.py 29 3 90% 61, 190, 258
pyaurorax/search/conjunctions/_conjunctions.py 94 60 36% 42, 47-49, 57, 63, 67, 72, 84-147, 154-157, 175-191
pyaurorax/search/conjunctions/classes/conjunction.py 24 2 92% 99, 102
pyaurorax/search/conjunctions/__init__.py 29 6 79% 61, 132, 190, 210, 226, 258
pyaurorax/search/conjunctions/_conjunctions.py 94 81 14% 31-79, 84-147, 152-165, 169-170, 175-191
pyaurorax/search/conjunctions/classes/conjunction.py 24 11 54% 88-96, 99, 102
pyaurorax/search/conjunctions/classes/criteria_block.py 84 60 29% 45-48, 51, 54, 66-76, 107-111, 114, 117, 130-141, 144-147, 166-168, 171, 174, 185-194, 209, 212, 215, 221-222, 225-233
pyaurorax/search/conjunctions/classes/search.py 215 70 67% 40, 148, 151, 162-203, 271, 315-320, 327-334, 343-349, 358-359, 377, 419, 423, 445-446, 457-458, 530-535
pyaurorax/search/conjunctions/classes/search.py 215 179 17% 40, 124-145, 148, 151, 162-203, 207-220, 232-245, 259-279, 289, 294-298, 309-373, 377, 387-403, 418-432, 445-446, 456-474, 491-492, 519-520, 530-535
pyaurorax/search/conjunctions/swarmaurora/__init__.py 15 3 80% 46, 65, 87
pyaurorax/search/conjunctions/swarmaurora/_swarmaurora.py 25 18 28% 25, 29-35, 41-58
pyaurorax/search/data_products/__init__.py 33 2 94% 124, 234
pyaurorax/search/data_products/_data_products.py 100 31 69% 40-44, 71, 76-78, 86, 92, 96, 101, 128, 143-145, 154, 169, 177-204, 211-214
pyaurorax/search/data_products/classes/data_product.py 47 2 96% 130, 154
pyaurorax/search/data_products/classes/search.py 128 46 64% 33, 142, 145, 156-197, 209, 235, 272, 291-292, 300-301, 371-376
pyaurorax/search/ephemeris/__init__.py 30 1 97% 119
pyaurorax/search/ephemeris/_ephemeris.py 88 21 76% 38-42, 68, 73-75, 83, 89, 93, 98, 125, 140-142, 151, 167, 177-180
pyaurorax/search/ephemeris/classes/ephemeris.py 42 1 98% 97
pyaurorax/search/ephemeris/classes/search.py 129 49 62% 33, 138, 141, 152-193, 203-208, 230, 241, 274, 292-293, 301-302, 371-376
pyaurorax/search/location.py 29 6 79% 52-55, 63-66
pyaurorax/search/metadata/__init__.py 14 0 100%
pyaurorax/search/metadata/_metadata.py 20 5 75% 29-31, 45, 54
pyaurorax/search/data_products/__init__.py 33 8 76% 122-129, 175, 199, 234, 251, 268
pyaurorax/search/data_products/_data_products.py 100 83 17% 38-54, 60-106, 111-148, 153-172, 177-204, 209-222, 226-227
pyaurorax/search/data_products/classes/data_product.py 47 29 38% 102-107, 118-141, 144, 148-157
pyaurorax/search/data_products/classes/search.py 128 101 21% 33, 118-139, 142, 145, 156-197, 205-231, 235, 242-255, 267-281, 291-292, 299-316, 330-331, 360-361, 371-376
pyaurorax/search/ephemeris/__init__.py 30 7 77% 117-124, 163, 191, 208, 224
pyaurorax/search/ephemeris/_ephemeris.py 88 73 17% 36-52, 58-103, 108-145, 150-170, 175-188, 192-193
pyaurorax/search/ephemeris/classes/ephemeris.py 42 33 21% 60-66, 77-108, 111, 115-121
pyaurorax/search/ephemeris/classes/search.py 129 102 21% 33, 115-135, 138, 141, 152-193, 201-226, 230, 240-257, 269-283, 292-293, 300-317, 330-331, 360-361, 371-376
pyaurorax/search/location.py 29 15 48% 40-44, 48, 52-55, 59, 63-66, 76, 79, 82
pyaurorax/search/metadata/__init__.py 14 3 79% 57, 70, 83
pyaurorax/search/metadata/_metadata.py 20 15 25% 24-34, 39-45, 50-56
pyaurorax/search/metadata_filters.py 61 39 36% 53-55, 59, 63-66, 69, 73-78, 86-89, 95, 126-127, 131, 135-137, 140, 144-152, 159-169, 175
pyaurorax/search/requests/__init__.py 28 3 89% 144, 191, 207
pyaurorax/search/requests/_requests.py 97 44 55% 51, 85, 96, 101, 112, 119-122, 126, 132-169, 174-181
pyaurorax/search/sources/__init__.py 59 26 56% 183-240
pyaurorax/search/sources/_sources.py 119 16 87% 50, 52, 132, 154-155, 189, 208, 211, 213, 215, 217, 245-246, 257, 293-294
pyaurorax/search/requests/__init__.py 28 7 75% 58, 80, 93, 112, 144, 191, 207
pyaurorax/search/requests/_requests.py 97 83 14% 34-38, 43-74, 79-85, 90-102, 107-127, 132-169, 174-181
pyaurorax/search/sources/__init__.py 59 33 44% 118, 183-240, 284, 385, 419, 437, 456, 523
pyaurorax/search/sources/_sources.py 119 85 29% 39-55, 89, 92, 107-135, 153-157, 162-173, 178-192, 207-246, 251-262, 268-294
pyaurorax/search/sources/classes/data_source.py 68 26 62% 170, 173, 186-212
pyaurorax/search/sources/classes/data_source_stats.py 22 9 59% 61, 64, 73-79
pyaurorax/search/util/__init__.py 11 0 100%
pyaurorax/search/util/_calculate_btrace.py 18 0 100%
pyaurorax/search/sources/classes/data_source_stats.py 22 15 32% 53-58, 61, 64, 73-79
pyaurorax/search/util/__init__.py 11 2 82% 52, 72
pyaurorax/search/util/_calculate_btrace.py 18 12 33% 26-35, 40-46, 51-57
pyaurorax/tools/__init__.py 61 12 80% 93, 100, 107, 114, 121, 128, 135, 142, 222, 256, 298, 313
pyaurorax/tools/_display.py 35 31 11% 22-84
pyaurorax/tools/_movie.py 37 32 14% 21, 34-95
Expand Down Expand Up @@ -94,7 +94,7 @@ pyaurorax/tools/mosaic/_prep_skymaps.py 119 112
pyaurorax/tools/spectra/__init__.py 10 1 90% 129
pyaurorax/tools/spectra/_plot.py 114 108 5% 42-233
--------------------------------------------------------------------------------------------
TOTAL 6214 4295 31%
TOTAL 6199 4403 29%
13 empty files skipped.
```
15 changes: 7 additions & 8 deletions pyaurorax/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import requests
import click
import pyaurorax
Expand All @@ -32,23 +33,21 @@ def __init__(self, verbose=False, api_key=None, api_base_url=None):
self.aurorax.api_base_url = api_base_url


def __test_connectivity(aurorax, quiet=False, return_json=False):
def __test_connectivity(aurorax):
# make request
click.echo("Checking connectivity to %s ...\n" % (aurorax.api_base_url))
try:
r = requests.get(aurorax.api_base_url, timeout=aurorax.api_timeout)
except requests.RequestException as e:
except requests.RequestException as e: # pragma: nocover
click.echo("Error connecting to AuroraX API: %s" % (str(e)))
return
sys.exit(1)

# check status code
if (r.status_code == 200):
if (quiet is False):
click.echo("Connectivity to the AuroraX API looks good!")
if (return_json is True):
return r.json()
click.echo("Connectivity to the AuroraX API looks good!")
else:
click.echo("Error connecting to AuroraX API, got a %d response" % (r.status_code))
sys.exit(1)


@click.group(invoke_without_command=True)
Expand All @@ -72,7 +71,7 @@ def cli(ctx, api_key, api_base_url, verbose, test_connectivity):
if (ctx.invoked_subcommand is None):
if (test_connectivity is True):
# evaluate --test-connectivity
__test_connectivity(ctx.obj.aurorax, quiet=False)
__test_connectivity(ctx.obj.aurorax)
else:
# no options called, output the help
click.echo("""Welcome to the PyAuroraX CLI program!
Expand Down
26 changes: 11 additions & 15 deletions pyaurorax/cli/search/availability/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def availability_group():
def __print_availability_table(type, availability, order):
# check to see if there's anything to show
if (len(availability) == 0):
click.echo(f"No {type} availability information found!")
click.echo(f"No {type.replace('_', ' ')} availability information found!")
return

# set table lists
Expand All @@ -42,15 +42,11 @@ def __print_availability_table(type, availability, order):
table_counts = []
for a in availability:
# set which info to use, based on type
dates_and_counts = None
if (type == "ephemeris"):
dates_and_counts = a.available_ephemeris
elif (type == "data products"):
else:
# type must be data_products
dates_and_counts = a.available_data_products
if (dates_and_counts is None):
click.echo("Unexpected error occurred, please open an issue on the Github repository detailing "
"how you were able to make this message appear")
return

# for each date
for date, count in dates_and_counts.items():
Expand Down Expand Up @@ -107,7 +103,7 @@ def __print_availability_table(type, availability, order):
@click.option("--instrument-type", type=str, help="The instrument type to filter for")
@click.option("--source-type", type=str, help="The source type to filter for")
@click.option("--order",
type=click.Choice(["identifier", "program", "platform", "instrument_type", "display_name"]),
type=click.Choice(["identifier", "program", "platform", "instrument_type", "source_type", "display_name"]),
default="identifier",
show_default=True,
help="Order results using a certain column")
Expand All @@ -119,7 +115,7 @@ def ephemeris(config, start_date, end_date, program, platform, instrument_type,
\b
START_DATE the start date to retrieve info for, inclusive (valid formats: YYYY/MM/DD, YYYY-MM-DD, YYYYMMDD)
END_DATE the end date to retrieve info for, inclusive (valid formats: YYYY/MM/, YYYY-MM-DD, YYYYMMDD)
END_DATE the end date to retrieve info for, inclusive (valid formats: YYYY/MM/DD, YYYY-MM-DD, YYYYMMDD)
"""
# set start and end datetime objects
try:
Expand Down Expand Up @@ -151,7 +147,7 @@ def ephemeris(config, start_date, end_date, program, platform, instrument_type,
platform=platform,
instrument_type=instrument_type,
source_type=source_type)
except pyaurorax.AuroraXError as e:
except pyaurorax.AuroraXError as e: # pragma: nocover
click.echo("%s occurred: %s" % (type(e).__name__, e.args[0]))
sys.exit(1)

Expand All @@ -171,7 +167,7 @@ def ephemeris(config, start_date, end_date, program, platform, instrument_type,

# reverse
if (reversed_ is True):
a = reversed(a)
a = list(reversed(a))

# print it out nicely
__print_availability_table("ephemeris", a, order)
Expand All @@ -185,7 +181,7 @@ def ephemeris(config, start_date, end_date, program, platform, instrument_type,
@click.option("--instrument-type", type=str, help="The instrument type to filter for")
@click.option("--source-type", type=str, help="The source type to filter for")
@click.option("--order",
type=click.Choice(["identifier", "program", "platform", "instrument_type", "display_name"]),
type=click.Choice(["identifier", "program", "platform", "instrument_type", "source_type", "display_name"]),
default="identifier",
show_default=True,
help="Order results using a certain column")
Expand All @@ -197,7 +193,7 @@ def data_products(config, start_date, end_date, program, platform, instrument_ty
\b
START_DATE the start date to retrieve info for, inclusive (valid formats: YYYY/MM/DD, YYYY-MM-DD, YYYYMMDD)
END_DATE the end date to retrieve info for, inclusive (valid formats: YYYY/MM/, YYYY-MM-DD, YYYYMMDD)
END_DATE the end date to retrieve info for, inclusive (valid formats: YYYY/MM/DD, YYYY-MM-DD, YYYYMMDD)
"""
# set start and end datetime objects
try:
Expand Down Expand Up @@ -229,13 +225,13 @@ def data_products(config, start_date, end_date, program, platform, instrument_ty
platform=platform,
instrument_type=instrument_type,
source_type=source_type)
except pyaurorax.AuroraXError as e:
except pyaurorax.AuroraXError as e: # pragma: nocover
click.echo("%s occurred: %s" % (type(e).__name__, e.args[0]))
sys.exit(1)

# reverse
if (reversed_ is True):
a = reversed(a)
a = list(reversed(a))

# print it out nicely
__print_availability_table("data products", a, order)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ markers = [
"top_level: top level PyAuroraX object tests",
"search_ro: search engine read-only tests",
"search_rw: search engine read/write tests",
"cli: command line interface tests",
]

[tool.bandit]
Expand Down
Empty file.
Empty file.
Empty file.
Loading

0 comments on commit 5745f0f

Please sign in to comment.