From 3f60faf6f6969b23206b9ee19a46986d1fbd823b Mon Sep 17 00:00:00 2001 From: James Rowe Date: Wed, 16 May 2012 19:34:48 +0100 Subject: [PATCH 01/10] Use nose.tools.eq_ instead of assert_equals. --- tests/test_charset_header.py | 6 +- tests/test_commits.py | 62 +++---- tests/test_date_handling.py | 258 ++++++++++++-------------- tests/test_issues.py | 72 ++++---- tests/test_organizations.py | 52 +++--- tests/test_pull_requests.py | 69 ++++--- tests/test_regression.py | 8 +- tests/test_repositories.py | 103 +++++------ tests/test_teams.py | 4 +- tests/test_tz_aware_date_handling.py | 266 +++++++++++++-------------- tests/test_unit.py | 30 +-- tests/test_user.py | 59 +++--- 12 files changed, 473 insertions(+), 516 deletions(-) diff --git a/tests/test_charset_header.py b/tests/test_charset_header.py index 3b29635..2786673 100644 --- a/tests/test_charset_header.py +++ b/tests/test_charset_header.py @@ -3,16 +3,16 @@ # This file is part of python-github2, and is made available under the 3-clause # BSD license. See LICENSE for the full details. -from nose.tools import assert_equals +from nose.tools import eq_ from github2.request import charset_from_headers def no_match_test(): d = {} - assert_equals("ascii", charset_from_headers(d)) + eq_("ascii", charset_from_headers(d)) def utf_test(): d = {'content-type': 'application/json; charset=utf-8'} - assert_equals("utf-8", charset_from_headers(d)) + eq_("utf-8", charset_from_headers(d)) diff --git a/tests/test_commits.py b/tests/test_commits.py index 20ed487..33f037c 100644 --- a/tests/test_commits.py +++ b/tests/test_commits.py @@ -5,7 +5,7 @@ from datetime import datetime -from nose.tools import assert_equals +from nose.tools import eq_ import utils @@ -16,28 +16,25 @@ class CommitProperties(utils.HttpMockTestCase): def test_commit(self): commit = self.client.commits.show('ask/python-github2', self.commit_id) - assert_equals(commit.message, - 'Added cache support to manage_collaborators.') - assert_equals(commit.parents, - [{"id": '7d1c855d2f44a55e4b90b40017be697cf70cb4a0'}]) - assert_equals(commit.url, - '/ask/python-github2/commit/%s' % self.commit_id) - assert_equals(commit.author['login'], 'JNRowe') - assert_equals(commit.id, self.commit_id) - assert_equals(commit.committed_date, - datetime(2011, 6, 6, 16, 13, 50)) - assert_equals(commit.authored_date, datetime(2011, 6, 6, 16, 13, 50)) - assert_equals(commit.tree, 'f48fcc1a0b8ea97f3147dc42cf7cdb6683493e94') - assert_equals(commit.committer['login'], 'JNRowe') - assert_equals(commit.added, None) - assert_equals(commit.removed, None) - assert_equals(commit.modified[0]['filename'], - 'github2/bin/manage_collaborators.py') + eq_(commit.message, 'Added cache support to manage_collaborators.') + eq_(commit.parents, + [{"id": '7d1c855d2f44a55e4b90b40017be697cf70cb4a0'}]) + eq_(commit.url, '/ask/python-github2/commit/%s' % self.commit_id) + eq_(commit.author['login'], 'JNRowe') + eq_(commit.id, self.commit_id) + eq_(commit.committed_date, datetime(2011, 6, 6, 16, 13, 50)) + eq_(commit.authored_date, datetime(2011, 6, 6, 16, 13, 50)) + eq_(commit.tree, 'f48fcc1a0b8ea97f3147dc42cf7cdb6683493e94') + eq_(commit.committer['login'], 'JNRowe') + eq_(commit.added, None) + eq_(commit.removed, None) + eq_(commit.modified[0]['filename'], + 'github2/bin/manage_collaborators.py') def test_repr(self): commit = self.client.commits.show('ask/python-github2', self.commit_id) - assert_equals(repr(commit), - '' % self.commit_id[:8]) + eq_(repr(commit), + '' % self.commit_id[:8]) class CommitsQueries(utils.HttpMockTestCase): @@ -45,32 +42,27 @@ class CommitsQueries(utils.HttpMockTestCase): def test_list(self): commits = self.client.commits.list('JNRowe/misc-overlay') - assert_equals(len(commits), 35) - assert_equals(commits[0].id, - '4de0834d58b37ef3020c49df43c95649217a2def') + eq_(len(commits), 35) + eq_(commits[0].id, '4de0834d58b37ef3020c49df43c95649217a2def') def test_list_with_page(self): commits = self.client.commits.list('JNRowe/jnrowe-misc', page=2) - assert_equals(len(commits), 35) - assert_equals(commits[0].id, - '1f5ad2c3206bafc4aca9e6ce50f5c605befdb3d6') + eq_(len(commits), 35) + eq_(commits[0].id, '1f5ad2c3206bafc4aca9e6ce50f5c605befdb3d6') def test_list_with_branch(self): commits = self.client.commits.list('JNRowe/misc-overlay', 'gh-pages') - assert_equals(len(commits), 35) - assert_equals(commits[0].id, - '025148bdaa6fb6bdac9c3522d481fadf1c0a456f') + eq_(len(commits), 35) + eq_(commits[0].id, '025148bdaa6fb6bdac9c3522d481fadf1c0a456f') def test_list_with_file(self): commits = self.client.commits.list('JNRowe/misc-overlay', file='Makefile') - assert_equals(len(commits), 35) - assert_equals(commits[0].id, - 'fc12b924d34dc38c8ce76d27a866221faa88cb72') + eq_(len(commits), 35) + eq_(commits[0].id, 'fc12b924d34dc38c8ce76d27a866221faa88cb72') def test_list_with_branch_and_file(self): commits = self.client.commits.list('JNRowe/misc-overlay', 'gh-pages', 'packages/dev-python.html') - assert_equals(len(commits), 35) - assert_equals(commits[0].id, - '025148bdaa6fb6bdac9c3522d481fadf1c0a456f') + eq_(len(commits), 35) + eq_(commits[0].id, '025148bdaa6fb6bdac9c3522d481fadf1c0a456f') diff --git a/tests/test_date_handling.py b/tests/test_date_handling.py index 855ccae..b696a74 100644 --- a/tests/test_date_handling.py +++ b/tests/test_date_handling.py @@ -6,7 +6,7 @@ from datetime import datetime as dt -from nose.tools import assert_equals +from nose.tools import eq_ from github2.core import (datetime_to_ghdate, datetime_to_commitdate, datetime_to_isodate, string_to_datetime) @@ -16,154 +16,138 @@ # naïve datetime objects used in the current code base def test_ghdate_to_datetime(): - assert_equals(string_to_datetime('2011/05/22 00:24:15 -0700'), - dt(2011, 5, 22, 0, 24, 15)) - - assert_equals(string_to_datetime('2009/04/18 13:04:09 -0700'), - dt(2009, 4, 18, 13, 4, 9)) - #assert_equals(string_to_datetime('2009/11/12 21:15:17 -0800'), - # dt(2009, 11, 12, 21, 15, 17)) - #assert_equals(string_to_datetime('2009/11/12 21:16:20 -0800'), - # dt(2009, 11, 12, 21, 16, 20)) - assert_equals(string_to_datetime('2010/04/17 17:24:29 -0700'), - dt(2010, 4, 17, 17, 24, 29)) - assert_equals(string_to_datetime('2010/05/18 06:10:36 -0700'), - dt(2010, 5, 18, 6, 10, 36)) - assert_equals(string_to_datetime('2010/05/25 21:59:37 -0700'), - dt(2010, 5, 25, 21, 59, 37)) - assert_equals(string_to_datetime('2010/05/26 17:08:41 -0700'), - dt(2010, 5, 26, 17, 8, 41)) - assert_equals(string_to_datetime('2010/06/20 06:13:37 -0700'), - dt(2010, 6, 20, 6, 13, 37)) - assert_equals(string_to_datetime('2010/07/28 12:56:51 -0700'), - dt(2010, 7, 28, 12, 56, 51)) - assert_equals(string_to_datetime('2010/09/20 21:32:49 -0700'), - dt(2010, 9, 20, 21, 32, 49)) + eq_(string_to_datetime('2011/05/22 00:24:15 -0700'), + dt(2011, 5, 22, 0, 24, 15)) + + eq_(string_to_datetime('2009/04/18 13:04:09 -0700'), + dt(2009, 4, 18, 13, 4, 9)) + #eq_(string_to_datetime('2009/11/12 21:15:17 -0800'), + # dt(2009, 11, 12, 21, 15, 17)) + #eq_(string_to_datetime('2009/11/12 21:16:20 -0800'), + # dt(2009, 11, 12, 21, 16, 20)) + eq_(string_to_datetime('2010/04/17 17:24:29 -0700'), + dt(2010, 4, 17, 17, 24, 29)) + eq_(string_to_datetime('2010/05/18 06:10:36 -0700'), + dt(2010, 5, 18, 6, 10, 36)) + eq_(string_to_datetime('2010/05/25 21:59:37 -0700'), + dt(2010, 5, 25, 21, 59, 37)) + eq_(string_to_datetime('2010/05/26 17:08:41 -0700'), + dt(2010, 5, 26, 17, 8, 41)) + eq_(string_to_datetime('2010/06/20 06:13:37 -0700'), + dt(2010, 6, 20, 6, 13, 37)) + eq_(string_to_datetime('2010/07/28 12:56:51 -0700'), + dt(2010, 7, 28, 12, 56, 51)) + eq_(string_to_datetime('2010/09/20 21:32:49 -0700'), + dt(2010, 9, 20, 21, 32, 49)) def test_datetime_to_ghdate(): - assert_equals(datetime_to_ghdate(dt(2011, 5, 22, 0, 24, 15)), - '2011/05/22 00:24:15 -0700') - - assert_equals(datetime_to_ghdate(dt(2009, 4, 18, 20, 4, 9)), - '2009/04/18 20:04:09 -0700') - #assert_equals(datetime_to_ghdate(dt(2009, 11, 13, 4, 15, 17)), - # '2009/11/13 04:15:17 -0800') - #assert_equals(datetime_to_ghdate(dt(2009, 11, 13, 4, 16, 20)), - # '2009/11/13 04:16:20 -0800') - assert_equals(datetime_to_ghdate(dt(2010, 4, 18, 0, 24, 29)), - '2010/04/18 00:24:29 -0700') - assert_equals(datetime_to_ghdate(dt(2010, 5, 18, 13, 10, 36)), - '2010/05/18 13:10:36 -0700') - assert_equals(datetime_to_ghdate(dt(2010, 5, 26, 5, 59, 37)), - '2010/05/26 05:59:37 -0700') - assert_equals(datetime_to_ghdate(dt(2010, 5, 27, 0, 8, 41)), - '2010/05/27 00:08:41 -0700') - assert_equals(datetime_to_ghdate(dt(2010, 6, 20, 13, 13, 37)), - '2010/06/20 13:13:37 -0700') - assert_equals(datetime_to_ghdate(dt(2010, 7, 28, 19, 56, 51)), - '2010/07/28 19:56:51 -0700') - assert_equals(datetime_to_ghdate(dt(2010, 9, 21, 4, 32, 49)), - '2010/09/21 04:32:49 -0700') + eq_(datetime_to_ghdate(dt(2011, 5, 22, 0, 24, 15)), + '2011/05/22 00:24:15 -0700') + + eq_(datetime_to_ghdate(dt(2009, 4, 18, 20, 4, 9)), + '2009/04/18 20:04:09 -0700') + #eq_(datetime_to_ghdate(dt(2009, 11, 13, 4, 15, 17)), + # '2009/11/13 04:15:17 -0800') + #eq_(datetime_to_ghdate(dt(2009, 11, 13, 4, 16, 20)), + # '2009/11/13 04:16:20 -0800') + eq_(datetime_to_ghdate(dt(2010, 4, 18, 0, 24, 29)), + '2010/04/18 00:24:29 -0700') + eq_(datetime_to_ghdate(dt(2010, 5, 18, 13, 10, 36)), + '2010/05/18 13:10:36 -0700') + eq_(datetime_to_ghdate(dt(2010, 5, 26, 5, 59, 37)), + '2010/05/26 05:59:37 -0700') + eq_(datetime_to_ghdate(dt(2010, 5, 27, 0, 8, 41)), + '2010/05/27 00:08:41 -0700') + eq_(datetime_to_ghdate(dt(2010, 6, 20, 13, 13, 37)), + '2010/06/20 13:13:37 -0700') + eq_(datetime_to_ghdate(dt(2010, 7, 28, 19, 56, 51)), + '2010/07/28 19:56:51 -0700') + eq_(datetime_to_ghdate(dt(2010, 9, 21, 4, 32, 49)), + '2010/09/21 04:32:49 -0700') def test_commitdate_to_datetime(): - assert_equals(string_to_datetime('2011-05-22T00:24:15-07:00'), - dt(2011, 5, 22, 0, 24, 15)) - - assert_equals(string_to_datetime('2011-04-09T10:07:30-07:00'), - dt(2011, 4, 9, 10, 7, 30)) - #assert_equals(string_to_datetime('2011-02-19T07:16:11-08:00'), - # dt(2011, 2, 19, 7, 16, 11)) - #assert_equals(string_to_datetime('2010-12-21T12:34:27-08:00'), - # dt(2010, 12, 21, 12, 34, 27)) - assert_equals(string_to_datetime('2011-04-09T10:20:05-07:00'), - dt(2011, 4, 9, 10, 20, 5)) - assert_equals(string_to_datetime('2011-04-09T10:05:58-07:00'), - dt(2011, 4, 9, 10, 5, 58)) - assert_equals(string_to_datetime('2011-04-09T09:53:00-07:00'), - dt(2011, 4, 9, 9, 53, 0)) - assert_equals(string_to_datetime('2011-04-09T10:00:21-07:00'), - dt(2011, 4, 9, 10, 0, 21)) - #assert_equals(string_to_datetime('2010-12-16T15:10:59-08:00'), - # dt(2010, 12, 16, 15, 10, 59)) - assert_equals(string_to_datetime('2011-04-09T09:53:00-07:00'), - dt(2011, 4, 9, 9, 53, 0)) - assert_equals(string_to_datetime('2011-04-09T09:53:00-07:00'), - dt(2011, 4, 9, 9, 53, 0)) + eq_(string_to_datetime('2011-05-22T00:24:15-07:00'), + dt(2011, 5, 22, 0, 24, 15)) + + eq_(string_to_datetime('2011-04-09T10:07:30-07:00'), + dt(2011, 4, 9, 10, 7, 30)) + #eq_(string_to_datetime('2011-02-19T07:16:11-08:00'), + # dt(2011, 2, 19, 7, 16, 11)) + #eq_(string_to_datetime('2010-12-21T12:34:27-08:00'), + # dt(2010, 12, 21, 12, 34, 27)) + eq_(string_to_datetime('2011-04-09T10:20:05-07:00'), + dt(2011, 4, 9, 10, 20, 5)) + eq_(string_to_datetime('2011-04-09T10:05:58-07:00'), + dt(2011, 4, 9, 10, 5, 58)) + eq_(string_to_datetime('2011-04-09T09:53:00-07:00'), + dt(2011, 4, 9, 9, 53, 0)) + eq_(string_to_datetime('2011-04-09T10:00:21-07:00'), + dt(2011, 4, 9, 10, 0, 21)) + #eq_(string_to_datetime('2010-12-16T15:10:59-08:00'), + # dt(2010, 12, 16, 15, 10, 59)) + eq_(string_to_datetime('2011-04-09T09:53:00-07:00'), + dt(2011, 4, 9, 9, 53, 0)) + eq_(string_to_datetime('2011-04-09T09:53:00-07:00'), + dt(2011, 4, 9, 9, 53, 0)) def test_datetime_to_commitdate(): - assert_equals(datetime_to_commitdate(dt(2011, 5, 22, 0, 24, 15)), - '2011-05-22T00:24:15-07:00') - - assert_equals(datetime_to_commitdate(dt(2011, 4, 9, 10, 7, 30)), - '2011-04-09T10:07:30-07:00') - #assert_equals(datetime_to_commitdate(dt(2011, 2, 19, 7, 16, 11)), - # '2011-02-19T07:16:11-08:00') - #assert_equals(datetime_to_commitdate(dt(2010, 12, 21, 12, 34, 27)), - # '2010-12-21T12:34:27-08:00') - assert_equals(datetime_to_commitdate(dt(2011, 4, 9, 10, 20, 5)), - '2011-04-09T10:20:05-07:00') - assert_equals(datetime_to_commitdate(dt(2011, 4, 9, 10, 5, 58)), - '2011-04-09T10:05:58-07:00') - assert_equals(datetime_to_commitdate(dt(2011, 4, 9, 9, 53, 0)), - '2011-04-09T09:53:00-07:00') - assert_equals(datetime_to_commitdate(dt(2011, 4, 9, 10, 0, 21)), - '2011-04-09T10:00:21-07:00') - #assert_equals(datetime_to_commitdate(dt(2010, 12, 16, 15, 10, 59)), - # '2010-12-16T15:10:59-08:00') - assert_equals(datetime_to_commitdate(dt(2011, 4, 9, 9, 53, 0)), - '2011-04-09T09:53:00-07:00') - assert_equals(datetime_to_commitdate(dt(2011, 4, 9, 9, 53, 0)), - '2011-04-09T09:53:00-07:00') + eq_(datetime_to_commitdate(dt(2011, 5, 22, 0, 24, 15)), + '2011-05-22T00:24:15-07:00') + + eq_(datetime_to_commitdate(dt(2011, 4, 9, 10, 7, 30)), + '2011-04-09T10:07:30-07:00') + #eq_(datetime_to_commitdate(dt(2011, 2, 19, 7, 16, 11)), + # '2011-02-19T07:16:11-08:00') + #eq_(datetime_to_commitdate(dt(2010, 12, 21, 12, 34, 27)), + # '2010-12-21T12:34:27-08:00') + eq_(datetime_to_commitdate(dt(2011, 4, 9, 10, 20, 5)), + '2011-04-09T10:20:05-07:00') + eq_(datetime_to_commitdate(dt(2011, 4, 9, 10, 5, 58)), + '2011-04-09T10:05:58-07:00') + eq_(datetime_to_commitdate(dt(2011, 4, 9, 9, 53, 0)), + '2011-04-09T09:53:00-07:00') + eq_(datetime_to_commitdate(dt(2011, 4, 9, 10, 0, 21)), + '2011-04-09T10:00:21-07:00') + #eq_(datetime_to_commitdate(dt(2010, 12, 16, 15, 10, 59)), + # '2010-12-16T15:10:59-08:00') + eq_(datetime_to_commitdate(dt(2011, 4, 9, 9, 53, 0)), + '2011-04-09T09:53:00-07:00') + eq_(datetime_to_commitdate(dt(2011, 4, 9, 9, 53, 0)), + '2011-04-09T09:53:00-07:00') def test_isodate_to_datetime(): - assert_equals(string_to_datetime('2011-05-22T00:24:15Z'), - dt(2011, 5, 22, 0, 24, 15)) - assert_equals(string_to_datetime('2011-04-09T10:07:30Z'), - dt(2011, 4, 9, 10, 7, 30)) - assert_equals(string_to_datetime('2011-02-19T07:16:11Z'), - dt(2011, 2, 19, 7, 16, 11)) - assert_equals(string_to_datetime('2010-12-21T12:34:27Z'), - dt(2010, 12, 21, 12, 34, 27)) - assert_equals(string_to_datetime('2011-04-09T10:20:05Z'), - dt(2011, 4, 9, 10, 20, 5)) - assert_equals(string_to_datetime('2011-04-09T10:05:58Z'), - dt(2011, 4, 9, 10, 5, 58)) - assert_equals(string_to_datetime('2011-04-09T09:53:00Z'), - dt(2011, 4, 9, 9, 53, 0)) - assert_equals(string_to_datetime('2011-04-09T10:00:21Z'), - dt(2011, 4, 9, 10, 0, 21)) - assert_equals(string_to_datetime('2010-12-16T15:10:59Z'), - dt(2010, 12, 16, 15, 10, 59)) - assert_equals(string_to_datetime('2011-04-09T09:53:00Z'), - dt(2011, 4, 9, 9, 53, 0)) - assert_equals(string_to_datetime('2011-04-09T09:53:00Z'), - dt(2011, 4, 9, 9, 53, 0)) + eq_(string_to_datetime('2011-05-22T00:24:15Z'), dt(2011, 5, 22, 0, 24, 15)) + eq_(string_to_datetime('2011-04-09T10:07:30Z'), dt(2011, 4, 9, 10, 7, 30)) + eq_(string_to_datetime('2011-02-19T07:16:11Z'), dt(2011, 2, 19, 7, 16, 11)) + eq_(string_to_datetime('2010-12-21T12:34:27Z'), + dt(2010, 12, 21, 12, 34, 27)) + eq_(string_to_datetime('2011-04-09T10:20:05Z'), dt(2011, 4, 9, 10, 20, 5)) + eq_(string_to_datetime('2011-04-09T10:05:58Z'), dt(2011, 4, 9, 10, 5, 58)) + eq_(string_to_datetime('2011-04-09T09:53:00Z'), dt(2011, 4, 9, 9, 53, 0)) + eq_(string_to_datetime('2011-04-09T10:00:21Z'), dt(2011, 4, 9, 10, 0, 21)) + eq_(string_to_datetime('2010-12-16T15:10:59Z'), + dt(2010, 12, 16, 15, 10, 59)) + eq_(string_to_datetime('2011-04-09T09:53:00Z'), dt(2011, 4, 9, 9, 53, 0)) + eq_(string_to_datetime('2011-04-09T09:53:00Z'), dt(2011, 4, 9, 9, 53, 0)) def test_datetime_to_isodate(): - assert_equals(datetime_to_isodate(dt(2011, 5, 22, 0, 24, 15)), - '2011-05-22T00:24:15Z') - assert_equals(datetime_to_isodate(dt(2011, 4, 9, 10, 7, 30)), - '2011-04-09T10:07:30Z') - assert_equals(datetime_to_isodate(dt(2011, 2, 19, 7, 16, 11)), - '2011-02-19T07:16:11Z') - assert_equals(datetime_to_isodate(dt(2010, 12, 21, 12, 34, 27)), - '2010-12-21T12:34:27Z') - assert_equals(datetime_to_isodate(dt(2011, 4, 9, 10, 20, 5)), - '2011-04-09T10:20:05Z') - assert_equals(datetime_to_isodate(dt(2011, 4, 9, 10, 5, 58)), - '2011-04-09T10:05:58Z') - assert_equals(datetime_to_isodate(dt(2011, 4, 9, 9, 53, 0)), - '2011-04-09T09:53:00Z') - assert_equals(datetime_to_isodate(dt(2011, 4, 9, 10, 0, 21)), - '2011-04-09T10:00:21Z') - assert_equals(datetime_to_isodate(dt(2010, 12, 16, 15, 10, 59)), - '2010-12-16T15:10:59Z') - assert_equals(datetime_to_isodate(dt(2011, 4, 9, 9, 53, 0)), - '2011-04-09T09:53:00Z') - assert_equals(datetime_to_isodate(dt(2011, 4, 9, 9, 53, 0)), - '2011-04-09T09:53:00Z') + eq_(datetime_to_isodate(dt(2011, 5, 22, 0, 24, 15)), + '2011-05-22T00:24:15Z') + eq_(datetime_to_isodate(dt(2011, 4, 9, 10, 7, 30)), '2011-04-09T10:07:30Z') + eq_(datetime_to_isodate(dt(2011, 2, 19, 7, 16, 11)), + '2011-02-19T07:16:11Z') + eq_(datetime_to_isodate(dt(2010, 12, 21, 12, 34, 27)), + '2010-12-21T12:34:27Z') + eq_(datetime_to_isodate(dt(2011, 4, 9, 10, 20, 5)), '2011-04-09T10:20:05Z') + eq_(datetime_to_isodate(dt(2011, 4, 9, 10, 5, 58)), '2011-04-09T10:05:58Z') + eq_(datetime_to_isodate(dt(2011, 4, 9, 9, 53, 0)), '2011-04-09T09:53:00Z') + eq_(datetime_to_isodate(dt(2011, 4, 9, 10, 0, 21)), '2011-04-09T10:00:21Z') + eq_(datetime_to_isodate(dt(2010, 12, 16, 15, 10, 59)), + '2010-12-16T15:10:59Z') + eq_(datetime_to_isodate(dt(2011, 4, 9, 9, 53, 0)), '2011-04-09T09:53:00Z') + eq_(datetime_to_isodate(dt(2011, 4, 9, 9, 53, 0)), '2011-04-09T09:53:00Z') diff --git a/tests/test_issues.py b/tests/test_issues.py index f82302b..2abf495 100644 --- a/tests/test_issues.py +++ b/tests/test_issues.py @@ -5,7 +5,7 @@ from datetime import datetime -from nose.tools import assert_equals +from nose.tools import eq_ import utils @@ -13,44 +13,42 @@ class Issue(utils.HttpMockTestCase): def test_properties(self): issue = self.client.issues.show('ask/python-github2', 24) - assert_equals(issue.position, 24.0) - assert_equals(issue.number, 24) - assert_equals(issue.votes, 0) - assert_equals(len(issue.body), 164) - assert_equals(issue.title, 'Pagination support for commits.') - assert_equals(issue.user, 'svetlyak40wt') - assert_equals(issue.state, 'open') - assert_equals(issue.labels, []) - assert_equals(issue.created_at, datetime(2010, 12, 8, 23, 50, 26)) - assert_equals(issue.closed_at, None) - assert_equals(issue.updated_at, datetime(2011, 1, 4, 16, 26, 7)) - assert_equals(issue.diff_url, - 'https://github.com/ask/python-github2/pull/24.diff') - assert_equals(issue.patch_url, - 'https://github.com/ask/python-github2/pull/24.patch') - assert_equals(issue.pull_request_url, - 'https://github.com/ask/python-github2/pull/24') + eq_(issue.position, 24.0) + eq_(issue.number, 24) + eq_(issue.votes, 0) + eq_(len(issue.body), 164) + eq_(issue.title, 'Pagination support for commits.') + eq_(issue.user, 'svetlyak40wt') + eq_(issue.state, 'open') + eq_(issue.labels, []) + eq_(issue.created_at, datetime(2010, 12, 8, 23, 50, 26)) + eq_(issue.closed_at, None) + eq_(issue.updated_at, datetime(2011, 1, 4, 16, 26, 7)) + eq_(issue.diff_url, + 'https://github.com/ask/python-github2/pull/24.diff') + eq_(issue.patch_url, + 'https://github.com/ask/python-github2/pull/24.patch') + eq_(issue.pull_request_url, + 'https://github.com/ask/python-github2/pull/24') def test_issue_repr(self): issue = self.client.issues.show('ask/python-github2', 24) - assert_equals(repr(issue), - '') + eq_(repr(issue), '') class Comment(utils.HttpMockTestCase): def test_properties(self): comments = self.client.issues.comments('ask/python-github2', 24) comment = comments[0] - assert_equals(comment.created_at, datetime(2010, 12, 9, 22, 37, 26)) - assert_equals(comment.updated_at, datetime(2010, 12, 9, 22, 37, 26)) - assert_equals(len(comment.body), 267) - assert_equals(comment.id, 601871) - assert_equals(comment.user, 'nvie') + eq_(comment.created_at, datetime(2010, 12, 9, 22, 37, 26)) + eq_(comment.updated_at, datetime(2010, 12, 9, 22, 37, 26)) + eq_(len(comment.body), 267) + eq_(comment.id, 601871) + eq_(comment.user, 'nvie') def test_comment_repr(self): comments = self.client.issues.comments('ask/python-github2', 24) - assert_equals(repr(comments[1]), - '') + eq_(repr(comments[1]), '') class IssueQueries(utils.HttpMockTestCase): @@ -58,25 +56,25 @@ class IssueQueries(utils.HttpMockTestCase): def test_search(self): issues = self.client.issues.search('ask/python-github2', 'timezone', 'closed') - assert_equals(len(issues), 2) - assert_equals(issues[1].number, 39) + eq_(len(issues), 2) + eq_(issues[1].number, 39) def test_list(self): issues = self.client.issues.list('ask/python-github2') - assert_equals(len(issues), 4) - assert_equals(issues[-1].number, 58) + eq_(len(issues), 4) + eq_(issues[-1].number, 58) def test_list_with_state(self): issues = self.client.issues.list('ask/python-github2', "closed") - assert_equals(len(issues), 55) - assert_equals(issues[0].number, 59) + eq_(len(issues), 55) + eq_(issues[0].number, 59) def test_issue_labels(self): labels = self.client.issues.list_labels('JNRowe/misc-overlay') - assert_equals(len(labels), 4) - assert_equals(labels[0], 'feature') + eq_(len(labels), 4) + eq_(labels[0], 'feature') def test_list_by_label(self): issues = self.client.issues.list_by_label('JNRowe/misc-overlay', 'bug') - assert_equals(len(issues), 30) - assert_equals(issues[-1].number, 328) + eq_(len(issues), 30) + eq_(issues[-1].number, 328) diff --git a/tests/test_organizations.py b/tests/test_organizations.py index 8571e23..399d450 100644 --- a/tests/test_organizations.py +++ b/tests/test_organizations.py @@ -5,7 +5,7 @@ from datetime import datetime -from nose.tools import (assert_equals, assert_true) +from nose.tools import (eq_, assert_true) import utils @@ -13,23 +13,21 @@ class OrganizationProperties(utils.HttpMockTestCase): def test_properties(self): organization = self.client.organizations.show('github') - assert_equals(organization.id, 9919) - assert_equals(organization.name, 'GitHub') - assert_equals(organization.blog, 'https://github.com/about') - assert_equals(organization.location, 'San Francisco, CA') - assert_equals(organization.gravatar_id, - '61024896f291303615bcd4f7a0dcfb74') - assert_equals(organization.login, 'github') - assert_equals(organization.email, 'support@github.com') - assert_equals(organization.company, None) - assert_equals(organization.created_at, - datetime(2008, 5, 10, 21, 37, 31)) - assert_equals(organization.following_count, 0) - assert_equals(organization.followers_count, 591) - assert_equals(organization.public_gist_count, 0) - assert_equals(organization.public_repo_count, 31) - assert_equals(organization.permission, None) - assert_equals(organization.plan, None) + eq_(organization.id, 9919) + eq_(organization.name, 'GitHub') + eq_(organization.blog, 'https://github.com/about') + eq_(organization.location, 'San Francisco, CA') + eq_(organization.gravatar_id, '61024896f291303615bcd4f7a0dcfb74') + eq_(organization.login, 'github') + eq_(organization.email, 'support@github.com') + eq_(organization.company, None) + eq_(organization.created_at, datetime(2008, 5, 10, 21, 37, 31)) + eq_(organization.following_count, 0) + eq_(organization.followers_count, 591) + eq_(organization.public_gist_count, 0) + eq_(organization.public_repo_count, 31) + eq_(organization.permission, None) + eq_(organization.plan, None) def test_is_authenticated(self): organization = self.client.organizations.show('github') @@ -41,29 +39,28 @@ def test_is_authenticated(self): class Organization(utils.HttpMockTestCase): def test_repr(self): organization = self.client.organizations.show('github') - assert_equals(repr(organization), - '') + eq_(repr(organization), '') class OrganizationQueries(utils.HttpMockTestCase): """Test organisation querying""" def test_public_repositories(self): repos = self.client.organizations.public_repositories('github') - assert_equals(len(repos), 31) - assert_equals(repos[2].name, 'hubahuba') + eq_(len(repos), 31) + eq_(repos[2].name, 'hubahuba') def test_public_members(self): members = self.client.organizations.public_members('github') - assert_equals(len(members), 35) - assert_equals(members[2].name, 'Ben Burkert') + eq_(len(members), 35) + eq_(members[2].name, 'Ben Burkert') class OrganizationsEdits(utils.HttpMockAuthenticatedTestCase): def test_add_team(self): team = self.client.organizations.add_team('JNRowe-test-org', 'test_pull', 'pull') - assert_equals(team.name, 'team_pull') - assert_equals(team.permission, 'pull') + eq_(team.name, 'team_pull') + eq_(team.permission, 'pull') def test_add_team_with_repos(self): projects = ['JNRowe-test-org/test1', 'JNRowe-test-org/test2'] @@ -72,5 +69,4 @@ def test_add_team_with_repos(self): projects) team_repos = self.client.teams.repositories(team.id) - assert_equals(['/'.join([x.organization, x.name]) for x in team_repos], - projects) + eq_(['/'.join([x.organization, x.name]) for x in team_repos], projects) diff --git a/tests/test_pull_requests.py b/tests/test_pull_requests.py index 9c2d35e..efe486c 100644 --- a/tests/test_pull_requests.py +++ b/tests/test_pull_requests.py @@ -5,7 +5,7 @@ from datetime import datetime -from nose.tools import assert_equals +from nose.tools import eq_ import utils @@ -13,55 +13,48 @@ class PullRequest(utils.HttpMockTestCase): def test_properties(self): pull_request = self.client.pull_requests.show('ask/python-github2', 39) - assert_equals(pull_request.state, 'closed') - assert_equals(pull_request.base['sha'], + eq_(pull_request.state, 'closed') + eq_(pull_request.base['sha'], '0786a96c80afad7bbd0747df590f649eaa46ca04') - assert_equals(pull_request.head['sha'], + eq_(pull_request.head['sha'], '5438e41d9c390f53089ed3fa0842831fafc73d8e') - assert_equals(pull_request.issue_user['login'], 'JNRowe') - assert_equals(pull_request.user['login'], 'JNRowe') - assert_equals(pull_request.title, 'Datetime timezone handling.') - assert_equals(len(pull_request.body), 1442) - assert_equals(pull_request.position, 39.0) - assert_equals(pull_request.number, 39.0) - assert_equals(pull_request.votes, 0) - assert_equals(pull_request.comments, 4) - assert_equals(pull_request.diff_url, - 'https://github.com/ask/python-github2/pull/39.diff') - assert_equals(pull_request.patch_url, - 'https://github.com/ask/python-github2/pull/39.patch') - assert_equals(pull_request.labels, []) - assert_equals(pull_request.html_url, - 'https://github.com/ask/python-github2/pull/39') - assert_equals(pull_request.issue_created_at, - datetime(2011, 4, 18, 15, 25, 47)) - assert_equals(pull_request.issue_updated_at, - datetime(2011, 6, 23, 9, 33, 57)) - assert_equals(pull_request.created_at, - datetime(2011, 6, 20, 16, 51, 24)) - assert_equals(pull_request.updated_at, - datetime(2011, 6, 23, 9, 28, 42)) - assert_equals(pull_request.closed_at, - datetime(2011, 6, 23, 9, 33, 57)) - assert_equals(len(pull_request.discussion), 13) - assert_equals(pull_request.mergeable, True) + eq_(pull_request.issue_user['login'], 'JNRowe') + eq_(pull_request.user['login'], 'JNRowe') + eq_(pull_request.title, 'Datetime timezone handling.') + eq_(len(pull_request.body), 1442) + eq_(pull_request.position, 39.0) + eq_(pull_request.number, 39.0) + eq_(pull_request.votes, 0) + eq_(pull_request.comments, 4) + eq_(pull_request.diff_url, + 'https://github.com/ask/python-github2/pull/39.diff') + eq_(pull_request.patch_url, + 'https://github.com/ask/python-github2/pull/39.patch') + eq_(pull_request.labels, []) + eq_(pull_request.html_url, + 'https://github.com/ask/python-github2/pull/39') + eq_(pull_request.issue_created_at, datetime(2011, 4, 18, 15, 25, 47)) + eq_(pull_request.issue_updated_at, datetime(2011, 6, 23, 9, 33, 57)) + eq_(pull_request.created_at, datetime(2011, 6, 20, 16, 51, 24)) + eq_(pull_request.updated_at, datetime(2011, 6, 23, 9, 28, 42)) + eq_(pull_request.closed_at, datetime(2011, 6, 23, 9, 33, 57)) + eq_(len(pull_request.discussion), 13) + eq_(pull_request.mergeable, True) def test_repr(self): pull_request = self.client.pull_requests.show('ask/python-github2', 39) - assert_equals(repr(pull_request), - '') + eq_(repr(pull_request), '') class PullRequestQueries(utils.HttpMockTestCase): """Test pull request querying""" def test_list(self): pull_requests = self.client.pull_requests.list('ask/python-github2') - assert_equals(len(pull_requests), 1) - assert_equals(pull_requests[0].title, - 'Pagination support for commits.') + eq_(len(pull_requests), 1) + eq_(pull_requests[0].title, 'Pagination support for commits.') def test_list_with_page(self): pull_requests = self.client.pull_requests.list('robbyrussell/oh-my-zsh', page=2) - assert_equals(len(pull_requests), 52) - assert_equals(pull_requests[1].title, 'Added my own custom theme') + eq_(len(pull_requests), 52) + eq_(pull_requests[1].title, 'Added my own custom theme') diff --git a/tests/test_regression.py b/tests/test_regression.py index cad7dc2..d5ff091 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -5,7 +5,7 @@ import httplib2 -from nose.tools import assert_equals +from nose.tools import eq_ from github2.client import Github @@ -21,8 +21,8 @@ def test_issue_50(): client = Github(proxy_host="my.proxy.com", proxy_port=9000) setup_args = client.request._http.called_with - assert_equals(type(setup_args['proxy_info']), httplib2.ProxyInfo) - assert_equals(setup_args['proxy_info'].proxy_host, 'my.proxy.com') - assert_equals(setup_args['proxy_info'].proxy_port, 9000) + eq_(type(setup_args['proxy_info']), httplib2.ProxyInfo) + eq_(setup_args['proxy_info'].proxy_host, 'my.proxy.com') + eq_(setup_args['proxy_info'].proxy_port, 9000) utils.unset_http_mock() diff --git a/tests/test_repositories.py b/tests/test_repositories.py index 1cdaab9..39017df 100644 --- a/tests/test_repositories.py +++ b/tests/test_repositories.py @@ -7,7 +7,7 @@ import datetime -from nose.tools import assert_equals +from nose.tools import eq_ import utils @@ -15,7 +15,7 @@ class Repo(utils.HttpMockTestCase): def test_repr(self): repo = self.client.repos.show('JNRowe/misc-overlay') - assert_equals(repr(repo), '') + eq_(repr(repo), '') class RepoProperties(utils.HttpMockTestCase): @@ -23,103 +23,98 @@ class RepoProperties(utils.HttpMockTestCase): def test_repo(self): repo = self.client.repos.show('JNRowe/misc-overlay') - assert_equals(repo.name, 'misc-overlay') - assert_equals(repo.description, - 'Gentoo overlay -- miscellaneous packages') - assert_equals(repo.url, 'https://github.com/JNRowe/misc-overlay') - assert_equals(repo.owner, 'JNRowe') - assert_equals(repo.homepage, 'http://jnrowe.github.com/misc-overlay/') + eq_(repo.name, 'misc-overlay') + eq_(repo.description, 'Gentoo overlay -- miscellaneous packages') + eq_(repo.url, 'https://github.com/JNRowe/misc-overlay') + eq_(repo.owner, 'JNRowe') + eq_(repo.homepage, 'http://jnrowe.github.com/misc-overlay/') - assert_equals(repo.project, 'JNRowe/misc-overlay') + eq_(repo.project, 'JNRowe/misc-overlay') def test_meta(self): repo = self.client.repos.show('JNRowe/misc-overlay') - assert_equals(repo.forks, 0) - assert_equals(repo.watchers, 5) - assert_equals(repo.private, False) - assert_equals(repo.fork, False) - assert_equals(repo.master_branch, None) - assert_equals(repo.integration_branch, None) - assert_equals(repo.open_issues, 13) - assert_equals(repo.created_at, - datetime.datetime(2009, 5, 2, 7, 32, 50)) - assert_equals(repo.pushed_at, - datetime.datetime(2011, 8, 11, 11, 46, 23)) - assert_equals(repo.has_downloads, True) - assert_equals(repo.has_wiki, True) - assert_equals(repo.has_issues, True) - assert_equals(repo.language, 'Python') + eq_(repo.forks, 0) + eq_(repo.watchers, 5) + eq_(repo.private, False) + eq_(repo.fork, False) + eq_(repo.master_branch, None) + eq_(repo.integration_branch, None) + eq_(repo.open_issues, 13) + eq_(repo.created_at, datetime.datetime(2009, 5, 2, 7, 32, 50)) + eq_(repo.pushed_at, datetime.datetime(2011, 8, 11, 11, 46, 23)) + eq_(repo.has_downloads, True) + eq_(repo.has_wiki, True) + eq_(repo.has_issues, True) + eq_(repo.language, 'Python') def test_fork_properties(self): repo = self.client.repos.show('JNRowe/python-github2') - assert_equals(repo.forks, 0) - assert_equals(repo.fork, True) - assert_equals(repo.parent, 'ask/python-github2') - assert_equals(repo.source, 'ask/python-github2') + eq_(repo.forks, 0) + eq_(repo.fork, True) + eq_(repo.parent, 'ask/python-github2') + eq_(repo.source, 'ask/python-github2') class RepoQueries(utils.HttpMockTestCase): """Test repository querying""" def test_search(self): repos = self.client.repos.search('surfraw') - assert_equals(len(repos), 8) - assert_equals(repos[0].owner, 'JNRowe') + eq_(len(repos), 8) + eq_(repos[0].owner, 'JNRowe') def test_list(self): repos = self.client.repos.list('JNRowe') - assert_equals(len(repos), 48) - assert_equals(repos[0].name, 'bfm') + eq_(len(repos), 48) + eq_(repos[0].name, 'bfm') def test_list_with_page(self): repos = self.client.repos.list('tekkub', page=2) - assert_equals(len(repos), 37) - assert_equals(repos[0].name, 'OhSnap') + eq_(len(repos), 37) + eq_(repos[0].name, 'OhSnap') def test_watching(self): repos = self.client.repos.watching('JNRowe') - assert_equals(len(repos), 90) - assert_equals(repos[0].name, 'nerdtree') + eq_(len(repos), 90) + eq_(repos[0].name, 'nerdtree') def test_watching_with_page(self): repos = self.client.repos.watching('tekkub', page=2) - assert_equals(len(repos), 39) - assert_equals(repos[0].name, 'Buffoon') + eq_(len(repos), 39) + eq_(repos[0].name, 'Buffoon') def test_contributors(self): contributors = self.client.repos.list_contributors('ask/python-github2') - assert_equals(len(contributors), 29) - assert_equals(contributors[1].name, 'Ask Solem Hoel') + eq_(len(contributors), 29) + eq_(contributors[1].name, 'Ask Solem Hoel') def test_list_collaborators(self): collaborators = self.client.repos.list_collaborators('ask/python-github2') - assert_equals(len(collaborators), 4) - assert_equals(collaborators[2], 'JNRowe') + eq_(len(collaborators), 4) + eq_(collaborators[2], 'JNRowe') def test_languages(self): languages = self.client.repos.languages('JNRowe/misc-overlay') - assert_equals(len(languages), 2) - assert_equals(languages['Python'], 11194) + eq_(len(languages), 2) + eq_(languages['Python'], 11194) def test_tags(self): tags = self.client.repos.tags('ask/python-github2') - assert_equals(len(tags), 7) - assert_equals(tags['0.4.1'], - '96b0a41dd249c521323700bc11a0a721a7c9e642') + eq_(len(tags), 7) + eq_(tags['0.4.1'], '96b0a41dd249c521323700bc11a0a721a7c9e642') def test_branches(self): branches = self.client.repos.branches('ask/python-github2') - assert_equals(len(branches), 1) - assert_equals(branches['master'], - '1c83cde9b5a7c396a01af1007fb7b88765b9ae45') + eq_(len(branches), 1) + eq_(branches['master'], '1c83cde9b5a7c396a01af1007fb7b88765b9ae45') def test_watchers(self): watchers = self.client.repos.watchers('ask/python-github2') - assert_equals(len(watchers), 143) - assert_equals(watchers[0], 'ask') + eq_(len(watchers), 143) + eq_(watchers[0], 'ask') class AuthenticatedRepoQueries(utils.HttpMockAuthenticatedTestCase): def test_pushable(self): repos = self.client.repos.pushable() - assert_equals(len(repos), 1) - assert_equals(repos[0].name, 'python-github2') + eq_(len(repos), 1) + eq_(repos[0].name, 'python-github2') diff --git a/tests/test_teams.py b/tests/test_teams.py index 7333edd..cd18166 100644 --- a/tests/test_teams.py +++ b/tests/test_teams.py @@ -3,7 +3,7 @@ # This file is part of python-github2, and is made available under the 3-clause # BSD license. See LICENSE for the full details. -from nose.tools import assert_equals +from nose.tools import eq_ import utils @@ -11,4 +11,4 @@ class TeamEdits(utils.HttpMockAuthenticatedTestCase): def test_add_member(self): users = self.client.teams.add_member(121990, 'JNRowe') - assert_equals(users[0].login, 'JNRowe') + eq_(users[0].login, 'JNRowe') diff --git a/tests/test_tz_aware_date_handling.py b/tests/test_tz_aware_date_handling.py index 6a501f0..77302ba 100644 --- a/tests/test_tz_aware_date_handling.py +++ b/tests/test_tz_aware_date_handling.py @@ -7,7 +7,7 @@ from datetime import datetime as dt from dateutil.tz import tzutc -from nose.tools import assert_equals +from nose.tools import eq_ from github2 import core from github2.core import (datetime_to_ghdate, datetime_to_commitdate, @@ -33,150 +33,150 @@ def dt_utz(year, month, day, hour, minute, second): def test_ghdate_to_datetime(): - assert_equals(string_to_datetime('2011/05/22 00:24:15 -0700'), - dt_utz(2011, 5, 22, 7, 24, 15)) - assert_equals(string_to_datetime('2009/04/18 13:04:09 -0700'), - dt_utz(2009, 4, 18, 20, 4, 9)) - assert_equals(string_to_datetime('2009/11/12 21:15:17 -0800'), - dt_utz(2009, 11, 13, 5, 15, 17)) - assert_equals(string_to_datetime('2009/11/12 21:16:20 -0800'), - dt_utz(2009, 11, 13, 5, 16, 20)) - assert_equals(string_to_datetime('2010/04/17 17:24:29 -0700'), - dt_utz(2010, 4, 18, 0, 24, 29)) - assert_equals(string_to_datetime('2010/05/18 06:10:36 -0700'), - dt_utz(2010, 5, 18, 13, 10, 36)) - assert_equals(string_to_datetime('2010/05/25 21:59:37 -0700'), - dt_utz(2010, 5, 26, 4, 59, 37)) - assert_equals(string_to_datetime('2010/05/26 17:08:41 -0700'), - dt_utz(2010, 5, 27, 0, 8, 41)) - assert_equals(string_to_datetime('2010/06/20 06:13:37 -0700'), - dt_utz(2010, 6, 20, 13, 13, 37)) - assert_equals(string_to_datetime('2010/07/28 12:56:51 -0700'), - dt_utz(2010, 7, 28, 19, 56, 51)) - assert_equals(string_to_datetime('2010/09/20 21:32:49 -0700'), - dt_utz(2010, 9, 21, 4, 32, 49)) + eq_(string_to_datetime('2011/05/22 00:24:15 -0700'), + dt_utz(2011, 5, 22, 7, 24, 15)) + eq_(string_to_datetime('2009/04/18 13:04:09 -0700'), + dt_utz(2009, 4, 18, 20, 4, 9)) + eq_(string_to_datetime('2009/11/12 21:15:17 -0800'), + dt_utz(2009, 11, 13, 5, 15, 17)) + eq_(string_to_datetime('2009/11/12 21:16:20 -0800'), + dt_utz(2009, 11, 13, 5, 16, 20)) + eq_(string_to_datetime('2010/04/17 17:24:29 -0700'), + dt_utz(2010, 4, 18, 0, 24, 29)) + eq_(string_to_datetime('2010/05/18 06:10:36 -0700'), + dt_utz(2010, 5, 18, 13, 10, 36)) + eq_(string_to_datetime('2010/05/25 21:59:37 -0700'), + dt_utz(2010, 5, 26, 4, 59, 37)) + eq_(string_to_datetime('2010/05/26 17:08:41 -0700'), + dt_utz(2010, 5, 27, 0, 8, 41)) + eq_(string_to_datetime('2010/06/20 06:13:37 -0700'), + dt_utz(2010, 6, 20, 13, 13, 37)) + eq_(string_to_datetime('2010/07/28 12:56:51 -0700'), + dt_utz(2010, 7, 28, 19, 56, 51)) + eq_(string_to_datetime('2010/09/20 21:32:49 -0700'), + dt_utz(2010, 9, 21, 4, 32, 49)) def test_datetime_to_ghdate(): - assert_equals(datetime_to_ghdate(dt_utz(2011, 5, 22, 7, 24, 15)), - '2011/05/22 00:24:15 -0700') - assert_equals(datetime_to_ghdate(dt_utz(2009, 4, 18, 20, 4, 9)), - '2009/04/18 13:04:09 -0700') - assert_equals(datetime_to_ghdate(dt_utz(2009, 11, 13, 4, 15, 17)), - '2009/11/12 20:15:17 -0800') - assert_equals(datetime_to_ghdate(dt_utz(2009, 11, 13, 4, 16, 20)), - '2009/11/12 20:16:20 -0800') - assert_equals(datetime_to_ghdate(dt_utz(2010, 4, 18, 0, 24, 29)), - '2010/04/17 17:24:29 -0700') - assert_equals(datetime_to_ghdate(dt_utz(2010, 5, 18, 13, 10, 36)), - '2010/05/18 06:10:36 -0700') - assert_equals(datetime_to_ghdate(dt_utz(2010, 5, 26, 5, 59, 37)), - '2010/05/25 22:59:37 -0700') - assert_equals(datetime_to_ghdate(dt_utz(2010, 5, 27, 0, 8, 41)), - '2010/05/26 17:08:41 -0700') - assert_equals(datetime_to_ghdate(dt_utz(2010, 6, 20, 13, 13, 37)), - '2010/06/20 06:13:37 -0700') - assert_equals(datetime_to_ghdate(dt_utz(2010, 7, 28, 19, 56, 51)), - '2010/07/28 12:56:51 -0700') - assert_equals(datetime_to_ghdate(dt_utz(2010, 9, 21, 4, 32, 49)), - '2010/09/20 21:32:49 -0700') + eq_(datetime_to_ghdate(dt_utz(2011, 5, 22, 7, 24, 15)), + '2011/05/22 00:24:15 -0700') + eq_(datetime_to_ghdate(dt_utz(2009, 4, 18, 20, 4, 9)), + '2009/04/18 13:04:09 -0700') + eq_(datetime_to_ghdate(dt_utz(2009, 11, 13, 4, 15, 17)), + '2009/11/12 20:15:17 -0800') + eq_(datetime_to_ghdate(dt_utz(2009, 11, 13, 4, 16, 20)), + '2009/11/12 20:16:20 -0800') + eq_(datetime_to_ghdate(dt_utz(2010, 4, 18, 0, 24, 29)), + '2010/04/17 17:24:29 -0700') + eq_(datetime_to_ghdate(dt_utz(2010, 5, 18, 13, 10, 36)), + '2010/05/18 06:10:36 -0700') + eq_(datetime_to_ghdate(dt_utz(2010, 5, 26, 5, 59, 37)), + '2010/05/25 22:59:37 -0700') + eq_(datetime_to_ghdate(dt_utz(2010, 5, 27, 0, 8, 41)), + '2010/05/26 17:08:41 -0700') + eq_(datetime_to_ghdate(dt_utz(2010, 6, 20, 13, 13, 37)), + '2010/06/20 06:13:37 -0700') + eq_(datetime_to_ghdate(dt_utz(2010, 7, 28, 19, 56, 51)), + '2010/07/28 12:56:51 -0700') + eq_(datetime_to_ghdate(dt_utz(2010, 9, 21, 4, 32, 49)), + '2010/09/20 21:32:49 -0700') def test_commitdate_to_datetime(): - assert_equals(string_to_datetime('2011-05-22T00:24:15-07:00'), - dt_utz(2011, 5, 22, 7, 24, 15)) - assert_equals(string_to_datetime('2011-04-09T10:07:30-07:00'), - dt_utz(2011, 4, 9, 17, 7, 30)) - assert_equals(string_to_datetime('2011-02-19T07:16:11-08:00'), - dt_utz(2011, 2, 19, 15, 16, 11)) - assert_equals(string_to_datetime('2010-12-21T12:34:27-08:00'), - dt_utz(2010, 12, 21, 20, 34, 27)) - assert_equals(string_to_datetime('2011-04-09T10:20:05-07:00'), - dt_utz(2011, 4, 9, 17, 20, 5)) - assert_equals(string_to_datetime('2011-04-09T10:05:58-07:00'), - dt_utz(2011, 4, 9, 17, 5, 58)) - assert_equals(string_to_datetime('2011-04-09T09:53:00-07:00'), - dt_utz(2011, 4, 9, 16, 53, 0)) - assert_equals(string_to_datetime('2011-04-09T10:00:21-07:00'), - dt_utz(2011, 4, 9, 17, 0, 21)) - assert_equals(string_to_datetime('2010-12-16T15:10:59-08:00'), - dt_utz(2010, 12, 16, 23, 10, 59)) - assert_equals(string_to_datetime('2011-04-09T09:53:00-07:00'), - dt_utz(2011, 4, 9, 16, 53, 0)) - assert_equals(string_to_datetime('2011-04-09T09:53:00-07:00'), - dt_utz(2011, 4, 9, 16, 53, 0)) + eq_(string_to_datetime('2011-05-22T00:24:15-07:00'), + dt_utz(2011, 5, 22, 7, 24, 15)) + eq_(string_to_datetime('2011-04-09T10:07:30-07:00'), + dt_utz(2011, 4, 9, 17, 7, 30)) + eq_(string_to_datetime('2011-02-19T07:16:11-08:00'), + dt_utz(2011, 2, 19, 15, 16, 11)) + eq_(string_to_datetime('2010-12-21T12:34:27-08:00'), + dt_utz(2010, 12, 21, 20, 34, 27)) + eq_(string_to_datetime('2011-04-09T10:20:05-07:00'), + dt_utz(2011, 4, 9, 17, 20, 5)) + eq_(string_to_datetime('2011-04-09T10:05:58-07:00'), + dt_utz(2011, 4, 9, 17, 5, 58)) + eq_(string_to_datetime('2011-04-09T09:53:00-07:00'), + dt_utz(2011, 4, 9, 16, 53, 0)) + eq_(string_to_datetime('2011-04-09T10:00:21-07:00'), + dt_utz(2011, 4, 9, 17, 0, 21)) + eq_(string_to_datetime('2010-12-16T15:10:59-08:00'), + dt_utz(2010, 12, 16, 23, 10, 59)) + eq_(string_to_datetime('2011-04-09T09:53:00-07:00'), + dt_utz(2011, 4, 9, 16, 53, 0)) + eq_(string_to_datetime('2011-04-09T09:53:00-07:00'), + dt_utz(2011, 4, 9, 16, 53, 0)) def test_datetime_to_commitdate(): - assert_equals(datetime_to_commitdate(dt_utz(2011, 5, 22, 7, 24, 15)), - '2011-05-22T00:24:15-07:00') - assert_equals(datetime_to_commitdate(dt_utz(2011, 4, 9, 17, 7, 30)), - '2011-04-09T10:07:30-07:00') - assert_equals(datetime_to_commitdate(dt_utz(2011, 2, 19, 15, 16, 11)), - '2011-02-19T07:16:11-08:00') - assert_equals(datetime_to_commitdate(dt_utz(2010, 12, 21, 20, 34, 27)), - '2010-12-21T12:34:27-08:00') - assert_equals(datetime_to_commitdate(dt_utz(2011, 4, 9, 17, 20, 5)), - '2011-04-09T10:20:05-07:00') - assert_equals(datetime_to_commitdate(dt_utz(2011, 4, 9, 17, 5, 58)), - '2011-04-09T10:05:58-07:00') - assert_equals(datetime_to_commitdate(dt_utz(2011, 4, 9, 16, 53, 0)), - '2011-04-09T09:53:00-07:00') - assert_equals(datetime_to_commitdate(dt_utz(2011, 4, 9, 17, 0, 21)), - '2011-04-09T10:00:21-07:00') - assert_equals(datetime_to_commitdate(dt_utz(2010, 12, 16, 23, 10, 59)), - '2010-12-16T15:10:59-08:00') - assert_equals(datetime_to_commitdate(dt_utz(2011, 4, 9, 16, 53, 0)), - '2011-04-09T09:53:00-07:00') - assert_equals(datetime_to_commitdate(dt_utz(2011, 4, 9, 16, 53, 0)), - '2011-04-09T09:53:00-07:00') + eq_(datetime_to_commitdate(dt_utz(2011, 5, 22, 7, 24, 15)), + '2011-05-22T00:24:15-07:00') + eq_(datetime_to_commitdate(dt_utz(2011, 4, 9, 17, 7, 30)), + '2011-04-09T10:07:30-07:00') + eq_(datetime_to_commitdate(dt_utz(2011, 2, 19, 15, 16, 11)), + '2011-02-19T07:16:11-08:00') + eq_(datetime_to_commitdate(dt_utz(2010, 12, 21, 20, 34, 27)), + '2010-12-21T12:34:27-08:00') + eq_(datetime_to_commitdate(dt_utz(2011, 4, 9, 17, 20, 5)), + '2011-04-09T10:20:05-07:00') + eq_(datetime_to_commitdate(dt_utz(2011, 4, 9, 17, 5, 58)), + '2011-04-09T10:05:58-07:00') + eq_(datetime_to_commitdate(dt_utz(2011, 4, 9, 16, 53, 0)), + '2011-04-09T09:53:00-07:00') + eq_(datetime_to_commitdate(dt_utz(2011, 4, 9, 17, 0, 21)), + '2011-04-09T10:00:21-07:00') + eq_(datetime_to_commitdate(dt_utz(2010, 12, 16, 23, 10, 59)), + '2010-12-16T15:10:59-08:00') + eq_(datetime_to_commitdate(dt_utz(2011, 4, 9, 16, 53, 0)), + '2011-04-09T09:53:00-07:00') + eq_(datetime_to_commitdate(dt_utz(2011, 4, 9, 16, 53, 0)), + '2011-04-09T09:53:00-07:00') def test_isodate_to_datetime(): - assert_equals(string_to_datetime('2011-05-22T00:24:15Z'), - dt_utz(2011, 5, 22, 0, 24, 15)) - assert_equals(string_to_datetime('2011-04-09T10:07:30Z'), - dt_utz(2011, 4, 9, 10, 7, 30)) - assert_equals(string_to_datetime('2011-02-19T07:16:11Z'), - dt_utz(2011, 2, 19, 7, 16, 11)) - assert_equals(string_to_datetime('2010-12-21T12:34:27Z'), - dt_utz(2010, 12, 21, 12, 34, 27)) - assert_equals(string_to_datetime('2011-04-09T10:20:05Z'), - dt_utz(2011, 4, 9, 10, 20, 5)) - assert_equals(string_to_datetime('2011-04-09T10:05:58Z'), - dt_utz(2011, 4, 9, 10, 5, 58)) - assert_equals(string_to_datetime('2011-04-09T09:53:00Z'), - dt_utz(2011, 4, 9, 9, 53, 0)) - assert_equals(string_to_datetime('2011-04-09T10:00:21Z'), - dt_utz(2011, 4, 9, 10, 0, 21)) - assert_equals(string_to_datetime('2010-12-16T15:10:59Z'), - dt_utz(2010, 12, 16, 15, 10, 59)) - assert_equals(string_to_datetime('2011-04-09T09:53:00Z'), - dt_utz(2011, 4, 9, 9, 53, 0)) - assert_equals(string_to_datetime('2011-04-09T09:53:00Z'), - dt_utz(2011, 4, 9, 9, 53, 0)) + eq_(string_to_datetime('2011-05-22T00:24:15Z'), + dt_utz(2011, 5, 22, 0, 24, 15)) + eq_(string_to_datetime('2011-04-09T10:07:30Z'), + dt_utz(2011, 4, 9, 10, 7, 30)) + eq_(string_to_datetime('2011-02-19T07:16:11Z'), + dt_utz(2011, 2, 19, 7, 16, 11)) + eq_(string_to_datetime('2010-12-21T12:34:27Z'), + dt_utz(2010, 12, 21, 12, 34, 27)) + eq_(string_to_datetime('2011-04-09T10:20:05Z'), + dt_utz(2011, 4, 9, 10, 20, 5)) + eq_(string_to_datetime('2011-04-09T10:05:58Z'), + dt_utz(2011, 4, 9, 10, 5, 58)) + eq_(string_to_datetime('2011-04-09T09:53:00Z'), + dt_utz(2011, 4, 9, 9, 53, 0)) + eq_(string_to_datetime('2011-04-09T10:00:21Z'), + dt_utz(2011, 4, 9, 10, 0, 21)) + eq_(string_to_datetime('2010-12-16T15:10:59Z'), + dt_utz(2010, 12, 16, 15, 10, 59)) + eq_(string_to_datetime('2011-04-09T09:53:00Z'), + dt_utz(2011, 4, 9, 9, 53, 0)) + eq_(string_to_datetime('2011-04-09T09:53:00Z'), + dt_utz(2011, 4, 9, 9, 53, 0)) def test_datetime_to_isodate(): - assert_equals(datetime_to_isodate(dt_utz(2011, 5, 22, 0, 24, 15)), - '2011-05-22T00:24:15Z') - assert_equals(datetime_to_isodate(dt_utz(2011, 4, 9, 10, 7, 30)), - '2011-04-09T10:07:30Z') - assert_equals(datetime_to_isodate(dt_utz(2011, 2, 19, 7, 16, 11)), - '2011-02-19T07:16:11Z') - assert_equals(datetime_to_isodate(dt_utz(2010, 12, 21, 12, 34, 27)), - '2010-12-21T12:34:27Z') - assert_equals(datetime_to_isodate(dt_utz(2011, 4, 9, 10, 20, 5)), - '2011-04-09T10:20:05Z') - assert_equals(datetime_to_isodate(dt_utz(2011, 4, 9, 10, 5, 58)), - '2011-04-09T10:05:58Z') - assert_equals(datetime_to_isodate(dt_utz(2011, 4, 9, 9, 53, 0)), - '2011-04-09T09:53:00Z') - assert_equals(datetime_to_isodate(dt_utz(2011, 4, 9, 10, 0, 21)), - '2011-04-09T10:00:21Z') - assert_equals(datetime_to_isodate(dt_utz(2010, 12, 16, 15, 10, 59)), - '2010-12-16T15:10:59Z') - assert_equals(datetime_to_isodate(dt_utz(2011, 4, 9, 9, 53, 0)), - '2011-04-09T09:53:00Z') - assert_equals(datetime_to_isodate(dt_utz(2011, 4, 9, 9, 53, 0)), - '2011-04-09T09:53:00Z') + eq_(datetime_to_isodate(dt_utz(2011, 5, 22, 0, 24, 15)), + '2011-05-22T00:24:15Z') + eq_(datetime_to_isodate(dt_utz(2011, 4, 9, 10, 7, 30)), + '2011-04-09T10:07:30Z') + eq_(datetime_to_isodate(dt_utz(2011, 2, 19, 7, 16, 11)), + '2011-02-19T07:16:11Z') + eq_(datetime_to_isodate(dt_utz(2010, 12, 21, 12, 34, 27)), + '2010-12-21T12:34:27Z') + eq_(datetime_to_isodate(dt_utz(2011, 4, 9, 10, 20, 5)), + '2011-04-09T10:20:05Z') + eq_(datetime_to_isodate(dt_utz(2011, 4, 9, 10, 5, 58)), + '2011-04-09T10:05:58Z') + eq_(datetime_to_isodate(dt_utz(2011, 4, 9, 9, 53, 0)), + '2011-04-09T09:53:00Z') + eq_(datetime_to_isodate(dt_utz(2011, 4, 9, 10, 0, 21)), + '2011-04-09T10:00:21Z') + eq_(datetime_to_isodate(dt_utz(2010, 12, 16, 15, 10, 59)), + '2010-12-16T15:10:59Z') + eq_(datetime_to_isodate(dt_utz(2011, 4, 9, 9, 53, 0)), + '2011-04-09T09:53:00Z') + eq_(datetime_to_isodate(dt_utz(2011, 4, 9, 9, 53, 0)), + '2011-04-09T09:53:00Z') diff --git a/tests/test_unit.py b/tests/test_unit.py index f17f9a0..1769751 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -10,7 +10,7 @@ import datetime import unittest -from nose.tools import (assert_equals, assert_true) +from nose.tools import (eq_, assert_true) from github2.core import repr_string from github2.issues import Issue @@ -26,18 +26,18 @@ def test_issue(self): """Issues can have non-ASCII characters in the title.""" title = 'abcdé' i = Issue(title=title) - assert_equals(str, type(repr(i))) + eq_(str, type(repr(i))) class HostSetting(unittest.TestCase): def test_default_host(self): client = Github() - assert_equals(client.request.github_url, 'https://github.com') + eq_(client.request.github_url, 'https://github.com') def test_non_standard_host(self): client = Github(github_url="http://your-github-enterprise-url.com/") - assert_equals(client.request.github_url, - 'http://your-github-enterprise-url.com/') + eq_(client.request.github_url, + 'http://your-github-enterprise-url.com/') class RateLimits(utils.HttpMockTestCase): @@ -70,21 +70,21 @@ class BaseDataDict(utils.HttpMockTestCase): """Test __getitem__ availability on objects""" def test_getitem(self): user = self.client.users.show('defunkt') - assert_equals(user['blog'], user.blog) - assert_equals(user['company'], user.company) - assert_equals(user['email'], user.email) - assert_equals(user['location'], user.location) - assert_equals(user['login'], user.login) - assert_equals(user['name'], user.name) + eq_(user['blog'], user.blog) + eq_(user['company'], user.company) + eq_(user['email'], user.email) + eq_(user['location'], user.location) + eq_(user['login'], user.login) + eq_(user['name'], user.name) def test_project_for_user_repo(): client = Github() - assert_equals(client.project_for_user_repo('JNRowe', 'misc-overlay'), + eq_(client.project_for_user_repo('JNRowe', 'misc-overlay'), 'JNRowe/misc-overlay') def test_repr_string(): - assert_equals(repr_string('test'), 'test') - assert_equals(repr_string('abcdefghijklmnopqrst'), 'abcdefghijklmnopqrst') - assert_equals(repr_string('abcdefghijklmnopqrstu'), 'abcdefghijklmnopq...') + eq_(repr_string('test'), 'test') + eq_(repr_string('abcdefghijklmnopqrst'), 'abcdefghijklmnopqrst') + eq_(repr_string('abcdefghijklmnopqrstu'), 'abcdefghijklmnopq...') diff --git a/tests/test_user.py b/tests/test_user.py index 33929db..0d80359 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -5,7 +5,7 @@ import datetime -from nose.tools import (assert_equals, assert_false, assert_true) +from nose.tools import (eq_, assert_false, assert_true) import utils @@ -14,29 +14,28 @@ class UserProperties(utils.HttpMockTestCase): """Test user property handling""" def test_user(self): user = self.client.users.show('defunkt') - assert_equals(user.blog, 'http://chriswanstrath.com/') - assert_equals(user.company, 'GitHub') - assert_equals(user.email, 'chris@wanstrath.com') - assert_equals(user.location, 'San Francisco') - assert_equals(user.login, 'defunkt') - assert_equals(user.name, 'Chris Wanstrath') + eq_(user.blog, 'http://chriswanstrath.com/') + eq_(user.company, 'GitHub') + eq_(user.email, 'chris@wanstrath.com') + eq_(user.location, 'San Francisco') + eq_(user.login, 'defunkt') + eq_(user.name, 'Chris Wanstrath') def test_meta(self): user = self.client.users.show('defunkt') - assert_equals(user.created_at, - datetime.datetime(2007, 10, 19, 22, 24, 19)) - assert_equals(user.followers_count, 3402) - assert_equals(user.following_count, 212) - assert_equals(user.gravatar_id, 'b8dbb1987e8e5318584865f880036796') - assert_equals(user.id, 2) - assert_equals(user.public_gist_count, 278) - assert_equals(user.public_repo_count, 93) + eq_(user.created_at, datetime.datetime(2007, 10, 19, 22, 24, 19)) + eq_(user.followers_count, 3402) + eq_(user.following_count, 212) + eq_(user.gravatar_id, 'b8dbb1987e8e5318584865f880036796') + eq_(user.id, 2) + eq_(user.public_gist_count, 278) + eq_(user.public_repo_count, 93) def test_followers(self): - assert_equals(len(self.client.users.followers('defunkt')), 3402) + eq_(len(self.client.users.followers('defunkt')), 3402) def test_following(self): - assert_equals(len(self.client.users.following('defunkt')), 212) + eq_(len(self.client.users.following('defunkt')), 212) def test_is_not_authenticated(self): user = self.client.users.show('defunkt') @@ -46,12 +45,12 @@ def test_is_not_authenticated(self): class UserQueries(utils.HttpMockTestCase): """Test user querying """ def test_search(self): - assert_equals(repr(self.client.users.search('James Rowe')), - '[, ]') + eq_(repr(self.client.users.search('James Rowe')), + '[, ]') def test_search_by_email(self): user = self.client.users.search_by_email('jnrowe@gmail.com') - assert_equals(repr(user), '') + eq_(repr(user), '') class AuthenticatedUserMethods(utils.HttpMockAuthenticatedTestCase): @@ -69,21 +68,21 @@ def test_is_authenticated(self): def test_list_keys(self): keys = self.client.users.list_keys() - assert_equals(keys[0].id, 1337) + eq_(keys[0].id, 1337) class AuthenticatedUserProperties(utils.HttpMockAuthenticatedTestCase): def test_private_data(self): user = self.client.users.show('') - assert_equals(user.total_private_repo_count, 0) - assert_equals(user.collaborators, 0) - assert_equals(user.disk_usage, 66069) - assert_equals(user.owned_private_repo_count, 0) - assert_equals(user.private_gist_count, 7) + eq_(user.total_private_repo_count, 0) + eq_(user.collaborators, 0) + eq_(user.disk_usage, 66069) + eq_(user.owned_private_repo_count, 0) + eq_(user.private_gist_count, 7) def test_plan_data(self): user = self.client.users.show('') - assert_equals(user.plan['name'], "free") - assert_equals(user.plan['collaborators'], 0) - assert_equals(user.plan['space'], 307200) - assert_equals(user.plan['private_repos'], 0) + eq_(user.plan['name'], "free") + eq_(user.plan['collaborators'], 0) + eq_(user.plan['space'], 307200) + eq_(user.plan['private_repos'], 0) From 01fdd82966c044e17b8f786369197203ec8b8b8a Mon Sep 17 00:00:00 2001 From: James Rowe Date: Wed, 16 May 2012 19:38:26 +0100 Subject: [PATCH 02/10] Use nose.tools.ok_ instead of assert_true. --- tests/test_organizations.py | 6 +++--- tests/test_unit.py | 10 +++++----- tests/test_user.py | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/test_organizations.py b/tests/test_organizations.py index 399d450..e2ddc77 100644 --- a/tests/test_organizations.py +++ b/tests/test_organizations.py @@ -5,7 +5,7 @@ from datetime import datetime -from nose.tools import (eq_, assert_true) +from nose.tools import (eq_, ok_) import utils @@ -31,9 +31,9 @@ def test_properties(self): def test_is_authenticated(self): organization = self.client.organizations.show('github') - assert_true(organization.is_authenticated() is False) + ok_(organization.is_authenticated() is False) organization = self.client.organizations.show('fake_org_with_auth') - assert_true(organization.is_authenticated() is True) + ok_(organization.is_authenticated() is True) class Organization(utils.HttpMockTestCase): diff --git a/tests/test_unit.py b/tests/test_unit.py index 1769751..ce93198 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -10,7 +10,7 @@ import datetime import unittest -from nose.tools import (eq_, assert_true) +from nose.tools import (eq_, ok_) from github2.core import repr_string from github2.issues import Issue @@ -53,9 +53,9 @@ def test_delays(self): delta = end - start delta_seconds = delta.days * 24 * 60 * 60 + delta.seconds - assert_true(delta_seconds >= 2, - "Expected .5 reqs per second to require a 2 second delay " - "between calls.") + ok_(delta_seconds >= 2, + "Expected .5 reqs per second to require a 2 second delay between " + "calls.") class BaseDataIter(utils.HttpMockTestCase): @@ -63,7 +63,7 @@ class BaseDataIter(utils.HttpMockTestCase): def test_iter(self): commit_id = '1c83cde9b5a7c396a01af1007fb7b88765b9ae45' commit = self.client.commits.show('ask/python-github2', commit_id) - assert_true('__iter__' in dir(commit)) + ok_('__iter__' in dir(commit)) class BaseDataDict(utils.HttpMockTestCase): diff --git a/tests/test_user.py b/tests/test_user.py index 0d80359..61fbc5c 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -5,7 +5,7 @@ import datetime -from nose.tools import (eq_, assert_false, assert_true) +from nose.tools import (eq_, assert_false, ok_) import utils @@ -39,7 +39,7 @@ def test_following(self): def test_is_not_authenticated(self): user = self.client.users.show('defunkt') - assert_true(user.is_authenticated() is False) + ok_(user.is_authenticated() is False) class UserQueries(utils.HttpMockTestCase): @@ -56,7 +56,7 @@ def test_search_by_email(self): class AuthenticatedUserMethods(utils.HttpMockAuthenticatedTestCase): def test_follow(self): result = self.client.users.follow('defunkt') - assert_true('defunkt' in result['users']) + ok_('defunkt' in result['users']) def test_unfollow(self): result = self.client.users.unfollow('defunkt') @@ -64,7 +64,7 @@ def test_unfollow(self): def test_is_authenticated(self): user = self.client.users.show('') - assert_true(user.is_authenticated() is True) + ok_(user.is_authenticated() is True) def test_list_keys(self): keys = self.client.users.list_keys() From bb968da0cc90dd60cf1709341a4b760d93a8405c Mon Sep 17 00:00:00 2001 From: James Rowe Date: Wed, 16 May 2012 19:42:00 +0100 Subject: [PATCH 03/10] [QA] PEP 257 fixes to tests. --- tests/test_commits.py | 5 ++++- tests/test_issues.py | 4 +++- tests/test_regression.py | 2 +- tests/test_repositories.py | 4 +++- tests/test_request.py | 4 +++- tests/test_tz_aware_date_handling.py | 7 ++++--- tests/test_unit.py | 15 +++++++++++---- tests/test_user.py | 8 ++++++-- tests/utils.py | 14 +++++++++----- 9 files changed, 44 insertions(+), 19 deletions(-) diff --git a/tests/test_commits.py b/tests/test_commits.py index 33f037c..b27fbd3 100644 --- a/tests/test_commits.py +++ b/tests/test_commits.py @@ -11,7 +11,9 @@ class CommitProperties(utils.HttpMockTestCase): - """Test commit property handling""" + + """Test commit property handling.""" + commit_id = '1c83cde9b5a7c396a01af1007fb7b88765b9ae45' def test_commit(self): @@ -38,6 +40,7 @@ def test_repr(self): class CommitsQueries(utils.HttpMockTestCase): + """Test commit querying""" def test_list(self): diff --git a/tests/test_issues.py b/tests/test_issues.py index 2abf495..67cbff7 100644 --- a/tests/test_issues.py +++ b/tests/test_issues.py @@ -52,7 +52,9 @@ def test_comment_repr(self): class IssueQueries(utils.HttpMockTestCase): - """Test issue querying""" + + """Test issue querying.""" + def test_search(self): issues = self.client.issues.search('ask/python-github2', 'timezone', 'closed') diff --git a/tests/test_regression.py b/tests/test_regression.py index d5ff091..d9de696 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -13,7 +13,7 @@ def test_issue_50(): - """Erroneous init of ``Http`` with proxy setup + """Erroneous init of ``Http`` with proxy setup. See https://github.com/ask/python-github2/pull/50 """ diff --git a/tests/test_repositories.py b/tests/test_repositories.py index 39017df..8abbc30 100644 --- a/tests/test_repositories.py +++ b/tests/test_repositories.py @@ -19,7 +19,9 @@ def test_repr(self): class RepoProperties(utils.HttpMockTestCase): - """Test repository property handling""" + + """Test repository property handling.""" + def test_repo(self): repo = self.client.repos.show('JNRowe/misc-overlay') diff --git a/tests/test_request.py b/tests/test_request.py index 0833c00..529de26 100644 --- a/tests/test_request.py +++ b/tests/test_request.py @@ -35,7 +35,9 @@ def assert_params_contain(first, second): class TestAuthEncode(unittest.TestCase): - """Test processing of authentication data""" + + """Test processing of authentication data.""" + def setUp(self): self.r = request.GithubRequest() diff --git a/tests/test_tz_aware_date_handling.py b/tests/test_tz_aware_date_handling.py index 77302ba..c2b152f 100644 --- a/tests/test_tz_aware_date_handling.py +++ b/tests/test_tz_aware_date_handling.py @@ -15,19 +15,20 @@ def setup_module(): - """Enable timezone-aware datetime handling for this module's tests""" + """Enable timezone-aware datetime handling for this module's tests.""" core.NAIVE = False def teardown_module(): - """Disable timezone-aware datetime handling when tests have completed""" + """Disable timezone-aware datetime handling when tests have completed.""" core.NAIVE = True def dt_utz(year, month, day, hour, minute, second): - """Produce a UTC-anchored datetime object + """Produce a UTC-anchored datetime object. :see: :class:`datetime.datetime` + """ return dt(year, month, day, hour, minute, second, tzinfo=tzutc()) diff --git a/tests/test_unit.py b/tests/test_unit.py index ce93198..2095952 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -20,6 +20,7 @@ class ReprTests(unittest.TestCase): + """__repr__ must return strings, not unicode objects.""" def test_issue(self): @@ -41,9 +42,11 @@ def test_non_standard_host(self): class RateLimits(utils.HttpMockTestCase): - """Test API rate-limitting""" + + """Test API rate-limitting.""" + def test_delays(self): - """Test call delay is at least one second""" + """Test call delay is at least one second.""" client = Github(requests_per_second=.5) client.users.show('defunkt') start = datetime.datetime.utcnow() @@ -59,7 +62,9 @@ def test_delays(self): class BaseDataIter(utils.HttpMockTestCase): - """Test iter availability of objects""" + + """Test iter availability of objects.""" + def test_iter(self): commit_id = '1c83cde9b5a7c396a01af1007fb7b88765b9ae45' commit = self.client.commits.show('ask/python-github2', commit_id) @@ -67,7 +72,9 @@ def test_iter(self): class BaseDataDict(utils.HttpMockTestCase): - """Test __getitem__ availability on objects""" + + """Test __getitem__ availability on objects.""" + def test_getitem(self): user = self.client.users.show('defunkt') eq_(user['blog'], user.blog) diff --git a/tests/test_user.py b/tests/test_user.py index 61fbc5c..c2fab11 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -11,7 +11,9 @@ class UserProperties(utils.HttpMockTestCase): - """Test user property handling""" + + """Test user property handling.""" + def test_user(self): user = self.client.users.show('defunkt') eq_(user.blog, 'http://chriswanstrath.com/') @@ -43,7 +45,9 @@ def test_is_not_authenticated(self): class UserQueries(utils.HttpMockTestCase): - """Test user querying """ + + """Test user querying.""" + def test_search(self): eq_(repr(self.client.users.search('James Rowe')), '[, ]') diff --git a/tests/utils.py b/tests/utils.py index 598b068..1b38949 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -25,9 +25,10 @@ class HttpMock(object): - """Simple Http mock that returns saved entries + """Simple Http mock that returns saved entries. + + Implementation tests should never span network boundaries. - Implementation tests should never span network boundaries """ def __init__(self, cache=None, timeout=None, proxy_info=None, @@ -55,33 +56,36 @@ def request(self, uri, method='GET', body=None, headers=None, class HttpMockTestCase(unittest.TestCase): def setUp(self): - """Prepare test fixtures + """Prepare test fixtures. `httplib2.Http` is patched to return cached entries via :class:`HttpMock`. :attr:`client` is an unauthenticated :obj:`Github` object for easy use in tests. + """ httplib2.Http = HttpMock self.client = Github() def tearDown(self): - """Remove test fixtures + """Remove test fixtures. `httplib2.Http` is returned to its original state. + """ httplib2.Http = ORIG_HTTP_OBJECT class HttpMockAuthenticatedTestCase(HttpMockTestCase): def setUp(self): - """Prepare test fixtures + """Prepare test fixtures. :see: :class:`HttpMockTestCase` :attr:`client` is an authenticated :obj:`Github` object for easy use in tests. + """ httplib2.Http = HttpMock self.client = Github(access_token='xxx') From 0010b09bb1d4b71ef98b55c67bbe8249557df394 Mon Sep 17 00:00:00 2001 From: James Rowe Date: Wed, 16 May 2012 19:42:29 +0100 Subject: [PATCH 04/10] Mark rate limit test with 'slow' attribute. --- tests/test_unit.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_unit.py b/tests/test_unit.py index 2095952..5a5b55c 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -11,6 +11,7 @@ import unittest from nose.tools import (eq_, ok_) +from nose.plugins.attrib import attr from github2.core import repr_string from github2.issues import Issue @@ -45,6 +46,7 @@ class RateLimits(utils.HttpMockTestCase): """Test API rate-limitting.""" + @attr('slow') def test_delays(self): """Test call delay is at least one second.""" client = Github(requests_per_second=.5) From e1b7047a1439346c1d5a83cb497b0c1478cfd73d Mon Sep 17 00:00:00 2001 From: James Rowe Date: Wed, 16 May 2012 19:43:10 +0100 Subject: [PATCH 05/10] Rewrite issue 50 test without using Http mock. --- tests/test_regression.py | 14 ++++---------- tests/utils.py | 11 ++--------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/tests/test_regression.py b/tests/test_regression.py index d9de696..b5fee60 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -9,20 +9,14 @@ from github2.client import Github -import utils - def test_issue_50(): """Erroneous init of ``Http`` with proxy setup. See https://github.com/ask/python-github2/pull/50 """ - utils.set_http_mock() - client = Github(proxy_host="my.proxy.com", proxy_port=9000) - setup_args = client.request._http.called_with - eq_(type(setup_args['proxy_info']), httplib2.ProxyInfo) - eq_(setup_args['proxy_info'].proxy_host, 'my.proxy.com') - eq_(setup_args['proxy_info'].proxy_port, 9000) - - utils.unset_http_mock() + proxy_info = client.request._http.proxy_info + eq_(type(proxy_info), httplib2.ProxyInfo) + eq_(proxy_info.proxy_host, 'my.proxy.com') + eq_(proxy_info.proxy_port, 9000) diff --git a/tests/utils.py b/tests/utils.py index 1b38949..e66284b 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -31,15 +31,8 @@ class HttpMock(object): """ - def __init__(self, cache=None, timeout=None, proxy_info=None, - ca_certs=None): - """Create a mock httplib.Http object - - .. attribute: called_with - - ``locals()`` during ``__init__``, for testing call spec - """ - self.called_with = locals() + def __init__(self, *args, **kwargs): + pass def request(self, uri, method='GET', body=None, headers=None, redirections=5, connection_type=None): From 6035cc3784543650fa8c9a731908c1b49d327cb4 Mon Sep 17 00:00:00 2001 From: James Rowe Date: Wed, 16 May 2012 19:45:03 +0100 Subject: [PATCH 06/10] Http mocking switched to use mock.Mock object. --- extra/requirements-test.txt | 1 + tests/utils.py | 58 +++++++++++++------------------------ 2 files changed, 21 insertions(+), 38 deletions(-) diff --git a/extra/requirements-test.txt b/extra/requirements-test.txt index c8d6b88..d271169 100644 --- a/extra/requirements-test.txt +++ b/extra/requirements-test.txt @@ -1,3 +1,4 @@ -r requirements.txt coverage>=3.5 +mock>=0.7.1 nose>=1.1.2 diff --git a/tests/utils.py b/tests/utils.py index e66284b..313836e 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -11,6 +11,8 @@ import httplib2 +from mock import Mock + from github2.client import Github from github2.request import charset_from_headers @@ -19,32 +21,26 @@ bytes = lambda x, enc: x -HTTP_DATA_DIR = "tests/data/" - -ORIG_HTTP_OBJECT = httplib2.Http +ORIG_REQUEST_METHOD = httplib2.Http.request -class HttpMock(object): - """Simple Http mock that returns saved entries. +def request_mock(uri, method='GET', body=None, headers=None, + redirections=5, connection_type=None): + """Http mock side effect that returns saved entries. Implementation tests should never span network boundaries. """ - def __init__(self, *args, **kwargs): - pass - - def request(self, uri, method='GET', body=None, headers=None, - redirections=5, connection_type=None): - file = os.path.join(HTTP_DATA_DIR, httplib2.safename(uri)) - if os.path.exists(file): - response = message_from_file(open(file)) - headers = httplib2.Response(response) - body = bytes(response.get_payload(), charset_from_headers(headers)) - return (headers, body) - else: - return (httplib2.Response({"status": "404"}), - "Resource %r unavailable from test data store" % file) + file = os.path.join("tests/data", httplib2.safename(uri)) + if os.path.exists(file): + response = message_from_file(open(file)) + headers = httplib2.Response(response) + body = bytes(response.get_payload(), charset_from_headers(headers)) + return (headers, body) + else: + return (httplib2.Response({"status": "404"}), + "Resource %r unavailable from test data store" % file) class HttpMockTestCase(unittest.TestCase): @@ -58,7 +54,8 @@ def setUp(self): in tests. """ - httplib2.Http = HttpMock + httplib2.Http.request = Mock(spec_set=httplib2.Http.request, + side_effect=request_mock) self.client = Github() def tearDown(self): @@ -67,7 +64,7 @@ def tearDown(self): `httplib2.Http` is returned to its original state. """ - httplib2.Http = ORIG_HTTP_OBJECT + httplib2.Http.request = ORIG_REQUEST_METHOD class HttpMockAuthenticatedTestCase(HttpMockTestCase): @@ -80,21 +77,6 @@ def setUp(self): in tests. """ - httplib2.Http = HttpMock + httplib2.Http.request = Mock(spec_set=httplib2.Http.request, + side_effect=request_mock) self.client = Github(access_token='xxx') - - -def set_http_mock(): - """Function to enable ``Http`` mock - - This is useful in simple `nose`-compliant test functions - """ - httplib2.Http = HttpMock - - -def unset_http_mock(): - """Function to disable ``Http`` mock - - :see: :func:`set_http_mock` - """ - httplib2.Http = ORIG_HTTP_OBJECT From 62472a34b18636219c286e2b9770ed8b4cfae5c6 Mon Sep 17 00:00:00 2001 From: James Rowe Date: Wed, 16 May 2012 20:48:07 +0100 Subject: [PATCH 07/10] Added test for requires_auth decorator. --- tests/test_unit.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/test_unit.py b/tests/test_unit.py index 5a5b55c..988d8d6 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -10,10 +10,10 @@ import datetime import unittest -from nose.tools import (eq_, ok_) +from nose.tools import (eq_, ok_, raises) from nose.plugins.attrib import attr -from github2.core import repr_string +from github2.core import (AuthError, repr_string, requires_auth) from github2.issues import Issue from github2.client import Github @@ -97,3 +97,12 @@ def test_repr_string(): eq_(repr_string('test'), 'test') eq_(repr_string('abcdefghijklmnopqrst'), 'abcdefghijklmnopqrst') eq_(repr_string('abcdefghijklmnopqrstu'), 'abcdefghijklmnopq...') + + +class RequiresAuth(utils.HttpMockTestCase): + @raises(AuthError) + def test_no_auth(self): + f = lambda: None + f.__doc__ = 'test func' + wrapped = requires_auth(f) + wrapped(self.client) From fd2a2ba8196a7150fa90cb882fd6806265bc8f3e Mon Sep 17 00:00:00 2001 From: James Rowe Date: Wed, 16 May 2012 20:59:13 +0100 Subject: [PATCH 08/10] Added BaseData dict key failure test. --- tests/test_unit.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_unit.py b/tests/test_unit.py index 988d8d6..50312d0 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -86,6 +86,11 @@ def test_getitem(self): eq_(user['login'], user.login) eq_(user['name'], user.name) + @raises(KeyError) + def test_getitem_failure(self): + user = self.client.users.show('defunkt') + ok_(user['invalid_key']) + def test_project_for_user_repo(): client = Github() From fbe6e453a5d828c9317642f5647ea47e32da4670 Mon Sep 17 00:00:00 2001 From: James Rowe Date: Wed, 16 May 2012 21:07:25 +0100 Subject: [PATCH 09/10] Added BaseData dict setting tests. --- tests/test_unit.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/test_unit.py b/tests/test_unit.py index 50312d0..d49dc38 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -75,7 +75,7 @@ def test_iter(self): class BaseDataDict(utils.HttpMockTestCase): - """Test __getitem__ availability on objects.""" + """Test dict compatibility on objects.""" def test_getitem(self): user = self.client.users.show('defunkt') @@ -91,6 +91,16 @@ def test_getitem_failure(self): user = self.client.users.show('defunkt') ok_(user['invalid_key']) + def test_setitem(self): + user = self.client.users.show('defunkt') + user['blog'] = 'http://example.com' + eq_(user['blog'], 'http://example.com') + + @raises(KeyError) + def test_setitem_failure(self): + user = self.client.users.show('defunkt') + user['invalid_key'] = 'test' + def test_project_for_user_repo(): client = Github() From 5c60b01d58359da94c11c4e8cd016050185a8fa8 Mon Sep 17 00:00:00 2001 From: James Rowe Date: Wed, 16 May 2012 21:54:45 +0100 Subject: [PATCH 10/10] Use mock for sleep in rate limit tests. --- tests/test_unit.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/tests/test_unit.py b/tests/test_unit.py index d49dc38..104256d 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -7,11 +7,10 @@ # This file is part of python-github2, and is made available under the 3-clause # BSD license. See LICENSE for the full details. -import datetime import unittest +from mock import patch from nose.tools import (eq_, ok_, raises) -from nose.plugins.attrib import attr from github2.core import (AuthError, repr_string, requires_auth) from github2.issues import Issue @@ -44,23 +43,17 @@ def test_non_standard_host(self): class RateLimits(utils.HttpMockTestCase): - """Test API rate-limitting.""" + """Test API rate-limiting.""" - @attr('slow') - def test_delays(self): - """Test call delay is at least one second.""" + @patch('github2.request.time.sleep') + def test_delays(self, sleep): + """Test calls in quick succession are delayed.""" client = Github(requests_per_second=.5) client.users.show('defunkt') - start = datetime.datetime.utcnow() client.users.show('mojombo') - end = datetime.datetime.utcnow() - delta = end - start - delta_seconds = delta.days * 24 * 60 * 60 + delta.seconds - - ok_(delta_seconds >= 2, - "Expected .5 reqs per second to require a 2 second delay between " - "calls.") + # 0.5 requests per second, means a two second delay + sleep.assert_called_once_with(2.0) class BaseDataIter(utils.HttpMockTestCase):