Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_setitem(self):
wl = tb.WordList(['I', 'love', 'JavaScript'])
wl[2] = tb.Word('Python')
assert_equal(wl[2], tb.Word('Python'))
def test_slicing(self):
wl = tb.WordList(self.words)
first = wl[0]
assert_true(isinstance(first, tb.Word))
assert_equal(first, 'Beautiful')
dogs = wl[0:2]
assert_true(isinstance(dogs, tb.WordList))
assert_equal(dogs, tb.WordList(['Beautiful', 'is']))
def test_stem(self): #only PorterStemmer tested
wl = tb.WordList(["cat", "dogs", "oxen"])
assert_equal(wl.stem(), tb.WordList(['cat', 'dog', 'oxen']))
def test_extend(self):
wl = tb.WordList(["cats", "dogs"])
wl.extend(["buffalo", 4])
assert_true(isinstance(wl[2], tb.Word))
assert_true(isinstance(wl[3], int))
def test_words_includes_apostrophes_in_contractions(self):
blob = tb.TextBlob("Let's test this.")
assert_equal(blob.words, tb.WordList(['Let', "'s", "test", "this"]))
blob2 = tb.TextBlob("I can't believe it's not butter.")
assert_equal(blob2.words, tb.WordList(['I', 'ca', "n't", "believe",
'it', "'s", "not", "butter"]))
def test_pluralize(self):
wl = tb.WordList(['dog', 'cat', 'buffalo', 'antelope'])
assert_equal(wl.pluralize(), tb.WordList(['dogs', 'cats', 'buffaloes', 'antelope']))
def test_slicing(self):
wl = tb.WordList(self.words)
first = wl[0]
assert_true(isinstance(first, tb.Word))
assert_equal(first, 'Beautiful')
dogs = wl[0:2]
assert_true(isinstance(dogs, tb.WordList))
assert_equal(dogs, tb.WordList(['Beautiful', 'is']))
def test_lemmatize(self):
wl = tb.WordList(["cat", "dogs", "oxen"])
assert_equal(wl.lemmatize(), tb.WordList(['cat', 'dog', 'ox']))
def test_tokenize_method(self):
tokenizer = nltk.tokenize.TabTokenizer()
blob = tb.TextBlob("This is\ttext.")
# If called without arguments, should default to WordTokenizer
assert_equal(blob.tokenize(), tb.WordList(["This", "is", "text", "."]))
# Pass in the TabTokenizer
assert_equal(blob.tokenize(tokenizer), tb.WordList(["This is", "text."]))
def test_pop(self):
wl = tb.WordList(['cats', 'dogs'])
assert_equal(wl.pop(), tb.Word('dogs'))
assert_raises(IndexError, wl.__getitem__, 1)
assert_equal(wl.pop(), tb.Word('cats'))
assert_equal(len(wl), 0)
assert_raises(IndexError, wl.pop)