Skip to content

Commit

Permalink
Merge pull request #131 from mistercrunch/moretests
Browse files Browse the repository at this point in the history
More tests using doctests!
  • Loading branch information
mistercrunch committed Feb 10, 2016
2 parents 7b0c045 + e039547 commit e759dfa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
20 changes: 18 additions & 2 deletions panoramix/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, date, timedelta
import functools
import hashlib
import json
Expand Down Expand Up @@ -52,6 +52,7 @@ def parse_human_datetime(s):
>>> parse_human_datetime("now") <= datetime.now()
True
>>> parse_human_datetime("yesterday") <= datetime.now()
True
>>> date.today() - timedelta(1) == parse_human_datetime('yesterday').date()
True
"""
Expand Down Expand Up @@ -118,6 +119,15 @@ def __init__(self, hash_based=False):
self.hash_based = hash_based

def get(self, s):
"""
>>> cf = ColorFactory()
>>> cf.get('item_1')
'#ff5a5f'
>>> cf.get('item_2')
'#7b0051'
>>> cf.get('item_1')
'#ff5a5f'
"""
if self.hash_based:
s = s.encode('utf-8')
h = hashlib.md5(s)
Expand Down Expand Up @@ -202,6 +212,9 @@ def wrapper(*args, **kwargs):


def datetime_f(dttm):
"""
Formats datetime to take less room is recent
"""
if dttm:
dttm = dttm.isoformat()
now_iso = datetime.now().isoformat()
Expand All @@ -215,7 +228,10 @@ def datetime_f(dttm):
def json_iso_dttm_ser(obj):
"""
json serializer that deals with dates
usage: json.dumps(object, default=utils.json_ser)
>>> dttm = datetime(1970, 1, 1)
>>> json.dumps({'dttm': dttm}, default=json_iso_dttm_ser)
'{"dttm": "1970-01-01T00:00:00"}'
"""
if isinstance(obj, datetime):
obj = obj.isoformat()
Expand Down
8 changes: 8 additions & 0 deletions tests/core_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import imp
import doctest
import os
import unittest
os.environ['PANORAMIX_CONFIG'] = 'tests.panoramix_test_config'
Expand Down Expand Up @@ -43,6 +44,13 @@ def test_dashboard(self):
for dash in db.session.query(models.Dashboard).all():
self.client.get(dash.url)

def test_doctests(self):
modules = [utils]
for mod in modules:
failed, tests = doctest.testmod(mod)
if failed:
raise Exception("Failed a doctest")

def tearDown(self):
pass

Expand Down

0 comments on commit e759dfa

Please sign in to comment.