8000 Fix up our tests while removing NullObject · ucbjrl/github3.py@9eb136d · GitHub
[go: up one dir, main page]

Skip to content

Commit 9eb136d

Browse files
committed
Fix up our tests while removing NullObject
1 parent 9cab370 commit 9eb136d

File tree

3 files changed

+58
-65
lines changed

3 files changed

+58
-65
lines changed

tests/unit/helper.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import github3
77
import json
88
import os.path
9+
import sys
910
import pytest
1011
import unittest
1112

@@ -173,7 +174,7 @@ class has a dummy ``__iter__`` implementation which we want for
173174
# Retrieve a mocked session object
174175
session = super(UnitIteratorHelper, self).create_mocked_session(*args)
175176
# Initialize a NullObject which has magical properties
176-
null = github3.null.NullObject()
177+
null = NullObject()
177178
# Set it as the return value for every method
178179
session.delete.return_value = null
179180
session.get.return_value = null
@@ -263,3 +264,59 @@ def setUp(self):
263264
# internet
264265
self.instance._build_url = self.build_url
265266
self.after_setup()
267+
268+
269+
is_py3 = (3, 0) <= sys.version_info < (4, 0)
270+
271+
272+
class NullObject(object):
273+
def __init__(self, initializer=None):
274+
self.__dict__['initializer'] = initializer
275+
276+
def __int__(self):
277+
return 0
278+
279+
def __bool__(self):
280+
return False
281+
282+
__nonzero__ = __bool__
283+
284+
def __str__(self):
285+
return ''
286+
287+
def __unicode__(self):
288+
return '' if is_py3 else ''.decode()
289+
290+
def __repr__(self):
291+
return '<NullObject({0})>'.format(
292+
repr(self.__getattribute__('initializer'))
293+
)
294+
295+
def __getitem__(self, index):
296+
return self
297+
298+
def __setitem__(self, index, value):
299+
pass
300+
301+
def __getattr__(self, attr):
302+
return self
303+
304+
def __setattr__(self, attr, value):
305+
pass
306+
307+
def __call__(self, *args, **kwargs):
308+
return self
309+
310+
def __contains__(self, other):
311+
return False
312+
313+
def __iter__(self):
314+
return iter([])
315+
316+
def __next__(self):
317+
raise StopIteration
318+
319+
next = __next__
320+
321+
def is_null(self):
322+
return True

tests/unit/test_null.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

tests/unit/test_repos_repo.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from base64 import b64encode
77
from github3 import GitHubError
8-
from github3.null import NullObject
98
from github3.repos.repo import (Comparison, Contents, Hook, RepoComment,
109
RepoCommit, Repository)
1110
from github3.models import GitHubCore
@@ -80,7 +79,6 @@ def test_add_collaborator(self):
8079
def test_add_null_collaborator(self):
8180
"""Verify no request is made when adding `None` as a collaborator."""
8281
self.instance.add_collaborator(None)
83-
self.instance.add_collaborator(NullObject())
8482

8583
assert self.session.put.called is False
8684

0 commit comments

Comments
 (0)
0