<commit_before># -*- Mode: Python; test-case-name: flumotion.test.test_feedcomponent010 -*-
# vi:si:et:sw=4:sts=4:ts=4
#
# Flumotion - a streaming media server
# Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com).
# All rights reserved.

# This file may be distributed and/or modified under the terms of
# the GNU General Public License version 2 as published by
# the Free Software Foundation.
# This file is distributed without any warranty; without even the implied
# warranty of merchantability or fitness for a particular purpose.
# See "LICENSE.GPL" in the source distribution for more information.

# Licensees having purchased or holding a valid Flumotion Advanced
# Streaming Server license may use this file in accordance with the
# Flumotion Advanced Streaming Server Commercial License Agreement.
# See "LICENSE.Flumotion" in the source distribution for more information.

# Headers in this file shall remain intact.

from twisted.trial import unittest

import common

from twisted.python import failure
from twisted.internet import defer

from flumotion.component import feedcomponent010 as fc

class TestFeeder(unittest.TestCase):
    def setUp(self):
        self.feeder = fc.Feeder('video:default')

    def test_clientConnected(self):
        clientId = '/default/muxer-video'
        self.feeder.clientConnected(clientId, 3)
        clients = self.feeder.getClients()
        self.failUnless(3 in clients.keys())
        client = clients[3]
        self.assertEquals(client.uiState.get('clientId'), clientId)

    def testReconnect(self):
        clientId = '/default/muxer-video'

        # connect
        c = self.feeder.clientConnected(clientId, 3)

        # verify some stuff
        self.clientAssertStats(c, 0, 0, 0, 0, 1)

        # read 10 bytes, drop 1 buffer
        c.setStats((10, None, None, None, None, 1))
        self.clientAssertStats(c, 10, 1, 10, 1, 1)

        # disconnect
        self.feeder.clientDisconnected(3)
        self.clientAssertStats(c, 0, 0, 10, 1, 1)

        # connect again
        self.feeder.clientConnected(clientId, 3)
        self.clientAssertStats(c, 0, 0, 10, 1, 2)

        # read 20 bytes, drop 2 buffers
        c.setStats((20, None, None, None, None, 2))
        self.clientAssertStats(c, 20, 2, 30, 3, 2)

    def clientAssertEquals(self, client, key, value):
        self.assertEquals(client.uiState.get(key), value)

    def clientAssertStats(self, client, brc, bdc, brt, bdt, reconnects):
        self.clientAssertEquals(client, 'bytesReadCurrent', brc)
        self.clientAssertEquals(client, 'buffersDroppedCurrent', bdc)
        self.clientAssertEquals(client, 'bytesReadTotal', brt)
        self.clientAssertEquals(client, 'buffersDroppedTotal', bdt)
        self.clientAssertEquals(client, 'reconnects', reconnects)

if __name__ == '__main__':
    unittest.main()<commit_msg>fix unit test<commit_after># -*- Mode: Python; test-case-name: flumotion.test.test_feedcomponent010 -*-
# vi:si:et:sw=4:sts=4:ts=4
#
# Flumotion - a streaming media server
# Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com).
# All rights reserved.

# This file may be distributed and/or modified under the terms of
# the GNU General Public License version 2 as published by
# the Free Software Foundation.
# This file is distributed without any warranty; without even the implied
# warranty of merchantability or fitness for a particular purpose.
# See "LICENSE.GPL" in the source distribution for more information.

# Licensees having purchased or holding a valid Flumotion Advanced
# Streaming Server license may use this file in accordance with the
# Flumotion Advanced Streaming Server Commercial License Agreement.
# See "LICENSE.Flumotion" in the source distribution for more information.

# Headers in this file shall remain intact.

import time

from twisted.trial import unittest

import common

from twisted.python import failure
from twisted.internet import defer

from flumotion.component import feedcomponent010 as fc

class TestFeeder(unittest.TestCase):
    def setUp(self):
        self.feeder = fc.Feeder('video:default')

    def test_clientConnected(self):
        clientId = '/default/muxer-video'
        self.feeder.clientConnected(clientId, 3)
        clients = self.feeder.getClients()
        self.failUnless(3 in clients.keys())
        client = clients[3]
        self.assertEquals(client.uiState.get('clientId'), clientId)

    def testReconnect(self):
        clientId = '/default/muxer-video'

        # connect
        c = self.feeder.clientConnected(clientId, 3)

        # verify some stuff
        self.clientAssertStats(c, 0, 0, 0, 0, 1)

        # read 10 bytes, drop 1 buffer
        c.setStats((10, None, None, None, time.time(), 1))
        self.clientAssertStats(c, 10, 1, 10, 1, 1)

        # disconnect
        self.feeder.clientDisconnected(3)
        self.clientAssertStats(c, 0, 0, 10, 1, 1)

        # connect again
        self.feeder.clientConnected(clientId, 3)
        self.clientAssertStats(c, 0, 0, 10, 1, 2)

        # read 20 bytes, drop 2 buffers
        c.setStats((20, None, None, None, time.time(), 2))
        self.clientAssertStats(c, 20, 2, 30, 3, 2)

    def clientAssertEquals(self, client, key, value):
        self.assertEquals(client.uiState.get(key), value)

    def clientAssertStats(self, client, brc, bdc, brt, bdt, reconnects):
        self.clientAssertEquals(client, 'bytesReadCurrent', brc)
        self.clientAssertEquals(client, 'buffersDroppedCurrent', bdc)
        self.clientAssertEquals(client, 'bytesReadTotal', brt)
        self.clientAssertEquals(client, 'buffersDroppedTotal', bdt)
        self.clientAssertEquals(client, 'reconnects', reconnects)

if __name__ == '__main__':
    unittest.main()
{'fraction_non_alphanumeric': 0.09998264190244749, 'fraction_numerical': 0.02603714632876237, 'mean_word_length': 3.4391371340523884, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5756877', 'n_tokens_mistral': 1849, 'n_tokens_neox': 1696, 'n_words': 529}