Skip to content
This repository has been archived by the owner on Jan 25, 2019. It is now read-only.

Commit

Permalink
Make tests work again, fix Author test, make tests for wok.util.date_…
Browse files Browse the repository at this point in the history
…and_times.
  • Loading branch information
mythmon committed Oct 12, 2011
1 parent 6cde6e9 commit 8264743
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 4 deletions.
Empty file added wok/tests/__init__.py
Empty file.
8 changes: 4 additions & 4 deletions wok/tests/test_page.py
Expand Up @@ -3,20 +3,20 @@
except ImportError:
from unittest import TestCase

from wok.page import Page
from wok.page import Author

class TestAuthor(TestCase):

def test_author(self):
a = Page.Author.parse('Bob Smith')
a = Author.parse('Bob Smith')
self.assertEqual(a.raw, 'Bob Smith')
self.assertEqual(a.name, 'Bob Smith')

a = Page.Author.parse('Bob Smith <bob@here.com>')
a = Author.parse('Bob Smith <bob@here.com>')
self.assertEqual(a.raw, 'Bob Smith <bob@here.com>')
self.assertEqual(a.name, 'Bob Smith')
self.assertEqual(a.email, 'bob@here.com')

a = Page.Author.parse('<bob@here.com>')
a = Author.parse('<bob@here.com>')
self.assertEqual(a.raw, '<bob@here.com>')
self.assertEqual(a.email, 'bob@here.com')
96 changes: 96 additions & 0 deletions wok/tests/test_util.py
Expand Up @@ -3,6 +3,8 @@
except ImportError:
from unittest import TestCase

from datetime import date, time, datetime, tzinfo

from wok import util

class TestSlugs(TestCase):
Expand Down Expand Up @@ -42,3 +44,97 @@ def test_apostrophes(self):
self.assertEqual(slug, util.slugify(orig))

test_apostrophes.todo = "Apostrophes are treated like normal words right now"

class TestDatetimes(TestCase):

def setUp(self):
"""
The date used is February 3rd, 2011 at 00:23 in the morning.
The datetime is the first commit of wok.
The date is the day this test was first written.
The time is pi second, in GMT-8.
"""
self.datetime = datetime(2011, 2, 3, 0, 23, 0, 0)
self.date = date(2011, 10, 12)
self.time = time(3, 14, 15, 0)

def test_blanks(self):
inp = {}
out = {'datetime': None, 'date': None, 'time': None, }

util.date_and_times(inp)
self.assertEquals(inp, out)

def test_just_date(self):
inp = {'date': self.date}
out = {
'datetime': datetime(2011, 10, 12, 0, 0, 0, 0),
'date': self.date,
'time': None,
}

util.date_and_times(inp)
self.assertEquals(inp, out)

def test_just_time(self):
inp = {'time': self.time}
out = {'datetime': None, 'date': None, 'time': self.time, }

util.date_and_times(inp)
self.assertEquals(inp, out)

def test_date_and_times(self):
inp = {'date': self.date, 'time': self.time}
out = {
'datetime': datetime(2011, 10, 12, 3, 14, 15, 0),
'date': self.date,
'time': self.time,
}

util.date_and_times(inp)
self.assertEquals(inp, out)

def test_just_datetime(self):
inp = {'datetime': self.datetime}
out = {
'datetime': self.datetime,
'date': self.datetime.date(),
'time': self.datetime.time(),
}

util.date_and_times(inp)
self.assertEquals(inp, out)

def test_datetime_and_date(self):
inp = {'datetime': self.datetime, 'date': self.date}
out = {
'datetime': datetime(2011, 10, 12, 0, 23, 0, 0),
'date': self.date,
'time': self.datetime.time(),
}

util.date_and_times(inp)
self.assertEquals(inp, out)

def test_datetime_and_time(self):
inp = {'datetime': self.datetime, 'time': self.time}
out = {
'datetime': datetime(2011, 2, 3, 3, 14, 15, 0),
'date': self.datetime.date(),
'time': self.time,
}

util.date_and_times(inp)
self.assertEquals(inp, out)

def test_all(self):
inp = {'datetime': self.datetime, 'date': self.date, 'time': self.time}
out = {
'datetime': datetime(2011, 10, 12, 3, 14, 15, 0),
'date': self.date,
'time': self.time,
}

util.date_and_times(inp)
self.assertEquals(inp, out)

0 comments on commit 8264743

Please sign in to comment.