Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More tests using doctests! #131

Merged
merged 1 commit into from
Feb 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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