<commit_before># -*- coding: utf-8 -*-

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


with describe('ipodio list') as _:

    @before.all
    def setup_all():
        update_environment(_)
        bootstrap_ipod(_.mountpoint_path)

    def should_return_an_error_with_bad_expressions():
        execution = _.env.run(*_.cmd + ['list', _.bad_expression], expect_error=True)

        expect(execution.stdout).to.have("Error: Invalid expression")

    with context('when iPod is empty'):
        def should_print_nothing():
            execution = _.env.run(*_.cmd + ['list'])

            expect(execution.stdout).to.be.empty

    with context('when iPod has songs'):
        def should_print_a_header():
            execution = _.env.run(*_.cmd + ['list'])

            expect(execution.stdout).to.have('Title', 'Album', 'Artist')

        def should_print_a_line_per_song():
            execution = _.env.run(*_.cmd + ['list'])

            length_of_footer = 2
            length_of_header = 1
            number_of_songs = len(_.songs)
            stdout_lines = execution.stdout.split('\n')

            expect(stdout_lines).to.have.length(
                length_of_header + number_of_songs + length_of_footer)

        def should_print_a_line_per_song_when_filtering_using_expression():
            execution = _.env.run(*_.cmd + ['list'] + _.expression.split())

            length_of_footer = 2
            length_of_header = 1
            number_of_songs = 1
            stdout_lines = execution.stdout.split('\n')

            expect(stdout_lines).to.have.length(
                length_of_header + number_of_songs + length_of_footer)

        @before.all
        def setup():
            populate_ipod(_.mountpoint_path, _.songs)

        @after.all
        def cleanup():
            try:
                shutil.rmtree(_.mountpoint_path)
            except:
                pass<commit_msg>Small rewrite to the list command handler spec<commit_after># -*- coding: utf-8 -*-

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


with describe('ipodio list') as _:

    @before.all
    def setup_all():
        update_environment(_)
        bootstrap_ipod(_.mountpoint_path)

    def should_return_an_error_with_bad_expressions():
        execution = _.env.run(*_.cmd + ['list', _.bad_expression], expect_error=True)

        expect(execution.stdout).to.have("Error: Invalid expression")

    with context('with an empty iPod'):
        def should_print_nothing():
            execution = _.env.run(*_.cmd + ['list'])

            expect(execution.stdout).to.be.empty

    with context('with songs in the iPod'):
        def should_print_a_header():
            execution = _.env.run(*_.cmd + ['list'])

            expect(execution.stdout).to.have('Title', 'Album', 'Artist')

        def should_print_a_line_per_song():
            execution = _.env.run(*_.cmd + ['list'])

            length_of_footer = 2
            length_of_header = 1
            number_of_songs = len(_.songs)
            stdout_lines = execution.stdout.split('\n')

            expect(stdout_lines).to.have.length(
                length_of_header + number_of_songs + length_of_footer)

        with context('given a filtering expression'):
            def should_print_a_line_per_song_that_matches():
                execution = _.env.run(*_.cmd + ['list'] + _.expression.split())

                length_of_footer = 2
                length_of_header = 1
                number_of_songs = 1
                stdout_lines = execution.stdout.split('\n')

                expect(stdout_lines).to.have.length(
                    length_of_header + number_of_songs + length_of_footer)

        @before.all
        def setup():
            populate_ipod(_.mountpoint_path, _.songs)

        @after.all
        def cleanup():
            try:
                shutil.rmtree(_.mountpoint_path)
            except:
                pass
{'fraction_non_alphanumeric': 0.10855499640546369, 'fraction_numerical': 0.002875629043853343, 'mean_word_length': 2.200920245398773, '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': '5860398', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1167, 'n_words': 238}