<commit_before>
import os
import unittest

from PySide import QtCore
from PySide import phonon

from helper import UsesQCoreApplication

# XXX Hack to get the correct filename
example_file = os.path.join(os.path.dirname(__file__),'tone.ogg')

class TestSimplePlaying(UsesQCoreApplication):
    def setUp(self):
        super(TestSimplePlaying, self).setUp()
        self.app.setApplicationName('Dummy')
        self.source = phonon.Phonon.MediaSource(example_file)
        self.media = phonon.Phonon.MediaObject()
        self.media.setCurrentSource(self.source)

        QtCore.QObject.connect(self.media,
                QtCore.SIGNAL('finished()'),
                self.app,
                QtCore.SLOT('quit()'))

        self.called = False

        # prevent locking with:
        # request to play a stream, but no valid audio ...
        self.output = phonon.Phonon.AudioOutput()
        self.path = phonon.Phonon.createPath(self.media, self.output)

    def tearDown(self):
        super(TestSimplePlaying, self).tearDown()
        del self.path
        del self.output
        del self.media
        del self.source

    def testFinishedSignal(self):
        # Should pass if finished() is called
        self.media.play()
        self.app.exec_()

    def testMediaSource(self):
        self.assertEqual(self.media.currentSource(), self.source)

    def testPathCreation(self):
        # FIXME Both functions below are not exported by PyQt4
        self.assertEqual(self.path.sink(), self.output)
        self.assertEqual(self.path.source(), self.media)

    def state_cb(self, newState, OldState):
        self.called = True

    def testStateChanged(self):
        # Check for ogg support before playing it
        if (phonon.Phonon.BackendCapabilities.isMimeTypeAvailable('audio/ogg')):
            QtCore.QObject.connect(self.media,
                QtCore.SIGNAL('stateChanged(Phonon::State, Phonon::State)'),
                self.state_cb)

            self.media.play()
            self.app.exec_()
            self.assert_(self.called)
        else:
            print 'Ogg format not supported! Playback test skipped!'

if __name__ == '__main__':
    unittest.main()
<commit_msg>Only try to play the ogg file if the system has the capability to do it.<commit_after>
import os
import unittest

from PySide import QtCore
from PySide import phonon

from helper import UsesQCoreApplication

# XXX Hack to get the correct filename
example_file = os.path.join(os.path.dirname(__file__),'tone.ogg')

class TestSimplePlaying(UsesQCoreApplication):
    def setUp(self):
        super(TestSimplePlaying, self).setUp()
        self.app.setApplicationName('Dummy')
        self.source = phonon.Phonon.MediaSource(example_file)
        self.media = phonon.Phonon.MediaObject()
        self.media.setCurrentSource(self.source)

        QtCore.QObject.connect(self.media,
                QtCore.SIGNAL('finished()'),
                self.app,
                QtCore.SLOT('quit()'))

        self.called = False

        # prevent locking with:
        # request to play a stream, but no valid audio ...
        self.output = phonon.Phonon.AudioOutput()
        self.path = phonon.Phonon.createPath(self.media, self.output)

    def tearDown(self):
        super(TestSimplePlaying, self).tearDown()
        del self.path
        del self.output
        del self.media
        del self.source

    def testFinishedSignal(self):
        # Check for ogg support before playing it
        if (phonon.Phonon.BackendCapabilities.isMimeTypeAvailable('audio/ogg')):
            # Should pass if finished() is called
            self.media.play()
            self.app.exec_()
        else:
            print 'Ogg format not supported! Playback test skipped!'

    def testMediaSource(self):
        self.assertEqual(self.media.currentSource(), self.source)

    def testPathCreation(self):
        # FIXME Both functions below are not exported by PyQt4
        self.assertEqual(self.path.sink(), self.output)
        self.assertEqual(self.path.source(), self.media)

    def state_cb(self, newState, OldState):
        self.called = True

    def testStateChanged(self):
        # Check for ogg support before playing it
        if (phonon.Phonon.BackendCapabilities.isMimeTypeAvailable('audio/ogg')):
            QtCore.QObject.connect(self.media,
                QtCore.SIGNAL('stateChanged(Phonon::State, Phonon::State)'),
                self.state_cb)

            self.media.play()
            self.app.exec_()
            self.assert_(self.called)
        else:
            print 'Ogg format not supported! Playback test skipped!'

if __name__ == '__main__':
    unittest.main()

{'fraction_non_alphanumeric': 0.10087625561017312, 'fraction_numerical': 0.00042744176106005556, 'mean_word_length': 2.4718100890207717, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2868780', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1321, 'n_words': 311}