Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Tests Revamp w/ Testing Documentation Improvements #168

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -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
```
2 changes: 2 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
youtokentome
fasttext
2 changes: 1 addition & 1 deletion tests/tests/test_abstractive_summarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
3 changes: 1 addition & 2 deletions tests/tests/test_constituency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test_emotion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/test_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test_paraphrase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test_pos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test_relevancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test_sentiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test_toxicity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test_translation_en_ms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test_translation_ms_en.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test_true_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test_zeroshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down