aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzhaoyehua <zhaoyh6@asiainfo.com>2021-05-28 15:09:33 +0800
committerzhaoyehua <zhaoyh6@asiainfo.com>2021-05-28 15:09:45 +0800
commit8e0a65d9c1501f157af18957e16f40053ec04b87 (patch)
tree525b59c2e50420d6b8fbb14bf85039fc4a09b730
parent9f672413bbc463290852bbe861028dacc9936dca (diff)
feat:add test file for nlp project
Issue-ID: USECASEUI-525 Change-Id: Id542b70cbb3b63b9b0f2be9b3b5dd3761a75da9c Signed-off-by: zhaoyehua <zhaoyh6@asiainfo.com>
-rw-r--r--nlp/TestApiSquad.py30
-rw-r--r--nlp/requirements.txt8
-rw-r--r--nlp/tox.ini8
3 files changed, 38 insertions, 8 deletions
diff --git a/nlp/TestApiSquad.py b/nlp/TestApiSquad.py
new file mode 100644
index 0000000..537b41d
--- /dev/null
+++ b/nlp/TestApiSquad.py
@@ -0,0 +1,30 @@
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+
+import unittest
+from unittest import mock
+import sys
+sys.path.append("scripts")
+import pandas as pd
+sys.modules['modeling'] = mock.Mock()
+sys.modules['optimization'] = mock.Mock()
+sys.modules['tokenization'] = mock.Mock()
+sys.modules['tensorflow'] = mock.Mock()
+import api_squad
+
+
+class TestApiSquad(unittest.TestCase):
+
+ def test_make_json(self):
+ data = {"Sequence": ['0'], "text": ['Please'], "Communication Service Name": ['exclusive'], "Max Number of UEs": ['10'], "Data Rate Downlink": ['1Gbps'], "Latency": ['low'], "Data Rate Uplink": ['1Gbps'], "Resource Sharing Level": ['Resources are not shared'], "Mobility": ['Fixed network'], "Area": ['East of seven Science and Technology cities in North Changping']}
+ df = pd.DataFrame(data, index=[0])
+ mock_data_train = mock.Mock(return_value=df)
+ pd.read_excel = mock_data_train
+ result = api_squad.make_json('fileName', ['Communication Service Name', 'Max Number of UEs', 'Data Rate Downlink', 'Latency', 'Data Rate Uplink', 'Resource Sharing Level', 'Mobility', 'Area'])
+ print(result)
+ self.assertEqual(result, '{"data": [{"title": "Not available", "paragraphs": [{"context": "Please", "qas": [{"answers": [{"text": "exclusive", "answer_start": -1}], "is_impossible": 0, "id": "0Communication Service Name", "question": "Communication Service Name"}, {"answers": [{"text": "10", "answer_start": -1}], "is_impossible": 0, "id": "0Max Number of UEs", "question": "Max Number of UEs"}, {"answers": [{"text": "1Gbps", "answer_start": -1}], "is_impossible": 0, "id": "0Data Rate Downlink", "question": "Data Rate Downlink"}, {"answers": [{"text": "low", "answer_start": -1}], "is_impossible": 0, "id": "0Latency", "question": "Latency"}, {"answers": [{"text": "1Gbps", "answer_start": -1}], "is_impossible": 0, "id": "0Data Rate Uplink", "question": "Data Rate Uplink"}, {"answers": [{"text": "Resources are not shared", "answer_start": -1}], "is_impossible": 0, "id": "0Resource Sharing Level", "question": "Resource Sharing Level"}, {"answers": [{"text": "Fixed network", "answer_start": -1}], "is_impossible": 0, "id": "0Mobility", "question": "Mobility"}, {"answers": [{"text": "East of seven Science and Technology cities in North Changping", "answer_start": -1}], "is_impossible": 0, "id": "0Area", "question": "Area"}]}]}]}')
+
+
+if __name__ == "__main__":
+ unittest.main() \ No newline at end of file
diff --git a/nlp/requirements.txt b/nlp/requirements.txt
index 024d1b4..18d09a7 100644
--- a/nlp/requirements.txt
+++ b/nlp/requirements.txt
@@ -1,4 +1,6 @@
pytest
-entrypoints==0.3
-Flask==1.1.1
-coverage
+entrypoints==0.3
+Flask==1.1.1
+coverage==4.2
+six==1.12.0
+pandas==0.24.2 \ No newline at end of file
diff --git a/nlp/tox.ini b/nlp/tox.ini
index 2b6716e..92767c4 100644
--- a/nlp/tox.ini
+++ b/nlp/tox.ini
@@ -13,14 +13,12 @@ commands = flake8
[testenv]
deps = -r{toxinidir}/requirements.txt
-commands = pytest
+commands = coverage run --branch TestApiSquad.py
[testenv:py36]
commands =
{[testenv]commands}
[testenv:cov]
-deps = pytest
- pytest-cov
-commands = pytest --cov-report=html
-
+deps = coverage==4.2
+commands = coverage xml --omit="*test*,*__init__.py,*site-packages*,*Test*" \ No newline at end of file