示例#1
0
 def test_log(self, logged_obj):
     log = Logger()
     log += logged_obj
     logged = log.log()
     inner_dict = logged['pytest']['test_logging']['DummyLoggable']
     assert inner_dict['prop'] == (logged_obj.prop, 'scalar')
     assert inner_dict['proplist'] == (logged_obj.proplist, 'sequence')
示例#2
0
    def test_isub(self, logged_obj, base_namespace):

        # Test when given string
        log = Logger()
        log += logged_obj
        log -= 'pytest'
        assert len(log) == 0
        log += logged_obj
        log -= 'eg'
        assert len(log) == 2

        # Test when given a namespace
        log -= base_namespace + ('prop', )
        assert base_namespace + ('prop', ) not in log
        assert len(log) == 1

        # Test with list of namespaces
        log += logged_obj
        rm_nsp = [base_namespace + (name, ) for name in ['prop', 'proplist']]
        log -= rm_nsp
        for nsp in rm_nsp:
            assert nsp not in log
        assert len(log) == 0

        # Test with obj
        log += logged_obj
        log -= logged_obj
        assert len(log) == 0
示例#3
0
    def test_remove(self, logged_obj, base_namespace):

        # Test removing all properties
        prop_namespace = base_namespace + ('prop', )
        list_namespace = base_namespace + ('proplist', )
        log = Logger()
        log.add(logged_obj)
        log.remove(logged_obj)
        assert len(log) == 0
        assert prop_namespace not in log
        assert list_namespace not in log

        # Test removing select properties
        log = Logger()
        log.add(logged_obj)
        log.remove(logged_obj, 'prop')
        assert len(log) == 1
        assert prop_namespace not in log
        assert list_namespace in log

        log = Logger()
        log.add(logged_obj)
        log.remove(logged_obj, ['prop', 'proplist'])
        assert len(log) == 0
        assert prop_namespace not in log
        assert list_namespace not in log

        # Test remove just given namespaces
        prop_namespace = base_namespace + ('prop', )
        log = Logger()
        log.add(logged_obj)
        log.remove(quantities=[prop_namespace])
        assert len(log) == 1
        assert prop_namespace not in log
        assert list_namespace in log

        # Test remove when not in initial namespace
        log = Logger()
        log[prop_namespace] = (lambda: None, '__call__', 'scalar')
        log.add(logged_obj)
        assert len(log) == 3
        log.remove(logged_obj, 'prop')
        assert len(log) == 2
        assert prop_namespace in log
        assert list_namespace in log
        assert prop_namespace[:-2] + (prop_namespace[-2] + '_1',
                                      prop_namespace[-1]) not in log
示例#4
0
def blank_logger():
    return Logger()