예제 #1
0
    def test_count(self):
        # A basic test of counts
        counter = cobe.counter.MergeCounter()

        def repeat(items):
            # Repeat each key of items as many times as its value
            for item, count in items.iteritems():
                for i in xrange(count):
                    yield item, 1

        counts = counter.count(repeat(self.items))
        self.assert_(isinstance(counts, types.GeneratorType))

        for item, count in counts:
            self.assertEqual(self.items[item], count)
예제 #2
0
    def test_count(self):
        # A basic test of counts
        counter = cobe.counter.MergeCounter()

        def repeat(items):
            # Repeat each key of items as many times as its value
            for item, count in items.iteritems():
                for i in xrange(count):
                    yield item, 1

        counts = counter.count(repeat(self.items))
        self.assert_(isinstance(counts, types.GeneratorType))

        for item, count in counts:
            self.assertEqual(self.items[item], count)
예제 #3
0
    def test_count_overflow(self):
        # Test counts, with restricted max_len. This forces an
        # overflow file to be written for every count logged.
        counter = cobe.counter.MergeCounter(max_len=1)

        def repeat(items):
            # Repeat each key of items as many times as its value
            for item, count in items.iteritems():
                for i in xrange(count):
                    yield item, 1

        counts = counter.count(repeat(self.items))
        self.assert_(isinstance(counts, types.GeneratorType))

        for item, count in counts:
            self.assertEqual(self.items[item], count)
예제 #4
0
    def test_count_overflow(self):
        # Test counts, with restricted max_len. This forces an
        # overflow file to be written for every count logged.
        counter = cobe.counter.MergeCounter(max_len=1)

        def repeat(items):
            # Repeat each key of items as many times as its value
            for item, count in items.iteritems():
                for i in xrange(count):
                    yield item, 1

        counts = counter.count(repeat(self.items))
        self.assert_(isinstance(counts, types.GeneratorType))

        for item, count in counts:
            self.assertEqual(self.items[item], count)
예제 #5
0
    def test_count_overflow_merge(self):
        # Test counts, with restricted max_len and max_fds. This
        # forces overflow files to be merged together on every logged
        # count.
        counter = cobe.counter.MergeCounter(max_fds=1, max_len=1)

        def repeat(items):
            # Repeat each key of items as many times as its value
            for item, count in items.iteritems():
                for i in xrange(count):
                    yield item, 1

        counts = counter.count(repeat(self.items))
        self.assert_(isinstance(counts, types.GeneratorType))

        for item, count in counts:
            self.assertEqual(self.items[item], count)
예제 #6
0
    def test_count_overflow_merge(self):
        # Test counts, with restricted max_len and max_fds. This
        # forces overflow files to be merged together on every logged
        # count.
        counter = cobe.counter.MergeCounter(max_fds=1, max_len=1)

        def repeat(items):
            # Repeat each key of items as many times as its value
            for item, count in items.iteritems():
                for i in xrange(count):
                    yield item, 1

        counts = counter.count(repeat(self.items))
        self.assert_(isinstance(counts, types.GeneratorType))

        for item, count in counts:
            self.assertEqual(self.items[item], count)