From ca25baf6b9007f6347fe7969e723537115fc64f9 Mon Sep 17 00:00:00 2001 From: ChenXin Date: Mon, 26 Oct 2020 13:53:46 +0800 Subject: [PATCH] =?UTF-8?q?1.=20SKIP=20test=5Fprocess=5Ffrom=5Ffile=202.?= =?UTF-8?q?=20doc=5Futils=20=E5=A2=9E=E5=8A=A0=E4=BA=86=20=5F=5Fall=5F=5F?= =?UTF-8?q?=20=E7=9A=84=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastNLP/doc_utils.py | 10 +++++++--- test/io/pipe/test_classification.py | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/fastNLP/doc_utils.py b/fastNLP/doc_utils.py index 3f7889e4..119db776 100644 --- a/fastNLP/doc_utils.py +++ b/fastNLP/doc_utils.py @@ -23,7 +23,9 @@ def doc_process(m): while 1: defined_m = sys.modules[module_name] try: - if "undocumented" not in defined_m.__doc__ and name in defined_m.__all__: + if not hasattr(defined_m, "__all__"): + print("Warning: Module {} lacks `__all__`".format(module_name)) + elif "undocumented" not in defined_m.__doc__ and name in defined_m.__all__: obj.__doc__ = r"别名 :class:`" + m.__name__ + "." + name + "`" \ + " :class:`" + module_name + "." + name + "`\n" + obj.__doc__ break @@ -34,7 +36,7 @@ def doc_process(m): except: print("Warning: Module {} lacks `__doc__`".format(module_name)) break - + # 识别并标注基类,只有基类也在 fastNLP 中定义才显示 if inspect.isclass(obj): @@ -45,7 +47,9 @@ def doc_process(m): for i in range(len(parts) - 1): defined_m = sys.modules[module_name] try: - if "undocumented" not in defined_m.__doc__ and name in defined_m.__all__: + if not hasattr(defined_m, "__all__"): + print("Warning: Module {} lacks `__all__`".format(module_name)) + elif "undocumented" not in defined_m.__doc__ and name in defined_m.__all__: obj.__doc__ = r"基类 :class:`" + defined_m.__name__ + "." + base.__name__ + "` \n\n" + obj.__doc__ break module_name += "." + parts[i + 1] diff --git a/test/io/pipe/test_classification.py b/test/io/pipe/test_classification.py index c6bd5444..8ebdb2df 100644 --- a/test/io/pipe/test_classification.py +++ b/test/io/pipe/test_classification.py @@ -10,7 +10,7 @@ from fastNLP.io.pipe.classification import ChnSentiCorpPipe, THUCNewsPipe, Weibo @unittest.skipIf('TRAVIS' in os.environ, "Skip in travis") class TestClassificationPipe(unittest.TestCase): def test_process_from_file(self): - for pipe in [YelpPolarityPipe, SST2Pipe, IMDBPipe, YelpFullPipe, SSTPipe]: + for pipe in [YelpPolarityPipe, SST2Pipe, IMDBPipe, YelpFullPipe, SSTPipe]: with self.subTest(pipe=pipe): print(pipe) data_bundle = pipe(tokenizer='raw').process_from_file() @@ -33,6 +33,7 @@ class TestCNClassificationPipe(unittest.TestCase): print(data_bundle) +@unittest.skipIf('TRAVIS' in os.environ, "Skip in travis") class TestRunClassificationPipe(unittest.TestCase): def test_process_from_file(self): data_set_dict = { @@ -79,15 +80,14 @@ class TestRunClassificationPipe(unittest.TestCase): data_bundle = pipe(tokenizer='raw').process_from_file(path) else: data_bundle = pipe(bigrams=True, trigrams=True).process_from_file(path) - + self.assertTrue(isinstance(data_bundle, DataBundle)) self.assertEqual(len(data_set), data_bundle.num_dataset) for name, dataset in data_bundle.iter_datasets(): self.assertTrue(name in data_set.keys()) self.assertEqual(data_set[name], len(dataset)) - + self.assertEqual(len(vocab), data_bundle.num_vocab) for name, vocabs in data_bundle.iter_vocabs(): self.assertTrue(name in vocab.keys()) self.assertEqual(vocab[name], len(vocabs)) -