Ejemplo n.º 1
0
def test_mp3gen_with_non_empty_music_listing():
    """test func."""
    music_item = mock.Mock()
    with mock.patch('melissa.actions.play_music.sys') \
            as m_sys, \
            mock.patch('sys.stdout', new_callable=StringIO) \
            as m_stdout, \
            mock.patch('melissa.actions.play_music.os') \
            as m_os:
        # run
        from melissa.actions import play_music
        play_music.music_listing = [[music_item]]
        play_music.mp3gen()
        assert play_music.music_listing == [[music_item]]
        assert not m_sys.mock_calls
        assert '' == m_stdout.getvalue()
        assert not m_os.mock_calls
Ejemplo n.º 2
0
def test_mp3gen(platform, m_file_ext):
    """test func."""
    m_music_path = 'm_music_path'
    splitext_retval = ['filename', m_file_ext]
    m_root = mock.Mock()
    m_file = mock.Mock()
    walk_retval = [(m_root, None, [m_file])]
    with mock.patch('melissa.actions.play_music.sys') \
            as m_sys, \
            mock.patch('sys.stdout', new_callable=StringIO) \
            as m_stdout, \
            mock.patch('melissa.actions.play_music.os') \
            as m_os:
        # pre run
        m_os.path.splitext.return_value = splitext_retval
        m_os.walk.return_value = walk_retval
        m_sys.platform = platform
        # run
        from melissa.actions import play_music
        play_music.profile.data = {'music_path': m_music_path}
        play_music.music_listing = None
        play_music.mp3gen()
        # test
        cmd = None
        if platform in ('win32', 'linux') and m_file_ext == '.mp3':
            cmd = 'mpg123'
        elif platform in ('win32', 'linux') and \
                m_file_ext in play_music.sox_file_types:
            cmd = 'play'
        elif platform == 'darwin' and m_file_ext == '.mp3':
            cmd = 'afplay'
        if platform == 'random':
            assert \
                'Music only enabled on darwin, win32, and linux.' in \
                m_stdout.getvalue()
            m_file.assert_not_called()
            assert not m_os.mock_calls
        else:
            if m_file_ext == '.mp3':
                m_os.assert_has_calls([
                    mock.call.walk(m_music_path),
                    mock.call.path.splitext(m_file),
                    mock.call.path.join(m_root, m_file.lower.return_value),
                ])
            elif m_file_ext in play_music.sox_file_types:
                m_os.assert_has_calls([
                    mock.call.walk(m_music_path),
                    mock.call.path.splitext(m_file),
                    mock.call.path.splitext(m_file)
                ])
            if cmd is not None:
                assert play_music.music_listing == [[
                    cmd, m_os.path.join.return_value]]
                m_file.lower.assert_called_once_with()
            else:
                assert not m_file.mock_calls
                m_os.assert_has_calls([
                    mock.call.walk(m_music_path),
                    mock.call.path.splitext(m_file),
                    mock.call.path.splitext(m_file)
                ])