diff --git a/tests/README.md b/tests/README.md index e5c529bd..3b2b77fb 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,42 +1,53 @@ -# Unit tests +# Unit Tests [![codecov](https://codecov.io/gh/huseinzol05/malaya/branch/master/graph/badge.svg?token=Mto5hHr8da)](https://codecov.io/gh/huseinzol05/malaya) -## how-to +This folder contains the unit tests for malaya. We use `pytest` as our testing framework. -1. Install pytest, +## Preqrequisites +> Note: You should use Python 3.6 and above with pip3. Make sure to also use a virtual environment! +Install pytest, pytest-cov, pytest-codecov, and gitpython. ```bash pip3 install pytest pytest-cov pytest-codecov gitpython ``` -2. Run pytest, +Make sure tensorflow is installed, if some tests fail you might need to install the extra libraries in requirements.txt. + +```bash +pip3 install -r requirements.txt +``` + +## Running Tests + +**Run all tests** ```bash pytest tests --cov --cov-report term --cov-report html ``` -Or run failed tests only, +**Run failed tests only** ```bash pytest tests --cov --cov-report term --cov-report html --last-failed ``` -Or run for specific py file, +**Run a specific test file** ```bash -pytest tests/test_emotion.py --cov --cov-report term --cov-report html +pytest tests/test_name.py --cov --cov-report term --cov-report html ``` -Or run for specific function, +**Run a test for a specific function** ```bash -pytest tests/test_emotion.py::test_multinomial --cov --cov-report term --cov-report html +pytest tests/test_name.py::test_multinomial --cov --cov-report term --cov-report html ``` -3. Upload to CodeCov, https://app.codecov.io/gh/huseinzol05/malaya +## Updating Code Coverage +Once you have run all the tests upload the generated HTML coverage report to our CodeCov at https://app.codecov.io/gh/huseinzol05/malaya. -``` +```bash CODECOV_TOKEN= pytest tests --cov --codecov --codecov-token=$CODECOV_TOKEN ``` \ No newline at end of file diff --git a/tests/requirements.txt b/tests/requirements.txt new file mode 100644 index 00000000..2ff8ae4f --- /dev/null +++ b/tests/requirements.txt @@ -0,0 +1,2 @@ +youtokentome +fasttext \ No newline at end of file diff --git a/tests/tests/test_abstractive_summarization.py b/tests/tests/test_abstractive_summarization.py index 1a73c766..a04f33d2 100644 --- a/tests/tests/test_abstractive_summarization.py +++ b/tests/tests/test_abstractive_summarization.py @@ -48,7 +48,7 @@ def cleaning(string): def test_transformer(): models = malaya.summarization.abstractive.available_transformer() - for m in models.index: + for m in models.keys(): print(m) model = malaya.summarization.abstractive.transformer(model=m) print(model.greedy_decoder([string])) diff --git a/tests/tests/test_constituency.py b/tests/tests/test_constituency.py index 1049f29a..6a0488e8 100644 --- a/tests/tests/test_constituency.py +++ b/tests/tests/test_constituency.py @@ -11,10 +11,9 @@ string = 'Dr Mahathir menasihati mereka supaya berhenti berehat dan tidur sebentar sekiranya mengantuk ketika memandu.' - def test_transformer(): models = malaya.constituency.available_transformer() - for m in models.index: + for m in models.keys(): print(m) model = malaya.constituency.transformer(model=m, gpu_limit=0.3) print(model.parse_tree(string)) diff --git a/tests/tests/test_dependency.py b/tests/tests/test_dependency.py index 833c81e0..c0cc517c 100644 --- a/tests/tests/test_dependency.py +++ b/tests/tests/test_dependency.py @@ -14,7 +14,7 @@ def test_transformer_v2(): models = malaya.dependency.available_transformer() - for m in models.index: + for m in models.keys(): print(m) model = malaya.dependency.transformer(model=m, gpu_limit=0.3) d_object, tagging, indexing = model.predict(string) @@ -24,7 +24,7 @@ def test_transformer_v2(): def test_transformer_v1(): models = malaya.dependency.available_transformer(version='v1') - for m in models.index: + for m in models.keys(): print(m) model = malaya.dependency.transformer(version='v1', model=m, gpu_limit=0.3) d_object, tagging, indexing = model.predict(string) diff --git a/tests/tests/test_emotion.py b/tests/tests/test_emotion.py index a459effd..ed68da46 100644 --- a/tests/tests/test_emotion.py +++ b/tests/tests/test_emotion.py @@ -19,7 +19,7 @@ def test_multinomial(): def test_transformer(): models = malaya.emotion.available_transformer() - for m in models.index: + for m in models.keys(): print(m) model = malaya.emotion.transformer(model=m, gpu_limit=0.3) print(model.predict_proba([text])) diff --git a/tests/tests/test_entity.py b/tests/tests/test_entity.py index b01674d4..29e04b01 100644 --- a/tests/tests/test_entity.py +++ b/tests/tests/test_entity.py @@ -15,7 +15,7 @@ def test_transformer(): models = malaya.entity.available_transformer() - for m in models.index: + for m in models.keys(): print(m) model = malaya.entity.transformer(model=m) print(model.predict(string)) @@ -27,7 +27,7 @@ def test_transformer(): def test_transformer_ontonotes5(): models = malaya.entity.available_transformer_ontonotes5() - for m in models.index: + for m in models.keys(): print(m) model = malaya.entity.transformer_ontonotes5(model=m) print(model.predict(string)) diff --git a/tests/tests/test_paraphrase.py b/tests/tests/test_paraphrase.py index 9132629e..e02bb6d5 100644 --- a/tests/tests/test_paraphrase.py +++ b/tests/tests/test_paraphrase.py @@ -14,7 +14,7 @@ def test_transformer(): models = malaya.paraphrase.available_transformer() - for m in models.index: + for m in models.keys(): print(m) model = malaya.paraphrase.transformer(model=m) print(model.greedy_decoder([string])) diff --git a/tests/tests/test_pos.py b/tests/tests/test_pos.py index 9c855664..fda0a120 100644 --- a/tests/tests/test_pos.py +++ b/tests/tests/test_pos.py @@ -15,7 +15,7 @@ def test_transformer(): models = malaya.pos.available_transformer() - for m in models.index: + for m in models.keys(): print(m) model = malaya.pos.transformer(model=m) print(model.predict(string)) diff --git a/tests/tests/test_relevancy.py b/tests/tests/test_relevancy.py index feab7a08..61880eff 100644 --- a/tests/tests/test_relevancy.py +++ b/tests/tests/test_relevancy.py @@ -14,7 +14,7 @@ def test_transformer(): models = malaya.relevancy.available_transformer() - for m in models.index: + for m in models.keys(): print(m) model = malaya.relevancy.transformer(model=m, gpu_limit=0.3) print(model.predict_proba([text])) diff --git a/tests/tests/test_segmentation.py b/tests/tests/test_segmentation.py index bd34a930..992dc806 100644 --- a/tests/tests/test_segmentation.py +++ b/tests/tests/test_segmentation.py @@ -14,7 +14,7 @@ def test_transformer(): models = malaya.segmentation.available_transformer() - for m in models.index: + for m in models.keys(): print(m) model = malaya.segmentation.transformer(model=m) print(model.greedy_decoder([string1])) diff --git a/tests/tests/test_sentiment.py b/tests/tests/test_sentiment.py index 87713bd2..d72da7a2 100644 --- a/tests/tests/test_sentiment.py +++ b/tests/tests/test_sentiment.py @@ -19,7 +19,7 @@ def test_multinomial(): def test_transformer(): models = malaya.sentiment.available_transformer() - for m in models.index: + for m in models.keys(): print(m) model = malaya.sentiment.transformer(model=m, gpu_limit=0.3) print(model.predict_proba([text])) diff --git a/tests/tests/test_toxicity.py b/tests/tests/test_toxicity.py index f0d0cf98..2832ca0f 100644 --- a/tests/tests/test_toxicity.py +++ b/tests/tests/test_toxicity.py @@ -19,7 +19,7 @@ def test_multinomial(): def test_transformer(): models = malaya.toxicity.available_transformer() - for m in models.index: + for m in models.keys(): print(m) model = malaya.toxicity.transformer(model=m, gpu_limit=0.3) print(model.predict_proba([text])) diff --git a/tests/tests/test_translation_en_ms.py b/tests/tests/test_translation_en_ms.py index e41b29c3..55e62fcf 100644 --- a/tests/tests/test_translation_en_ms.py +++ b/tests/tests/test_translation_en_ms.py @@ -14,7 +14,7 @@ def test_transformer(): models = malaya.translation.en_ms.available_transformer() - for m in models.index: + for m in models.keys(): print(m) model = malaya.translation.en_ms.transformer(model=m, gpu_limit=0.3) print(model.greedy_decoder([random_string1])) diff --git a/tests/tests/test_translation_ms_en.py b/tests/tests/test_translation_ms_en.py index c3a79cbd..ff8b91b7 100644 --- a/tests/tests/test_translation_ms_en.py +++ b/tests/tests/test_translation_ms_en.py @@ -14,7 +14,7 @@ def test_transformer(): models = malaya.translation.ms_en.available_transformer() - for m in models.index: + for m in models.keys(): print(m) model = malaya.translation.ms_en.transformer(model=m, gpu_limit=0.3) print(model.greedy_decoder([random_string1])) diff --git a/tests/tests/test_true_case.py b/tests/tests/test_true_case.py index 934f508f..2c0708c4 100644 --- a/tests/tests/test_true_case.py +++ b/tests/tests/test_true_case.py @@ -14,7 +14,7 @@ def test_transformer(): models = malaya.true_case.available_transformer() - for m in models.index: + for m in models.keys(): print(m) model = malaya.true_case.transformer(model=m) print(model.greedy_decoder([string1])) diff --git a/tests/tests/test_zeroshot.py b/tests/tests/test_zeroshot.py index 3975a248..0aad4039 100644 --- a/tests/tests/test_zeroshot.py +++ b/tests/tests/test_zeroshot.py @@ -20,7 +20,7 @@ def test_transformer(): models = malaya.zero_shot.classification.available_transformer() - for m in models.index: + for m in models.keys(): print(m) model = malaya.zero_shot.classification.transformer(model=m, gpu_limit=0.3) model.predict_proba([string], labels=['najib razak', 'mahathir', 'kerajaan', 'PRU', 'anarki'])