Skip to content

Commit

Permalink
Added tests and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ndyashas committed Aug 20, 2020
1 parent 733f100 commit 22b1936
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: python

python:
- "3.6"

install:
- pip3 install pytest==5.4.3 timeout-decorator==0.4.1

script:
- python3 -m pytest --cache-clear --tb=long --showlocals
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Documentation Status](https://readthedocs.org/projects/dhwani/badge/?version=latest)](https://dhwani.readthedocs.io/en/latest/?badge=latest)
[![Documentation Status](https://readthedocs.org/projects/dhwani/badge/?version=latest)](https://dhwani.readthedocs.io/en/latest/?badge=latest) [![Build Status](https://travis-ci.com/ndyashas/Dhwani.svg?branch=master)](https://travis-ci.com/ndyashas/Dhwani)

# Dhwani
English to Indic language phonetic conversion engine. Read more about the project [here](https://ndyashas.github.io/projects/Dhwani.html).
Expand Down
Empty file added tests/__init__.py
Empty file.
48 changes: 48 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import unittest

import dhwani

_test_id_match = {
"00": "Sanity test for the returned supported language dictionary",
"01": "Converter class API testing",
}


class Test_Dhwani_API(unittest.TestCase):
def setUp(self):
"""Load the supported conversions
"""
self.supported_conversions_dict = dhwani.get_supported_conversions()

def test_id_00(self):
"""Sanity test for the returned supported language dictionary
"""
self.assertIsNotNone(
self.supported_conversions_dict,
msg="{} returned None".format("dhwani.get_lang_mappings()"),
)

self.assertTrue(
len(self.supported_conversions_dict) > 0,
msg="No supported convertions available.",
)

for src_lang_code in self.supported_conversions_dict:
self.assertIsInstance(self.supported_conversions_dict[src_lang_code], list)
self.assertTrue(
len(self.supported_conversions_dict[src_lang_code]) > 0,
msg="src {} does not support convertions to any destination language".format(
src_lang_code
),
)

def test_id_01(self):
"""Converter class API testing
"""

for src_lang_code in self.supported_conversions_dict:
for dest_lang_code in self.supported_conversions_dict[src_lang_code]:
converter = dhwani.Converter(src_lang_code, dest_lang_code)

self.assertIsInstance(converter, dhwani.Converter) # Needed?
self.assertIsNotNone(converter.convert)
42 changes: 42 additions & 0 deletions tests/test_mapping_integrity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import unittest
import unittest.mock
import timeout_decorator

import dhwani
import dhwani.mappings.utils as utils

_test_id_match = {
"00": "Test that the mappings do not form any loops",
}


class Test_Dhwani_API(unittest.TestCase):
def setUp(self):
"""Load the supported conversions
"""
self.supported_conversions_dict = dhwani.get_supported_conversions()

def load_src_string_from_codes(self, src_lang_code: str, dest_lang_code: str):
mappings_list = utils.get_lang_mappings(src_lang_code, dest_lang_code)
toret_list = [list(element.keys())[0] for element in mappings_list]
toret = "".join(toret_list)
return toret

@timeout_decorator.timeout(2) # Assumption that it wont take more than this.
def _convert(self, converter, *args, **kwargs):
return converter.convert(*args, **kwargs)

def test_id_00(self):
"""Test that the mappings do not form any loops
"""

for src_lang_code in self.supported_conversions_dict:
for dest_lang_code in self.supported_conversions_dict[src_lang_code]:
src_text = self.load_src_string_from_codes(
src_lang_code, dest_lang_code
)

converter = dhwani.Converter(src_lang_code, dest_lang_code)
self.assertIsNotNone(converter.convert)

dest_text = self._convert(converter, src_text)

0 comments on commit 22b1936

Please sign in to comment.