This repository has been archived by the owner on Feb 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some tests and infra to run them
- Loading branch information
Showing
3 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |