Esempio n. 1
0
 def test_only_listens_to_its_collector_named(self, limit_cls):
     listened_to = limit_cls.collector_cls(id_='has listener')
     unlistened = limit_cls.collector_cls(id_='no listeners')
     limit = self.get_call_capturing_limit(
         limit_cls=limit_cls, collector_id='has listener')
     results_collected.send(
         sender=listened_to, results=[5], context={'should': 'receive'})
     results_collected.send(
         sender=unlistened, results=[6], context={'not': 'received'})
     assert len(limit.calls) == 1
     assert limit.calls == [
         {'results': [5], 'context': {'should': 'receive'}},
     ]
Esempio n. 2
0
def test_writer_only_writes_when_end_is_called(tmpfilepath):
    writer = serializer.Writer(tmpfilepath)
    writer.start()
    results_collected.send(sender=WithId('after start'),
                           results=[2],
                           context={'after': 'start'})
    reader = serializer.Reader(tmpfilepath)
    deserialized = reader.read_all()
    try:
        assert deserialized == []
    finally:
        writer.end()
    deserialized = reader.read_all()
    assert deserialized == [(WithId('after start'), [2], {'after': 'start'})]
Esempio n. 3
0
 def test_only_listens_to_its_collector_anonymous(self, limit_cls):
     limit = self.get_call_capturing_limit(limit_cls=limit_cls)
     listened_to = limit.collector
     unlistened = limit_cls.collector_cls(id_='no listeners')
     with limit:
         results_collected.send(
             sender=listened_to, results=[99],
             context={'should': 'receive'})
         results_collected.send(
             sender=unlistened, results=[55],
             context={'not': 'received'})
         assert len(limit.calls) == 1
         assert limit.calls == [
             {'results': [99], 'context': {'should': 'receive'}},
         ]
Esempio n. 4
0
def test_roundtrip_serialization_single_results(tmpfilepath, sender_id,
                                                sender_type, sample_result):
    sender = FakeSender(id_=sender_id, type_name=sender_type)
    context = {
        'setUp method': ['setUp (some.module.TestCase'],
    }
    writer = serializer.Writer(tmpfilepath)
    writer.start()
    results_collected.send(sender=sender,
                           results=sample_result,
                           context=context)
    writer.end()
    reader = serializer.Reader(tmpfilepath)
    deserialized = reader.read_all()
    assert deserialized == [(sender, sample_result, context)]
Esempio n. 5
0
    def test_only_listens_to_its_own_typed_collector(self, limit_cls):
        id_ = 'id to listen to'

        class OtherCollectorType(BaseCollector):
            pass

        listened_to = limit_cls.collector_cls(id_=id_)
        unlistened = OtherCollectorType(id_=id_)
        limit = self.get_call_capturing_limit(
            limit_cls=limit_cls, collector_id=id_)
        results_collected.send(
            sender=listened_to, results=[1], context={'should': 'receive'})
        results_collected.send(
            sender=unlistened, results=[2], context={'not': 'received'})
        assert len(limit.calls) == 1
        assert limit.calls == [
            {'results': [1], 'context': {'should': 'receive'}},
        ]
Esempio n. 6
0
def test_read_all_fires_results_read_signals(tmpfilepath):
    writer = serializer.Writer(tmpfilepath)
    writer.start()
    results_collected.send(sender=WithId('after start'),
                           results=[2],
                           context={'after': 'start'})
    writer.end()
    results_from_results_read_signal = []

    def record_read_results(sender, results, context, **kwargs):
        results_from_results_read_signal.append((sender, results, context))

    results_read.connect(record_read_results)
    reader = serializer.Reader(tmpfilepath)
    deserialized = reader.read_all()
    try:
        assert deserialized != []
        assert results_from_results_read_signal != []
        assert results_from_results_read_signal == deserialized
    finally:
        results_read.disconnect(record_read_results)
Esempio n. 7
0
 def test_without_id_only_listens_while_a_context_manager(self, limit_cls):
     limit = self.get_call_capturing_limit(limit_cls=limit_cls)
     assert limit.collector_id is None
     results_collected.send(
         sender=limit.collector, results=[0],
         context={'before': 'context manager'})
     with limit:
         results_collected.send(
             sender=limit.collector, results=[1],
             context={'inside': 'context manager'})
         assert len(limit.calls) == 1
         assert limit.calls == [
             {'results': [1], 'context': {'inside': 'context manager'}},
         ]
     limit.calls = []
     results_collected.send(
         sender=limit.collector, results=[2],
         context={'after': 'context manager'})
     assert len(limit.calls) == 0
Esempio n. 8
0
    def test_listening_by_id_is_always_active(self, limit_cls):
        collector = limit_cls.collector_cls(id_='listen by id')
        limit = self.get_call_capturing_limit(
            limit_cls=limit_cls, collector_id='listen by id')
        results_collected.send(
            sender=collector, results=[0],
            context={'before': 'context manager'})
        with limit:
            results_collected.send(
                sender=collector, results=[1],
                context={'inside': 'context manager'})
        results_collected.send(
            sender=collector, results=[2],
            context={'after': 'context manager'})

        assert len(limit.calls) == 3
        assert limit.calls == [
            {'results': [0], 'context': {'before': 'context manager'}},
            {'results': [1], 'context': {'inside': 'context manager'}},
            {'results': [2], 'context': {'after': 'context manager'}},
        ]
Esempio n. 9
0
def test_writer_writes_collected_results_fired_between_statt_stop(tmpfilepath):
    writer = serializer.Writer(tmpfilepath)
    results_collected.send(sender=WithId('before start'),
                           results=[1],
                           context={'before': 'start'})
    writer.start()
    results_collected.send(sender=WithId('after start'),
                           results=[2],
                           context={'after': 'start'})
    writer.end()
    results_collected.send(sender=WithId('after end'),
                           results=[3],
                           context={'after': 'end'})
    reader = serializer.Reader(tmpfilepath)
    deserialized = reader.read_all()
    assert deserialized == [(WithId('after start'), [2], {'after': 'start'})]
    writer.end()  # dump data again
    reader = serializer.Reader(tmpfilepath)
    deserialized = reader.read_all()
    assert deserialized == \
        [(WithId('after start'), [2], {'after': 'start'})], \
        'after first writer.end it should have disonnected the signal'
Esempio n. 10
0
 def test_whatever_two(self):
     results_collected.send(sender=WithId('whatever'),
                            results=[2],
                            context={'test': 'two'})
Esempio n. 11
0
 def test_whatever_one(self):
     results_collected.send(sender=WithId('whatever'),
                            results=[1],
                            context={'test': 'one'})