Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Commit

Permalink
Add some tests and infra to run them
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Aug 21, 2014
1 parent ea45949 commit 78ba716
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
12 changes: 10 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
-r requirements.txt
bumpversion
nose
nose==1.3.1
coverage==3.7.1
mock==1.0.1
scripttest==1.3
tox==1.7.0
nosexcover==1.0.8

check-manifest==0.19
pyroma==1.5
bumpversion==0.4.1
74 changes: 74 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env python

import sys

from datetime import datetime
from dateutils import relativedelta


from bosun import utils


def test_genrange_int():
assert list(utils.genrange(1, 6, 2)) == [1, 3, 5]


def test_genrange_mixed_numbers():
assert list(utils.genrange(1, 3., .5)) == [1, 1.5, 2, 2.5]


def test_genrange_datetime():
begin = datetime.strptime("2008010112", "%Y%m%d%H")
end = datetime.strptime("2008010512", "%Y%m%d%H")

interval, units = "1 day".split()
if not units.endswith('s'):
units = units + 's'
delta = relativedelta(**dict([[units, int(interval)]]))

assert (list(utils.genrange(begin, end, delta)) ==
[datetime(2008, 1, 1, 12, 0), datetime(2008, 1, 2, 12, 0),
datetime(2008, 1, 3, 12, 0), datetime(2008, 1, 4, 12, 0)])


def test_total_seconds():
period = datetime(2001, 1, 1) - datetime(2000, 1, 1)
assert utils.total_seconds(period) == 31622400


def test_calc_ETA():
assert utils.calc_ETA(4, 30, .25) == (13, 30)


def test_print_ETA():
# TODO: how to capture and check stdout?
pass


def test_hsm_full_path():
environ = {
'start': 2008012200,
'type': 'atmos',
'hsm': '/archive',
'name': 'base'
}

canonical_names = (('atmos', 'AGCM'),
('coupled', 'CGCM'),
('mom4p1_falsecoupled', 'OGCM'))

for t, n in canonical_names:
environ['type'] = t
full_path, cname = utils.hsm_full_path(environ)
assert full_path == "/archive/base/dataout/ic01/ic2008/22"
assert cname == n


def test_clear_output():
out = """
"""
cleaned = utils.clear_output(out)
assert ("HOME=" not in cleaned) is True
assert ("TRANSFER_HOME=" not in cleaned) is True
assert ("SUBMIT_HOME=" not in cleaned) is True
assert ("WORK_HOME=" not in cleaned) is True
6 changes: 6 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[tox]
envlist=py26,py27
[testenv]
deps=-r{toxinidir}/requirements-dev.txt
commands=
nosetests --with-xcoverage --cover-package=bosun --cover-tests

0 comments on commit 78ba716

Please sign in to comment.