Ejemplo n.º 1
0
 def test_errors(self, aug_toks):
     for num in [-1, 2.0]:
         with pytest.raises(ValueError):
             _ = transforms.swap_words(aug_toks, num=num)
     for obj in [["foo", "bar"], "foo bar"]:
         with pytest.raises(TypeError):
             _ = transforms.swap_words(obj, num=1)
Ejemplo n.º 2
0
 def test_pos(self, aug_toks):
     for pos in ["NOUN", ("NOUN", "VERB", "ADJ", "ADV")]:
         new_aug_toks = transforms.swap_words(aug_toks, num=1, pos=pos)
         assert isinstance(new_aug_toks, list)
         assert len(new_aug_toks) == len(aug_toks)
         assert all(
             isinstance(aug_tok, aug_utils.AugTok)
             for aug_tok in new_aug_toks)
         assert any(aug_tok.text != new_aug_tok.text
                    for aug_tok, new_aug_tok in zip(aug_toks, new_aug_toks))
Ejemplo n.º 3
0
 def test_num_int(self, aug_toks):
     for num in [1, 3]:
         new_aug_toks = transforms.swap_words(aug_toks, num=num)
         assert isinstance(new_aug_toks, list)
         assert len(new_aug_toks) == len(aug_toks)
         assert all(
             isinstance(aug_tok, aug_utils.AugTok)
             for aug_tok in new_aug_toks)
         assert any(aug_tok.text != new_aug_tok.text
                    for aug_tok, new_aug_tok in zip(aug_toks, new_aug_toks))
Ejemplo n.º 4
0
 def test_num_float(self, aug_toks):
     for num in [0.1, 0.3]:
         _ = transforms.swap_words(aug_toks, num=num)
Ejemplo n.º 5
0
 def test_noop(self, aug_toks):
     for num in [0, 0.0]:
         new_aug_toks = transforms.swap_words(aug_toks, num=num)
         for aug_tok, new_aug_tok in zip(aug_toks, new_aug_toks):
             assert aug_tok.text == new_aug_tok.text