Skip to content

Commit

Permalink
Merge pull request #51 from esheldon/tests
Browse files Browse the repository at this point in the history
Add unit tests
  • Loading branch information
esheldon authored Mar 29, 2021
2 parents 066cb3e + 7385f76 commit 7eaf0e7
Show file tree
Hide file tree
Showing 15 changed files with 1,437 additions and 801 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: tests

on:
push:
branches:
- master
pull_request: null

jobs:
tests:
name: tests
strategy:
matrix:
pyver: [3.6, 3.7, 3.8]

runs-on: "ubuntu-latest"

steps:
- uses: actions/checkout@v2

- uses: conda-incubator/setup-miniconda@v2
with:
python-version: ${{ matrix.pyver }}
channels: conda-forge,defaults
channel-priority: strict
show-channel-urls: true

- name: configure conda and install code
shell: bash -l {0}
run: |
conda config --set always_yes yes
conda install -q mamba
# requirements for meds
mamba install -q --file requirements.txt
# installs for testing
mamba install -q \
pip \
setuptools \
flake8 \
pytest-cov
python -m pip install -e .
- name: lint
shell: bash -l {0}
run: |
flake8 meds
- name: test
shell: bash -l {0}
run: |
pytest -v --cov=meds --cov-report term-missing meds
1 change: 1 addition & 0 deletions meds/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa
from .defaults import __version__
from . import meds

Expand Down
33 changes: 14 additions & 19 deletions meds/bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ class Bounds(object):
Based on Bounds from deswl_shapelets
"""
def __init__(self, rowmin, rowmax, colmin, colmax):
self.rowmin=rowmin
self.rowmax=rowmax
self.colmin=colmin
self.colmax=colmax
self.rowmin = rowmin
self.rowmax = rowmax
self.colmin = colmin
self.colmax = colmax

def contains_point(self, row, col):
"""
Expand All @@ -33,11 +33,10 @@ def contains_points(self, rows, cols):
rows,cols: arrays
The positions to check
"""
return ( (rows <= self.rowmax)
& (rows >= self.rowmin)
& (cols <= self.colmax)
& (cols >= self.colmin) )

return ((rows <= self.rowmax) &
(rows >= self.rowmin) &
(cols <= self.colmax) &
(cols >= self.colmin))

def contains_bounds(self, bounds):
"""
Expand All @@ -48,7 +47,7 @@ def contains_bounds(self, bounds):
bounds: Bounds
The bounding box to check
"""
assert isinstance(bounds,Bounds)
assert isinstance(bounds, Bounds)
return (bounds.rowmin >= self.rowmin
and bounds.rowmax <= self.rowmax
and bounds.colmin >= self.colmin
Expand All @@ -63,12 +62,12 @@ def intersects_bounds(self, bounds):
bounds: Bounds
The bounding box to check
"""
assert isinstance(bounds,Bounds)
assert isinstance(bounds, Bounds)

return ( not (bounds.rowmin >= self.rowmax)
return (not (bounds.rowmin >= self.rowmax)
and not (bounds.rowmax <= self.rowmin)
and not (bounds.colmin >= self.colmax)
and not (bounds.colmax <= self.colmin) )
and not (bounds.colmax <= self.colmin))

def expand_point(self, row, col):
"""
Expand Down Expand Up @@ -114,8 +113,6 @@ def expand_points(self, rows, cols):
if colmax > self.colmax:
self.colmax = colmax



def expand_bounds(self, bounds):
"""
expand the bounds to include the input Bounds
Expand All @@ -125,7 +122,7 @@ def expand_bounds(self, bounds):
bounds: Bounds
The bounding box to check
"""
assert isinstance(bounds,Bounds)
assert isinstance(bounds, Bounds)

if bounds.rowmin < self.rowmin:
self.rowmin = bounds.rowmin
Expand All @@ -138,8 +135,6 @@ def expand_bounds(self, bounds):
self.colmax = bounds.colmax

def __repr__(self):
mess="Bounds(rowmin=%g, rowmax=%g, colmin=%g, colmax=%g)"
mess = "Bounds(rowmin=%g, rowmax=%g, colmin=%g, colmax=%g)"
mess = mess % (self.rowmin, self.rowmax, self.colmin, self.colmax)
return mess


Loading

0 comments on commit 7eaf0e7

Please sign in to comment.