コード例 #1
0
def test_empty_vocab():
    """
    Nothing is present in an empty word list
    """
    vocab = Vocab([])
    assert vocab.as_list() == []
    assert not vocab.has("sheep")
コード例 #2
0
def test_small_vocab():
    l = ["eeny", "moe", "miney", "meeny"]
    vocab = Vocab(l)
    assert vocab.has("moe")
    assert vocab.has("eeny")
    assert vocab.has("miney")
    assert vocab.has("meeny")
    assert not vocab.has("many")
    assert sorted(vocab.as_list()) == sorted(l)
コード例 #3
0
def test_from_simulated_file():
    from io import StringIO
    l = StringIO(initial_value="""
        #comment
        # another comment line
        sheep

        rats
        #comment
        squirrels
        """)
    vocab = Vocab(l)
    assert sorted(vocab.as_list()) == ["rats", "sheep", "squirrels"]
    assert vocab.has("sheep")
    assert vocab.has("rats")
    assert vocab.has("squirrels")
    assert not vocab.has("#comment")
コード例 #4
0
ファイル: flask_vocab.py プロジェクト: raulpatel/UOCIS322-P3
# Globals
###
app = flask.Flask(__name__)

CONFIG = config.configuration()
app.secret_key = CONFIG.SECRET_KEY  # Should allow using session variables

#
# One shared 'Vocab' object, read-only after initialization,
# shared by all threads and instances.  Otherwise we would have to
# store it in the browser and transmit it on each request/response cycle,
# or else read it from the file on each request/responce cycle,
# neither of which would be suitable for responding keystroke by keystroke.

WORDS = Vocab(CONFIG.VOCAB)
NUM = min(len(WORDS.as_list()), CONFIG.SUCCESS_AT_COUNT)

###
# Pages
###


@app.route("/")
@app.route("/index")
def index():
    """The main page of the application"""
    flask.g.vocab = WORDS.as_list()
    flask.session["target_count"] = min(len(flask.g.vocab),
                                        CONFIG.SUCCESS_AT_COUNT)
    flask.session["jumble"] = jumbled(flask.g.vocab,
                                      flask.session["target_count"])
コード例 #5
0
def test_single_vocab():
    vocab = Vocab(["moe"])
    assert vocab.as_list() == ["moe"]
    assert vocab.has("moe")
    assert not vocab.has("meeny")