# Path: spec/ui/_fixture.py
# def update_environment(_):
#     _.bad_expression = '?'
#     _.expression = 'richard stallman'
# 
#     _.env_path = '/tmp/testing-sandbox'
#     _.env = TestFileEnvironment(_.env_path)
# 
#     _.fixtures = 'fixtures'
#     _.fixtures_path = '/tmp/ipodio_fixtures'
# 
#     if not os.path.isdir(_.fixtures_path):
#         shutil.copytree(_.fixtures, _.fixtures_path)
# 
#     _.songs = ['fixtures/song1.mp3', 'fixtures/song2.mp3']
#     _.song_paths = [os.path.abspath(song) for song in _.songs]
# 
#     _.mountpoint = 'ipod'
#     _.mountpoint_path = os.path.join(_.env_path, _.mountpoint)
#     _.cmd = ['ipodio', '--mount', _.mountpoint]


import re
import os
import shutil
from expects import expect
from mamba import describe, context, before, after
from spec.ui._ipod_helpers import *
from spec.ui._fixture import update_environment
# -*- coding: utf-8 -*-





with describe('ipodio pull') as _:

    @before.all
    def setup_all():
        update_environment(_)
        bootstrap_ipod(_.mountpoint_path)
        populate_ipod(_.mountpoint_path, _.songs)
        _.execution = _.env.run(*_.cmd + ['pull'])

    @after.all
    def cleanup():
        shutil.rmtree(_.env_path)

    def should_copy_selected_songs_to_the_current_directory():
        copied_songs = [path for path in _.execution.files_created if path.endswith('.mp3')]

        expect(copied_songs).to.have.length(2)

    def should_name_copied_songs_using_number_title_album_artist():
        pattern = re.compile('^(\d+)?_([\s\w]+)?_([\s\w]+)?_([\s\w]+)?.mp3$')
        copied_songs = [path for path in _.execution.files_created if pattern.match(os.path.basename(path))]


# Path: spec/ui/_fixture.py
# def update_environment(_):
#     _.bad_expression = '?'
#     _.expression = 'richard stallman'
# 
#     _.env_path = '/tmp/testing-sandbox'
#     _.env = TestFileEnvironment(_.env_path)
# 
#     _.fixtures = 'fixtures'
#     _.fixtures_path = '/tmp/ipodio_fixtures'
# 
#     if not os.path.isdir(_.fixtures_path):
#         shutil.copytree(_.fixtures, _.fixtures_path)
# 
#     _.songs = ['fixtures/song1.mp3', 'fixtures/song2.mp3']
#     _.song_paths = [os.path.abspath(song) for song in _.songs]
# 
#     _.mountpoint = 'ipod'
#     _.mountpoint_path = os.path.join(_.env_path, _.mountpoint)
#     _.cmd = ['ipodio', '--mount', _.mountpoint]


# Path: spec/ui/pull_spec.py
import re
import os
import shutil
from expects import expect
from mamba import describe, context, before, after
from spec.ui._ipod_helpers import *
from spec.ui._fixture import update_environment

# -*- coding: utf-8 -*-





with describe('ipodio pull') as _:

    @before.all
    def setup_all():
        update_environment(_)
        bootstrap_ipod(_.mountpoint_path)
        populate_ipod(_.mountpoint_path, _.songs)
        _.execution = _.env.run(*_.cmd + ['pull'])

    @after.all
    def cleanup():
        shutil.rmtree(_.env_path)

    def should_copy_selected_songs_to_the_current_directory():
        copied_songs = [path for path in _.execution.files_created if path.endswith('.mp3')]

        expect(copied_songs).to.have.length(2)

    def should_name_copied_songs_using_number_title_album_artist():
        pattern = re.compile('^(\d+)?_([\s\w]+)?_([\s\w]+)?_([\s\w]+)?.mp3$')
        copied_songs = [path for path in _.execution.files_created if pattern.match(os.path.basename(path))]


        expect(copied_songs).to.have.length(2)