Changeset 164

Show
Ignore:
Timestamp:
17.04.2008 02:57:10 (9 months ago)
Author:
elghinn
Message:

* added tests for DictWrapper? and DotDesktop? (and fixed them)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/pycawm/dotdesktop.py

    r163 r164  
    3838    raise ImportError('dotdesktop module needs at least Python 2.5!') 
    3939 
    40 from ConfigParser import RawConfigParser 
     40from ConfigParser import MissingSectionHeaderError, RawConfigParser 
    4141from dircache import listdir 
    4242from operator import itemgetter 
     
    5555            return None 
    5656        config = RawConfigParser() 
    57         config.read(filepath) 
     57        try: 
     58            config.read(filepath) 
     59        except MissingSectionHeaderError: 
     60            return None 
    5861        # Type, Name, Exec options are required and Type must be "Application" 
    5962        if not (config.has_option('Desktop Entry', 'Type') and 
  • trunk/pycawm/patterns.py

    r140 r164  
    114114        return '%s(%s)' % (self.__class__, repr(self._data)) 
    115115 
     116    def __nonzero__(self): 
     117        return True if len(self._data) else False 
     118 
     119    def __len__(self): 
     120        return len(self._data) 
     121 
    116122    def __cmp__(self, other): 
    117123        if isinstance(other, DictWrapper): 
  • trunk/tests/patterns.test

    r58 r164  
    5858 
    5959>>> if a: print "nonzero!" 
     60 
     613) The DictWrapper 
     62 
     63>>> from pycawm.patterns import DictWrapper 
     64>>> a = DictWrapper() 
     65>>> if a: print "nonzero!" 
     66>>> len(a) 
     670 
     68>>> a.foo 
     69Traceback (most recent call last): 
     70  File "...", line 1, in ... 
     71  File "...", line ..., in __getattr__ 
     72    raise AttributeError(attr) 
     73AttributeError: foo 
     74>>> a.foo = 42 
     75>>> a.foo 
     7642 
     77>>> a['foo'] 
     7842 
     79>>> a['bar'] = 21 
     80>>> a.bar 
     8121 
     82>>> if a: print "nonzero!" 
     83nonzero! 
     84>>> len(a) 
     852 
     86 
     87>>> b = DictWrapper() 
     88>>> a is b 
     89False 
     90>>> a == b 
     91False 
     92>>> b.foo = 42 
     93>>> b.bar = 21 
     94>>> a is b 
     95False 
     96>>> a == b 
     97True 
     98 
     99>>> c = DictWrapper(recursive=True) 
     100>>> if c: print "nonzero!" 
     101>>> len(c) 
     1020 
     103>>> c.foo 
     104<class 'pycawm.patterns.DictWrapper'>({}) 
     105>>> c.foo == c.bar.foo 
     106True 
     107>>> c.foo is c.bar.foo 
     108False 
     109>>> c.baz.foo.bar.foobar.barbaz.marvin 
     110<class 'pycawm.patterns.DictWrapper'>({}) 
     111>>> c.baz['foo'].bar['foobar'].barbaz['marvin'] = 42 
     112>>> c['baz'].foo['bar'].foobar['barbaz'].marvin 
     11342 
     114>>> if c: print "nonzero!" 
     115nonzero! 
     116>>> len(c) 
     1173 
     118 
     119>>> d = DictWrapper(recursive=True) 
     120>>> d.baz.foo.bar.foobar.barbaz.marvin = 42 
     121>>> c == d 
     122False 
     123>>> d.foo 
     124<class 'pycawm.patterns.DictWrapper'>({}) 
     125>>> d.bar.foo 
     126<class 'pycawm.patterns.DictWrapper'>({}) 
     127>>> c == d 
     128True 
     129