From 9dbc31d72c256a6a581ae883a9781812cc30280d Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Mon, 16 Feb 2015 11:49:31 -0500 Subject: [PATCH] * Add test from NSchrading --- tests/test_token_references.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test_token_references.py b/tests/test_token_references.py index db1b828f3..b5fe9f941 100644 --- a/tests/test_token_references.py +++ b/tests/test_token_references.py @@ -22,3 +22,26 @@ def test_orphan(): assert orphan.orth_ == 'orphan' assert orphan.pos_ == 'ADJ' assert orphan.head.orth_ == 'token' + + +def _orphan_from_list(toks): + ''' Take the tokens from nlp(), append them to a list, return the list ''' + lst = [] + for tok in toks: + lst.append(tok) + return lst + +def test_list_orphans(): + # Test case from NSchrading + nlp = English() + samples = ["a", "test blah wat okay"] + lst = [] + for sample in samples: + # Go through all the samples, call nlp() on each to get tokens, + # pass those tokens to the _orphan_from_list() function, get a list back + # and put all results in another list + lst.extend(_orphan_from_list(nlp(sample))) + # go through the list of all tokens and try to print orth_ + orths = ['a', 'test', 'blah', 'wat', 'okay'] + for i, l in enumerate(lst): + assert l.orth_ == orths[i]