|
6 | 6 | import github3
|
7 | 7 | import json
|
8 | 8 | import os.path
|
| 9 | +import sys |
9 | 10 | import pytest
|
10 | 11 | import unittest
|
11 | 12 |
|
@@ -173,7 +174,7 @@ class has a dummy ``__iter__`` implementation which we want for
|
173 | 174 | # Retrieve a mocked session object
|
174 | 175 | session = super(UnitIteratorHelper, self).create_mocked_session(*args)
|
175 | 176 | # Initialize a NullObject which has magical properties
|
176 |
| - null = github3.null.NullObject() |
| 177 | + null = NullObject() |
177 | 178 | # Set it as the return value for every method
|
178 | 179 | session.delete.return_value = null
|
179 | 180 | session.get.return_value = null
|
@@ -263,3 +264,59 @@ def setUp(self):
|
263 | 264 | # internet
|
264 | 265 | self.instance._build_url = self.build_url
|
265 | 266 | 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 |
0 commit comments