8000 Finish covering the repos module. · jsullivanlive/github3.py@fdb1196 · GitHub
[go: up one dir, main page]

Skip to content

Commit fdb1196

Browse files
committed
Finish covering the repos module.
1 parent 7bbc084 commit fdb1196

File tree

2 files changed

+69
-11
lines changed

2 files changed

+69
-11
lines changed

github3/repos.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,11 @@ def __init__(self, compare):
18151815
self._ttl_commits = compare.get('total_commits')
18161816
self._commits = [RepoCommit(com, None) for com in
18171817
compare.get('commits')]
1818-
self._files = compare.get('files')
1818+
self._files = []
1819+
if compare.get('files'):
1820+
append = self._files.append
1821+
for f in compare.get('files'):
1822+
append(type('Comparison File', (object, ), f))
18191823

18201824
def __repr__(self):
18211825
return '<Comparison of {0} commits>'.format(self.total_commits)
@@ -1849,7 +1853,7 @@ def diff_url(self):
18491853

18501854
@property
18511855
def files(self):
1852-
"""List of dictionaries describing the files modified."""
1856+
"""List of objects describing the files modified."""
18531857
return self._files
18541858

18551859
@property

tests/test_repos.py

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,20 @@ def test_zipball_url(self):
444444
expect(self.tag.zipball_url).isinstance(base.str_test)
445445

446446

447+
def __test_files__(fd, sha):
448+
expect(fd.additions) > 0
449+
expect(fd.deletions) >= 0
450+
expect(fd.changes) == fd.additions + fd.deletions
451+
expect(fd.filename).isinstance(base.str_test)
452+
expect(fd.blob_url).isinstance(base.str_test)
453+
expect(fd.raw_url).isinstance(base.str_test)
454+
expect(fd.sha).isinstance(base.str_test)
455+
if sha:
456+
expect(fd.sha) == sha
457+
expect(fd.status) == 'modified'
458+
expect(fd.patch).isinstance(base.str_test)
459+
460+
447461
class TestRepoCommit(base.BaseTest):
448462
def __init__(self, methodName='runTest'):
449463
super(TestRepoCommit, self).__init__(methodName)
@@ -469,16 +483,56 @@ def test_deletions(self):
469483
def test_files(self):
470484
expect(self.commit.files).isinstance(list)
471485
expect(self.commit.files) > []
486+
self.expect_list_of_class(self.commit.files, type)
472487
for file in self.commit.files:
473-
expect(file.additions) > 0
474-
expect(file.deletions) > 0
475-
expect(file.changes) == file.additions + file.deletions
476-
expect(file.filename).isinstance(base.str_test)
477-
expect(file.blob_url).isinstance(base.str_test)
478-
expect(file.raw_url).isinstance(base.str_test)
479-
expect(file.sha) == self.sha
480-
expect(file.status) == 'modified'
481-
expect(file.patch).isinstance(base.str_test)
488+
__test_files__(file, self.sha)
482489

483490
def test_total(self):
484491
expect(self.commit.total) == 17
492+
493+
494+
class TestComparison(base.BaseTest):
495+
def __init__(self, methodName='runTest'):
496+
super(TestComparison, self).__init__(methodName)
497+
repo = self.g.repository(self.sigm, self.todo)
498+
self.comp = repo.compare_commits(
499+
'04d55444a3ec06ca8d2aa0a5e333cdaf27113254',
500+
'731691616b71258c7ad7c141379856b5ebbab310'
501+
)
502+
503+
def test_ahead_by(self):
504+
expect(self.comp.ahead_by) > 0
505+
506+
def test_base_commit(self):
507+
expect(self.comp.base_commit).isinstance(RepoCommit)
508+
509+
def test_behind_by(self):
510+
expect(self.comp.behind_by) >= 0
511+
512+
def test_commits(self):
513+
self.expect_list_of_class(self.comp.commits, RepoCommit)
514+
515+
def test_diff_url(self):
516+
expect(self.comp.diff_url).isinstance(base.str_test)
517+
518+
def test_files(self):
519+
expect(self.comp.files).isinstance(list)
520+
expect(self.comp.files) > []
521+
self.expect_list_of_class(self.comp.files, type)
522+
for file in self.comp.files:
523+
__test_files__(file, '')
524+
525+
def test_html_url(self):
526+
expect(self.comp.html_url).isinstance(base.str_test)
527+
528+
def test_patch_url(self):
529+
expect(self.comp.patch_url).isinstance(base.str_test)
530+
531+
def test_permalink_url(self):
532+
expect(self.comp.permalink_url).isinstance(base.str_test)
533+
534+
def test_status(self):
535+
expect(self.comp.status) == 'ahead'
536+
537+
def test_total_commits(self):
538+
expect(self.comp.total_commits) == 18

0 commit comments

Comments
 (0)
0