From 159a3580e14c7c54f62487e9d0fd171d2bcf6097 Mon Sep 17 00:00:00 2001 From: shibing624 Date: Tue, 24 May 2022 11:17:47 +0800 Subject: [PATCH] update test. --- .github/workflows/ubuntu.yml | 3 ++- README.md | 2 +- requirements.txt | 2 +- setup.py | 2 +- tests/test_sim_score.py | 16 ++++++++++++++++ 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 5e92ac6..e2f87e5 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -47,6 +47,7 @@ jobs: run: | pip install -r requirements.txt pip install . + pip install pytest - name: PKG-TEST run: | - python -m unittest discover tests/ \ No newline at end of file + python -m pytest \ No newline at end of file diff --git a/README.md b/README.md index 4607cc3..e47c87e 100644 --- a/README.md +++ b/README.md @@ -439,7 +439,7 @@ version = {1.0.1} 项目代码还很粗糙,如果大家对代码有所改进,欢迎提交回本项目,在提交之前,注意以下两点: - 在`tests`添加相应的单元测试 -- 使用`python setup.py test`来运行所有单元测试,确保所有单测都是通过的 +- 使用`python -m pytest`来运行所有单元测试,确保所有单测都是通过的 之后即可提交PR。 diff --git a/requirements.txt b/requirements.txt index 4b982eb..a5f5f88 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ text2vec>=1.1.5 jieba>=0.39 loguru -transformers>=4.6.0 +transformers Pillow hnswlib annoy diff --git a/setup.py b/setup.py index 29fbee9..2d0b645 100644 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ setup( keywords='similarities,Chinese Text Similarity Calculation Tool,similarity,word2vec', install_requires=[ "text2vec>=1.1.5", - "transformers>=4.6.0", + "transformers", "jieba>=0.39", "loguru", "Pillow", diff --git a/tests/test_sim_score.py b/tests/test_sim_score.py index f12040c..e932393 100644 --- a/tests/test_sim_score.py +++ b/tests/test_sim_score.py @@ -36,6 +36,22 @@ class SimScoreTestCase(unittest.TestCase): self.assertEqual(len(r), 2) self.assertEqual(len(r[0]), 0) + def test_case(self): + cases = [("牙疼有蛀牙怎么办", "手机前十名排行榜"), + ("小游戏,下载", "干洗机什么牌子的好"), + ("如何恢复微信里面的聊天记录", "吸氢气机"), + ("胃病症状的早期表现", "胃溃疡症状"), ] + for i in cases: + print(i) + r = m.similarity(i[0], i[1]) + print(r) + print("-" * 50) + new_m = Similarity(model_name_or_path="sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2") + for i in cases: + print(i) + r = new_m.similarity(i[0], i[1]) + print(r) + if __name__ == '__main__': unittest.main()