Beispiel #1
0
def handle_exception(query):
    '''
    When passed a query, this function loops over each accepted
    Stack Overflow post, and displays them, until the user inputs
    'Y'.

    Parameter {str} query: the query to display posts for.
    '''

    for post in accepted_posts(query):
        # Display Stack Overflow posts for the error.
        clear_terminal()
        print_accepted_post(post)

        user_input = handle_user_input()

        # Custom query.
        if user_input not in (True, False):
            handle_exception(user_input)
            return

        # Error solved, break out of the loop.
        if user_input is True:
            clear_terminal()
            print_listening_for_errors()
            return
Beispiel #2
0
def handle_exception(error_description):
    '''
    When passed an error description, this function loops over each
    accepted Stack Overflow post, and displays them, until the user
    inputs 'Y'.

    Parameter {str} error_description: the error description to
    display posts for.
    '''

    for post in accepted_posts(error_description):
        # Display Stack Overflow posts for the error.
        print_accepted_post(post)

        error_is_solved = error_solved()

        if error_is_solved:
            print_listening_for_errors()
            break
Beispiel #3
0
def test_print_accepted_post_found_question_and_answer(capsys, monkeypatch):
    '''
    Ensures that proper output when both a question and answer are found.
    '''

    # 1. Given.
    def mock_get_post_text(*args):
        # pylint: disable=unused-argument
        '''
        Mocks the get_post_text function.
        '''

        return True

    def mock_print_post_text(*args):
        # pylint: disable=unused-argument
        '''
        Mocks the print_post_text function.
        '''

        return

    monkeypatch.setattr('autostack.so_web_scraper.get_post_text',
                        mock_get_post_text)

    monkeypatch.setattr('autostack.so_web_scraper.print_post_text',
                        mock_print_post_text)

    # 2. When.
    print_accepted_post(None)

    # 3. Then.
    captured = capsys.readouterr()
    assert ANSI_ESCAPE.sub('', captured.out) == (
        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n' +
        'Question:\n' +
        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n' + 'Answer:\n' +
        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n')
Beispiel #4
0
def test_print_accepted_post_no_answer(capsys, monkeypatch):
    '''
    Ensures that nothing is printed when no answer is found on a post.
    '''

    # 1. Given.
    def mock_get_post_text(*args):
        '''
        Mocks the get_post_text function.
        '''

        if args[1] == 'accepted-answer':
            return None
        return True

    monkeypatch.setattr('autostack.so_web_scraper.get_post_text',
                        mock_get_post_text)

    # 2. When.
    print_accepted_post(None)

    # 3. Then.
    captured = capsys.readouterr()
    assert not captured.out