Skip to content

Commit

Permalink
Merge pull request #214 from nielstron/feat/property-based-test
Browse files Browse the repository at this point in the history
Feat/property based test
  • Loading branch information
nielstron authored Jan 9, 2023
2 parents 96ed0b0 + d1c64c6 commit 06774a1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ install:
- pip install pylint
- pip install coverage
- pip install coveralls
- pip install hypothesis
# Check if installing works
- pip install -e .

Expand All @@ -32,6 +33,8 @@ script:
- coverage run --source=quantulum3 scripts/build.py
# Test basic functionality
- coverage run -a --source=quantulum3 setup.py test -s quantulum3.tests.test_setup
# Test generally that user-facing functions do not throw errors
- coverage run -a --source=quantulum3 setup.py test -s quantulum3.tests.test_hypothesis
# Test whether quantulum works without classifier
- coverage run -a --source=quantulum3 setup.py test -s quantulum3.tests.test_no_classifier
# Test language specific non-classifier tasks
Expand Down
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ quantulum3 = {editable = true,path = "."}
coverage = "*"
pymagnitude = "*"
black = "*"
hypothesis = "*"

[requires]
python_version = "3.8"
48 changes: 48 additions & 0 deletions quantulum3/tests/test_hypothesis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
:mod:`Quantulum` property based tests.
"""

import unittest

from hypothesis import given, settings
from hypothesis import strategies as st

from .. import parser as p
from ..language import LANGUAGES

multilang_strategy = st.one_of(*(st.just(l) for l in LANGUAGES))


class TestNoErrors(unittest.TestCase):
# pylint: disable=no-self-use
@given(st.text(), multilang_strategy)
@settings(deadline=None)
def test_parse(self, s, lang):
# Just assert that this does not throw any exceptions
p.parse(s, lang=lang)

@given(st.text(), multilang_strategy)
@settings(deadline=None)
def test_extract_spellout_values(self, s, lang):
# Just assert that this does not throw any exceptions
p.extract_spellout_values(s, lang=lang)

@given(st.text(), multilang_strategy)
@settings(deadline=None)
def test_inline_parse_and_expand(self, s, lang):
# Just assert that this does not throw any exceptions
p.inline_parse_and_expand(s, lang=lang)

@given(st.text(), multilang_strategy)
@settings(deadline=None)
def test_clean_text(self, s, lang):
# Just assert that this does not throw any exceptions
p.clean_text(s, lang=lang)


###############################################################################
if __name__ == "__main__": # pragma: no cover

unittest.main()

0 comments on commit 06774a1

Please sign in to comment.