From 08e924b54fee8b9357d8a0dd9801b2454bcd19e0 Mon Sep 17 00:00:00 2001 From: xuyige Date: Tue, 28 Aug 2018 17:17:07 +0800 Subject: [PATCH] add test code for testing preprocess.py --- test/core/test_preprocess.py | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/core/test_preprocess.py diff --git a/test/core/test_preprocess.py b/test/core/test_preprocess.py new file mode 100644 index 00000000..bff33ed3 --- /dev/null +++ b/test/core/test_preprocess.py @@ -0,0 +1,43 @@ +import os +import unittest + +from fastNLP.core.preprocess import SeqLabelPreprocess + + +class TestSeqLabelPreprocess(unittest.TestCase): + def test_case_1(self): + data = [ + [['Tom', 'and', 'Jerry', '.'], ['n', '&', 'n', '.']], + [['Hello', 'world', '!'], ['a', 'n', '.']], + [['Tom', 'and', 'Jerry', '.'], ['n', '&', 'n', '.']], + [['Hello', 'world', '!'], ['a', 'n', '.']], + [['Tom', 'and', 'Jerry', '.'], ['n', '&', 'n', '.']], + [['Hello', 'world', '!'], ['a', 'n', '.']], + [['Tom', 'and', 'Jerry', '.'], ['n', '&', 'n', '.']], + [['Hello', 'world', '!'], ['a', 'n', '.']], + [['Tom', 'and', 'Jerry', '.'], ['n', '&', 'n', '.']], + [['Hello', 'world', '!'], ['a', 'n', '.']], + ] + + if os.path.exists("./save"): + for root, dirs, files in os.walk("./save", topdown=False): + for name in files: + os.remove(os.path.join(root, name)) + for name in dirs: + os.rmdir(os.path.join(root, name)) + result = SeqLabelPreprocess().run(train_dev_data=data, train_dev_split=0.4, + pickle_path="./save") + result = SeqLabelPreprocess().run(train_dev_data=data, train_dev_split=0.4, + pickle_path="./save") + if os.path.exists("./save"): + for root, dirs, files in os.walk("./save", topdown=False): + for name in files: + os.remove(os.path.join(root, name)) + for name in dirs: + os.rmdir(os.path.join(root, name)) + result = SeqLabelPreprocess().run(test_data=data, train_dev_data=data, + pickle_path="./save", train_dev_split=0.4, + cross_val=True) + result = SeqLabelPreprocess().run(test_data=data, train_dev_data=data, + pickle_path="./save", train_dev_split=0.4, + cross_val=True)