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

Start to add tests #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def read(rel_path):
extras_require={
# Note that "lofar-utils" also depends on the python bindings to the LOFAR ParmDB.
# Since these have never been published on PyPI, we cannot specify this dependency.
"lofar-utils": ["losoto"]
"lofar-utils": ["losoto"],
"dev": ["pytest", "pytest-cov", "ruff", "pre-commit"],
},
entry_points={
"console_scripts": [
Expand Down
Empty file added tests/__init__.py
Empty file.
67 changes: 67 additions & 0 deletions tests/test_formatters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Tests for the formatters module
"""

from datetime import datetime, timedelta
import random
from RMextract.formatters import KNOWN_FORMATTERS, ftp_aiub_unibe_ch, cddis_gsfc_nasa_gov, igsiono_uwm_edu_pl, chapman_upc_es

def test_known_formatters():
"""
Test that the known formatters are correct
"""
assert KNOWN_FORMATTERS["ftp.aiub.unibe.ch"] == ftp_aiub_unibe_ch
assert KNOWN_FORMATTERS["cddis.gsfc.nasa.gov"] == cddis_gsfc_nasa_gov
assert KNOWN_FORMATTERS["igsiono.uwm.edu.pl"] == igsiono_uwm_edu_pl
assert KNOWN_FORMATTERS["http://chapman.upc.es"] == chapman_upc_es

def test_ftp_aiub_unibe_ch():
"""
Test the ftp_aiub_unibe_ch formatter
"""
for server in ["ftp://ftp.aiub.unibe.ch", "file://ftp.aiub.unibe.ch"]:
year = random.randint(2000, 2024)
dayofyear = random.randint(1, 366)
prefix = "CODG"
url = ftp_aiub_unibe_ch(server, year, dayofyear, prefix)
expected = f"{server}/CODE/{year:4d}/{prefix.upper()}{dayofyear:03d}0.{year%100:02d}I.Z"
assert url == expected, f"Expected {expected}, got {url}"

def test_cddis_gsfc_nasa_gov():
"""
Test the cddis_gsfc_nasa_gov formatter
"""
for server in ["ftp://cddis.gsfc.nasa.gov", "file://cddis.gsfc.nasa.gov"]:
year = random.randint(2000, 2024)
dayofyear = random.randint(1, 366)
prefix = "CODG"
url = cddis_gsfc_nasa_gov(server, year, dayofyear, prefix)
expected = f"{server}/gnss/products/ionex/{year:4d}/{dayofyear:03d}/{prefix.lower()}{dayofyear:03d}0.{year%100:02d}i.Z"
assert url == expected, f"Expected {expected}, got {url}"

def test_igsiono_uwm_edu_pl():
"""
Test the igsiono_uwm_edu_pl formatter
"""
for server in ["ftp://igsiono.uwm.edu.pl", "file://igsiono.uwm.edu.pl"]:
year = random.randint(2000, 2024)
dayofyear = random.randint(1, 366)
prefix = "IGRG"
url = igsiono_uwm_edu_pl(server, year, dayofyear, prefix)
expected = f"{server}/data/ilt/{year:4d}/{prefix.lower()}{dayofyear:03d}0.{year%100:02d}i"
assert url == expected, f"Expected {expected}, got {url}"

def test_chapman_upc_es():
"""
Test the chapman_upc_es formatter
"""
for server in ["http://chapman.upc.es", "file://chapman.upc.es"]:
year = random.randint(2000, 2024)
dayofyear = random.randint(1, 366)
prefix = "CODG"
url = chapman_upc_es(server, year, dayofyear, prefix)
dt = datetime(year,1,1) + timedelta(dayofyear-1)
expected = f"{server}/tomion/rapid/{year:4d}/{dayofyear:03d}_{year%100:02d}{dt.month:02d}{dt.day:02d}.15min/{prefix.lower()}{dayofyear:03d}0.{year%100:02d}i.Z"
assert url == expected, f"Expected {expected}, got {url}"