In the past there have been some incredibly hard to debug test failures
caused by using .now() vs .utcnow(). During a routine inspection I saw
various instances of .now() being used and have replaced them.
Added a .lbox to use -cr on propose by default and set the project
to lp:charmworld.
Fixed the testdebug target to stop on failures in addition to errors.
def test_days_apart(self):
"""A single delta will get us the correct days apart."""
- delta = datetime.now() - timedelta(10)
+ delta = datetime.utcnow() - timedelta(10)
pretty = pretty_timedelta(delta) self.assertEqual('10 days', pretty)
Reviewers: mp+191291_ code.launchpad. net,
Message:
Please take a look.
Description:
Make cw code tests tz agnostic.
In the past there have been some incredibly hard to debug test failures
caused by using .now() vs .utcnow(). During a routine inspection I saw
various instances of .now() being used and have replaced them.
Added a .lbox to use -cr on propose by default and set the project
to lp:charmworld.
Fixed the testdebug target to stop on failures in addition to errors.
https:/ /code.launchpad .net/~bac/ charmworld/ utc-smackdown/ +merge/ 191291
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/14486046/
Affected files (+12, -9 lines): jobs/tests/ test_askubuntu. py jobs/tests/ test_review. py migrations/ migrate. py reports. py tests/test_ utils.py utils.py
.lbox
Makefile
[revision details]
charmworld/
charmworld/
charmworld/
charmworld/
charmworld/
charmworld/
Index: .lbox
=== added file '.lbox'
--- .lbox 1970-01-01 00:00:00 +0000
+++ .lbox 2013-10-15 20:26:51 +0000
@@ -0,0 +1,1 @@
+propose -cr -for lp:charmworld
Index: Makefile
=== modified file 'Makefile'
--- Makefile 2013-10-15 17:55:59 +0000
+++ Makefile 2013-10-15 20:04:46 +0000
@@ -122,7 +122,7 @@
bin/test -v -s -x --with-id $(ID) charmworld
testdebug: bin/test
- bin/test --pdb charmworld
+ bin/test --pdb --pdb-failures charmworld
check: clear_ini clean sysdeps install lint testid
Index: [revision details] 20131015180445- lmxsdrtp2xjl0ec 3
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-
+New revision: <email address hidden>
Index: charmworld/ reports. py reports. py' reports. py 2013-08-08 12:05:02 +0000 reports. py 2013-10-15 20:04:46 +0000
self. _start_ date = start_date datetime. now() datetime. utcnow( )
self. _end_date = end_date
self. _step = step
self. _series = {}
=== modified file 'charmworld/
--- charmworld/
+++ charmworld/
@@ -34,7 +34,7 @@
def __init__(self, start_date, step, end_date=None):
if end_date is None:
- end_date = datetime.
+ end_date = datetime.
Index: charmworld/ migrations/ migrate. py migrations/ migrate. py' migrations/ migrate. py 2013-08-28 20:19:02 +0000 migrations/ migrate. py 2013-10-15 20:04:46 +0000
self. db.migration_ version. save({
'_id': 'version',
'version' : version,
=== modified file 'charmworld/
--- charmworld/
+++ charmworld/
@@ -98,7 +98,7 @@
- 'date': datetime.now(),
+ 'date': datetime.utcnow(),
})
def version_ datastore( self):
self. db.migration_ version. insert( {
'_id': 'version',
'version' : 0,
@@ -114,7 +114,7 @@
- 'date': datetime.now(),
+ 'date': datetime.utcnow(),
})
Index: charmworld/ jobs/tests/ test_askubuntu. py jobs/tests/ test_askubuntu. py' jobs/tests/ test_askubuntu. py 2013-09-27 16:13:21 +0000 jobs/tests/ test_askubuntu. py 2013-10-15 20:04:46 +0000
self. assertEqual( [], entries)
=== modified file 'charmworld/
--- charmworld/
+++ charmworld/
@@ -48,7 +48,7 @@
def test_create_ entries_ from_questions( self): datetime. now() datetime. utcnow( ) timedelta( 1)
"question_ id":345535,
"reputation ":13,
"user_ type":" registered" ,
"profile_ image": "https:/ /example. com/foo. jpg", askubuntu. com/users/ 130026/ jjmerelo" askubuntu. com/users/ 130026/ jjmerelo",
"link": "http:// example. com/questions/ 1/",
"is_answered" : False
- now = datetime.
+ now = datetime.
then = now - datetime.
questions = [{
@@ -67,7 +67,7 @@
- "link":"http://
+ "link":"http://
},
Index: charmworld/ jobs/tests/ test_review. py jobs/tests/ test_review. py' jobs/tests/ test_review. py 2013-09-30 16:00:47 +0000 jobs/tests/ test_review. py 2013-10-15 20:04:46 +0000
=== modified file 'charmworld/
--- charmworld/
+++ charmworld/
@@ -7,7 +7,7 @@
from charmworld.testing import MongoTestBase
-NOW = datetime. datetime. now() datetime. utcnow( ) timedelta( 1) timedelta( 2)
+NOW = datetime.
YESTERDAY = NOW - datetime.
TWO_DAYS = NOW - datetime.
Index: charmworld/ tests/test_ utils.py tests/test_ utils.py' tests/test_ utils.py 2013-09-10 13:54:39 +0000 tests/test_ utils.py 2013-10-15 20:04:46 +0000
=== modified file 'charmworld/
--- charmworld/
+++ charmworld/
@@ -53,7 +53,7 @@
def test_days_ apart(self) : timedelta( delta)
self. assertEqual( '10 days', pretty)
"""A single delta will get us the correct days apart."""
- delta = datetime.now() - timedelta(10)
+ delta = datetime.utcnow() - timedelta(10)
pretty = pretty_
Index: charmworld/utils.py utils.py' datetime. now() datetime. utcnow( )
=== modified file 'charmworld/
--- charmworld/utils.py 2013-09-10 13:54:39 +0000
+++ charmworld/utils.py 2013-10-15 20:04:46 +0000
@@ -50,7 +50,7 @@
if isinstance(time1, (str, unicode)):
time1 = parse(time1)
if time2 is None:
- time2 = datetime.
+ time2 = datetime.
if time1 > time2:
raise ValueError('The start date is before the end date.')