Exemplo n.º 1
0
def test_counter_eq_derive():
    """Test parsing of counters when expecting derives and vice versa"""
    def run_parse(parse_func):
        def wrapped(data):
            return list(parse_func(data))

        return wrapped

    types = "false_counter value:COUNTER:U:U\nfalse_derive value:DERIVE:U:U\n"
    with t.unlinking(t.temp_file(TYPESDB + types)) as path:
        parser = bucky.collectd.CollectDParser(types_dbs=[path])
        for pkts_file in ('collectd-counter.pkts', 'collectd-derive.pkts'):
            for data in pkts(pkts_file):
                t.not_raises(ProtocolError, run_parse(parser.parse), data)
        for pkts_file in ('collectd-false-counter.pkts',
                          'collectd-false-derive.pkts'):
            for data in pkts(pkts_file):
                t.raises(ProtocolError, run_parse(parser.parse), data)

        parser = bucky.collectd.CollectDParser(types_dbs=[path],
                                               counter_eq_derive=True)
        for pkts_file in ('collectd-counter.pkts', 'collectd-derive.pkts',
                          'collectd-false-counter.pkts',
                          'collectd-false-derive.pkts'):
            for data in pkts(pkts_file):
                t.not_raises(ProtocolError, run_parse(parser.parse), data)
Exemplo n.º 2
0
def test_counter_eq_derive():
    """Test parsing of counters when expecting derives and vice versa"""

    def run_parse(parse_func):
        def wrapped(data):
            return list(parse_func(data))

        return wrapped

    types = "false_counter value:COUNTER:U:U\nfalse_derive value:DERIVE:U:U\n"
    with t.unlinking(t.temp_file(TYPESDB + types)) as path:
        parser = bucky.collectd.CollectDParser(types_dbs=[path])
        for pkts_file in ('collectd-counter.pkts', 'collectd-derive.pkts'):
            for data in pkts(pkts_file):
                t.not_raises(ProtocolError, run_parse(parser.parse), data)
        for pkts_file in ('collectd-false-counter.pkts',
                          'collectd-false-derive.pkts'):
            for data in pkts(pkts_file):
                t.raises(ProtocolError, run_parse(parser.parse), data)

        parser = bucky.collectd.CollectDParser(types_dbs=[path],
                                               counter_eq_derive=True)
        for pkts_file in ('collectd-counter.pkts', 'collectd-derive.pkts',
                          'collectd-false-counter.pkts',
                          'collectd-false-derive.pkts'):
            for data in pkts(pkts_file):
                t.not_raises(ProtocolError, run_parse(parser.parse), data)
Exemplo n.º 3
0
def test_file_monitor():
    with t.unlinking(t.temp_file('asd')) as path:
        monitor = bucky.helpers.FileMonitor(path)
        t.eq(monitor.modified(), False)
        with open(path, 'w') as f:
            f.write('bbbb')
        time.sleep(1)
        t.eq(monitor.modified(), True)
        t.eq(monitor.modified(), False)