Skip to content

Commit

Permalink
Merge branch 'master' into inspections
Browse files Browse the repository at this point in the history
  • Loading branch information
djperrefort committed Aug 30, 2023
2 parents 5c1b388 + fc836a9 commit ce4bd03
Show file tree
Hide file tree
Showing 39 changed files with 321 additions and 343 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/PackageTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Test Package

on:
workflow_dispatch:
workflow_call:
push:

jobs:
run-tests:
name: Run Tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ "3.8", "3.9", "3.10", "3.11" ]

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install poetry
run: |
pip install poetry
poetry env use python${{ matrix.python-version }}
- name: Install dependencies
run: poetry install --with tests

- name: Run tests with coverage
run: |
poetry run coverage run -m unittest discover
poetry run coverage report --omit="tests/*"
poetry run coverage xml --omit="tests/*" -o coverage.xml
# Use this job for branch protection rules
report-test-status:
name: Report Test Status
if: always()
needs: run-tests
runs-on: ubuntu-latest
steps:
- name: Check build status
if: ${{ contains(needs.*.result, 'failure') }}
run: exit 1
33 changes: 0 additions & 33 deletions .travis.yml

This file was deleted.

2 changes: 0 additions & 2 deletions MANIFEST.in

This file was deleted.

3 changes: 0 additions & 3 deletions docs/requirements.txt

This file was deleted.

57 changes: 57 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "sndata"
version = "0.0.0" # Version is set dynamically by the CI tool on publication
authors = ["Daniel Perrefort"]
readme = "README.md"
description = "A Python interface for data published by various supernova surveys."
homepage = "http://sndata.readthedocs.io/"
repository = "https://github.com/sncosmo/SNData/"
documentation = "http://sndata.readthedocs.io/"
keywords = ["astronomy", "supernova", "data"]
packages = [{ include = "sndata" }]
include = [
"sndata/sdss/Spectra_txt.zip",
"sndata/loss/sndb_meta.csv"
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering :: Astronomy",
"Topic :: Scientific/Engineering :: Physics",
"Typing :: Typed"
]

[tool.poetry.dependencies]
python = ">=3.8"
beautifulsoup4 = "*"
astropy = "*"
cython = "*"
numpy = ">=1.17.0"
pandas = "*"
pyyaml = "*"
requests = "*"
tqdm = "*"
sncosmo = "*"
pytz = "*"

[tool.poetry.group.tests]
optional = true

[tool.poetry.group.tests.dependencies]
coverage = "*"

[tool.poetry.group.docs]
optional = true

[tool.poetry.group.docs.dependencies]
sphinx = "*"
sphinx-copybutton = "*"
sphinx_rtd_theme = "*"
10 changes: 0 additions & 10 deletions requirements.txt

This file was deleted.

9 changes: 0 additions & 9 deletions setup.cfg

This file was deleted.

54 changes: 0 additions & 54 deletions setup.py

This file was deleted.

3 changes: 0 additions & 3 deletions sndata/sweetspot/_dr1.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,12 @@ def _get_data_for_id(self, obj_id: str, format_table: bool = True) -> Table:
def _decompress_filters(self):
"""Decompress filter files into the filter directory"""

print(self._filter_zip_path)
with tarfile.open(self._filter_zip_path) as data_archive:
for ffile in data_archive:
path = self._filter_dir / ffile.name
if path.exists():
continue

print(f'Unzipping {ffile.name}')

try:
data_archive.extract(ffile, path=self._filter_dir)

Expand Down
4 changes: 2 additions & 2 deletions sndata/utils/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ def download_file(
if verbose:
tqdm.write(f'Fetching {url}', file=sys.stdout)
response = requests.get(url, stream=True, timeout=timeout)
response.raise_for_status()

total = int(response.headers.get('content-length', 0))
chunk_size = 1024
with tqdm(total=total, unit='B', unit_scale=True,
unit_divisor=chunk_size, file=sys.stdout) as pbar:
with tqdm(total=total, unit='B', unit_scale=True, unit_divisor=chunk_size, file=sys.stdout) as pbar:
for data in response.iter_content(chunk_size=chunk_size):
pbar.update(destination.write(data))

Expand Down
20 changes: 20 additions & 0 deletions tests/common_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""This module defines reusable setup and testing logic for streamlining the
creation of downstream tests.
"""

from unittest import SkipTest

import requests

from .data_parsing_tests import *
from .ui_tests import *


def download_data_or_skip(release):
"""Download data for the given data release. Skip any further tests if the download fails"""

try:
release.download_module_data()

except requests.exceptions.ConnectionError:
raise SkipTest('Could not connect to one or more remote servers.')
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""This module provides template testing classes for spectroscopic and
photometric data parsing.
"""
"""Template test classes for spectroscopic and photometric data parsing."""

import numpy as np
import sncosmo
Expand All @@ -27,9 +25,7 @@ def test_no_empty_data_tables(self, lim: int = 25):
return

obj_id = input_table.meta['obj_id']
self.assertTrue(
input_table,
msg=f'Empty table for obj_id {obj_id}.')
self.assertTrue(input_table, msg=f'Empty table for obj_id {obj_id}.')

if i < 0:
self.fail('No data yielded')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""This module provides template testing classes for the user interface of
spectroscopic and photometric data releases.
"""
"""Template test classes for high level data release class behavior."""


class SpectroscopicDataUI:
Expand Down
47 changes: 0 additions & 47 deletions tests/test_base_classes.py

This file was deleted.

6 changes: 2 additions & 4 deletions tests/test_combined_datasets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Test that survey data is accessed and served correctly for combined data
sets
"""
"""Test that survey data is accessed and served correctly for combined data sets."""

from unittest import TestCase

Expand All @@ -9,7 +7,7 @@
from sndata import CombinedDataset
from sndata import csp, des
from sndata._combine_data import reduce_id_mapping
from .data_parsing_template_tests import PhotometricDataParsing
from .common_tests import PhotometricDataParsing
from .test_exceptions import InvalidTableId


Expand Down
Empty file added tests/test_csp/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions tests/test_csp/test_dr1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Tests for the ``csp.DR1`` class."""

from unittest import TestCase

from sndata.csp import DR1
from ..common_tests import SpectroscopicDataParsing, SpectroscopicDataUI, download_data_or_skip

download_data_or_skip(DR1())


class DR1Parsing(TestCase, SpectroscopicDataParsing):
"""Data parsing tests for the DR1 release"""

@classmethod
def setUpClass(cls):
cls.test_class = DR1()


class DR1UI(TestCase, SpectroscopicDataUI):
"""UI tests for the DR1 release"""

@classmethod
def setUpClass(cls):
cls.test_class = DR1()
Loading

0 comments on commit ce4bd03

Please sign in to comment.