From cccc1bfd57e1ec05fbb997346cf54e906837b399 Mon Sep 17 00:00:00 2001 From: Yige Xu Date: Tue, 17 Sep 2019 19:37:37 +0800 Subject: [PATCH] add fitlog and spacy while testing --- .travis.yml | 2 ++ test/io/pipe/test_matching.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/.travis.yml b/.travis.yml index bd7a34f5..0770d4e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,12 @@ python: # command to install dependencies install: - pip install --quiet -r requirements.txt + - pip install --quiet fitlog - pip install pytest>=3.6 - pip install pytest-cov # command to run tests script: + - python -m spacy download en - pytest --cov=fastNLP test/ after_success: diff --git a/test/io/pipe/test_matching.py b/test/io/pipe/test_matching.py index 785d44bb..a901bc78 100644 --- a/test/io/pipe/test_matching.py +++ b/test/io/pipe/test_matching.py @@ -72,3 +72,37 @@ class TestRunMatchingPipe(unittest.TestCase): for x, y in zip(vocab, data_bundle1.iter_vocabs()): name, vocabs = y self.assertEqual(x + 1 if name == 'words' else x, len(vocabs)) + + def test_spacy(self): + data_set_dict = { + 'RTE': ('test/data_for_tests/io/RTE', RTEPipe, RTEBertPipe, (5, 5, 5), (425, 2)), + } + for k, v in data_set_dict.items(): + path, pipe1, pipe2, data_set, vocab = v + + with self.assertWarns(Warning): + data_bundle1 = pipe1(tokenizer='spacy').process_from_file(path) + data_bundle2 = pipe2(tokenizer='spacy').process_from_file(path) + + self.assertTrue(isinstance(data_bundle1, DataBundle)) + self.assertEqual(len(data_set), data_bundle1.num_dataset) + print(k) + print(data_bundle1) + print(data_bundle2) + for x, y in zip(data_set, data_bundle1.iter_datasets()): + name, dataset = y + self.assertEqual(x, len(dataset)) + self.assertEqual(len(data_set), data_bundle2.num_dataset) + for x, y in zip(data_set, data_bundle2.iter_datasets()): + name, dataset = y + self.assertEqual(x, len(dataset)) + + self.assertEqual(len(vocab), data_bundle1.num_vocab) + for x, y in zip(vocab, data_bundle1.iter_vocabs()): + name, vocabs = y + self.assertEqual(x, len(vocabs)) + self.assertEqual(len(vocab), data_bundle2.num_vocab) + for x, y in zip(vocab, data_bundle1.iter_vocabs()): + name, vocabs = y + self.assertEqual(x + 1 if name == 'words' else x, len(vocabs)) +