コード例 #1
0
def complete():
    query = request.args.get('query', '')
    if query:
        completions = display_completions(find_completions(query, repository))
        body = {'completions': completions}
        response = app.response_class(response=json.dumps(body),
                                      status=200,
                                      mimetype='application/json')
    else:
        response = app.response_class(status=400)
    return response
コード例 #2
0
def test_display_results_are_sorted():
    got = display_completions(find_completions('angular', repository))
    want = ['Angular Components and Stuff', 'Fundamentals of Angular 4']
    assert got == want
コード例 #3
0
def test_jared_matches_one_author():
    got = len(find_completions('jared', repository))
    want = 1
    assert got == want
コード例 #4
0
def test_ha_phan_matches_two_courses():
    got = len(find_completions('Ha Phan', repository))
    want = 2
    assert got == want
コード例 #5
0
def test_fundamental_angular_matches_one_course():
    got = len(find_completions('fundamental angular', repository))
    want = 1
    assert got == want
コード例 #6
0
def test_angular_matches_two_courses():
    got = len(find_completions('angular', repository))
    want = 2
    assert got == want
コード例 #7
0
def test_no_matches_yields_empty_list():
    got = find_completions('java', repository)
    want = []
    assert got == want
コード例 #8
0
def test_no_query_yields_empty_list():
    got = find_completions(None, repository)
    want = []
    assert got == want
コード例 #9
0
#! /usr/bin/env python3

import sys

from autocomplete import (find_completions, display_completions)
from completion import load_repository_from_file

repository_file_name = sys.argv[1]
query = sys.argv[2]

repository = load_repository_from_file(repository_file_name)
completions = find_completions(query, repository)

print('\n'.join(display_completions(completions)))