"Fossies" - the Fresh Open Source Software Archive

Member "roundup-2.0.0/test/mocknull.py" (26 Aug 2019, 1106 Bytes) of package /linux/www/roundup-2.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "mocknull.py": 1.6.1_vs_2.0.0.

    1 
    2 class MockNull:
    3     def __init__(self, **kwargs):
    4         for key, value in kwargs.items():
    5             self.__dict__[key] = value
    6 
    7     def __call__(self, *args, **kwargs): return MockNull()
    8     def __getattr__(self, name):
    9         # This allows assignments which assume all intermediate steps are Null
   10         # objects if they don't exist yet.
   11         #
   12         # For example (with just 'client' defined):
   13         #
   14         # client.db.config.TRACKER_WEB = 'BASE/'
   15         self.__dict__[name] = MockNull()
   16         return getattr(self, name)
   17 
   18     def __getitem__(self, key): return self
   19     def __bool__(self): return False
   20     # Python 2 compatibility:
   21     __nonzero__ = __bool__
   22     def __contains__(self, key): return False
   23     def __eq__(self, rhs): return False
   24     def __ne__(self, rhs): return False
   25     def __str__(self): return ''
   26     def __repr__(self): return '<MockNull 0x%x>'%id(self)
   27     def gettext(self, str): return str
   28     _ = gettext
   29     def get(self, name, default=None):
   30         try:
   31             return self.__dict__[name.lower()]
   32         except KeyError:
   33             return default