Skip to content

Commit

Permalink
- Added dragonfly.test sub-package containing testing tools.
Browse files Browse the repository at this point in the history
 - Added test cases for English Integer class.
 - Added initial test documentation.
 - Added Engine.set_exclusiveness() method.
 - Removed deprecated dragonfly.all module.
  • Loading branch information
t4ngo committed Oct 11, 2009
1 parent eee6488 commit 6461498
Show file tree
Hide file tree
Showing 14 changed files with 556 additions and 225 deletions.
23 changes: 23 additions & 0 deletions build_test.py
Expand Up @@ -19,6 +19,24 @@
#

"""
Main test runner script
============================================================================
This file is Dragonfly's main test scripts. Running it will execute all
tests within the Dragonfly library.
Dependencies
----------------------------------------------------------------------------
This script uses several external libraries to collect, run, and analyze
the Dragonfly tests. It requires the following external dependencies:
* `Nose <http://somethingaboutorange.com/mrl/projects/nose/>`_ --
an extension on unittest.
* `Coverage <http://nedbatchelder.com/code/coverage/>`_ --
a code coverage measuring tool.
"""


Expand All @@ -28,8 +46,10 @@


#===========================================================================
# Test control functions for the various types of tests: nose, pep8, pylint.

def run_nose():
""" Use Nose to collect and execute test cases within Dragonfly. """
import nose.core
import coverage.control
from pkg_resources import resource_filename
Expand Down Expand Up @@ -62,6 +82,7 @@ def run_nose():


def run_pylint():
""" Use the pylint package to analyze the Dragonfly source code. """
from pylint import lint
args = [
"dragonfly",
Expand All @@ -70,6 +91,7 @@ def run_pylint():


def run_pep8():
""" Use the pep8 package to analyze the Dragonfly source code. """
import pep8
argv = [
sys.argv[0],
Expand All @@ -83,6 +105,7 @@ def run_pep8():


#===========================================================================
# This script's main control logic.

def main():
# run_pep8()
Expand Down
1 change: 1 addition & 0 deletions documentation/index.txt
Expand Up @@ -20,6 +20,7 @@ Contents:
actions
windows
context
tests
misc


Expand Down
29 changes: 29 additions & 0 deletions documentation/tests.txt
@@ -0,0 +1,29 @@

.. _RefTests:

Test suite
****************************************************************************

The Dragonfly library contains tests to verify its functioning and
assure its quality.

Contents:

.. toctree::

actions_doctests


Test script
============================================================================

.. automodule:: dragonfly.test.run_tests
:members:


Test cases
============================================================================

.. automodule:: dragonfly.language.en.test_number
:members:

57 changes: 0 additions & 57 deletions dragonfly/all.py

This file was deleted.

3 changes: 3 additions & 0 deletions dragonfly/engines/engine_base.py
Expand Up @@ -59,6 +59,9 @@ def load_grammar(self, grammar, *args, **kwargs):
def update_list(self, lst, grammar):
raise NotImplementedError("Engine %s not implemented." % self)

def set_exclusiveness(self, grammar, exclusive):
raise NotImplementedError("Engine %s not implemented." % self)


#-----------------------------------------------------------------------
# Recognition observer methods.
Expand Down
4 changes: 2 additions & 2 deletions dragonfly/engines/engine_natlink.py
Expand Up @@ -128,12 +128,12 @@ def unload_grammar(self, grammar):
self._log.warning("Engine %s: failed to unload: %s."
% (self, e))

def set_exclusive(self, grammar, exclusive):
def set_exclusiveness(self, grammar, exclusive):
try:
grammar_object = self._get_grammar_wrapper(grammar).grammar_object
grammar_object.setExclusive(exclusive)
except self._natlink.NatError, e:
self._log.warning("Engine %s: failed set exclusive: %s."
self._log.warning("Engine %s: failed set exclusiveness: %s."
% (self, e))

def activate_grammar(self, grammar):
Expand Down
4 changes: 4 additions & 0 deletions dragonfly/grammar/grammar_base.py
Expand Up @@ -327,6 +327,10 @@ def unload(self):
self._loaded = False
self._in_context = False

def set_exclusiveness(self, exclusiveness):
""" Set the exclusiveness of this grammar. """
self._engine.set_exclusiveness(self, exclusiveness)

def get_complexity_string(self):
"""
Build and return a human-readable text giving insight into the
Expand Down
24 changes: 21 additions & 3 deletions dragonfly/language/base/integer.py
Expand Up @@ -37,9 +37,27 @@ class Integer(Alternative):

_content = None

def __init__(self, name=None, min=None, max=None, default=None):
if not self._content:
self.__class__._content = language.IntegerContent
@classmethod
def _set_content(cls, content):
"""
Set the Integer class' language-specific contents.
This is an internal class method. However, it is also useful
for testing the Integer framework, as tests for different
languages can each use this method to force a particular
Integer language implementation.
"""
cls._content = content

def __init__(self, name=None, min=None, max=None, default=None,
content=None):
if content:
self._content = content
elif not self._content:
# Language-specific integer content has not been set yet, so
# we set it by retrieving the current speaker language content.
self._set_content(language.IntegerContent)
self._builders = self._content.builders

self._min = min; self._max = max
Expand Down
145 changes: 145 additions & 0 deletions dragonfly/language/en/test_number.py
@@ -0,0 +1,145 @@
#
# This file is part of Dragonfly.
# (c) Copyright 2007, 2008 by Christo Butcher
# Licensed under the LGPL.
#
# Dragonfly is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Dragonfly is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with Dragonfly. If not, see
# <http://www.gnu.org/licenses/>.
#

"""
Test suite for English language Integer and Digits classes
============================================================================
"""


from ...test import ElementTestCase, RecognitionFailure
from ..base.integer import Integer
from .number import IntegerContent


#---------------------------------------------------------------------------

class IntegerTestCase(ElementTestCase):
""" Verify various integers between 0 and 10**12. """
def _build_element(self):
return Integer(content=IntegerContent, min=0, max=10**12 - 1)
input_output = [
("zero", 0),
("one", 1),
("two", 2),
("three", 3),
("four", 4),
("five", 5),
("six", 6),
("seven", 7),
("eight", 8),
("nine", 9),
("ten", 10),
("eleven", 11),
("twelve", 12),
("thirteen", 13),
("fourteen", 14),
("fifteen", 15),
("sixteen", 16),
("seventeen", 17),
("eighteen", 18),
("nineteen", 19),
("seventy four hundred", 7400),
("seventy four thousand", 74000),
("two hundred and thirty four thousand five hundred sixty seven", 234567),
]


class Limit3to14TestCase(ElementTestCase):
""" Verify integer limits of range 3 -- 14. """
def _build_element(self):
return Integer(content=IntegerContent, min=3, max=14)
input_output = [
("zero", RecognitionFailure),
("one", RecognitionFailure),
("two", RecognitionFailure),
("three", 3),
("four", 4),
("five", 5),
("six", 6),
("seven", 7),
("eight", 8),
("nine", 9),
("ten", 10),
("eleven", 11),
("twelve", 12),
("thirteen", 13),
("fourteen", RecognitionFailure),
("fifteen", RecognitionFailure),
("sixteen", RecognitionFailure),
("seventeen", RecognitionFailure),
("eighteen", RecognitionFailure),
("nineteen", RecognitionFailure),
]


class Limit23to47TestCase(ElementTestCase):
""" Verify integer limits of range 23 -- 47. """
def _build_element(self):
return Integer(content=IntegerContent, min=23, max=47)
input_output = [
("twenty two", RecognitionFailure),
("twenty three", 23),
("forty six", 46),
("forty seven", RecognitionFailure),
]


class Limit230to350TestCase(ElementTestCase):
""" Verify integer limits of range 230 -- 350. """
def _build_element(self):
return Integer(content=IntegerContent, min=230, max=350)
input_output = [
("two hundred twenty nine", RecognitionFailure),
("two hundred thirty", 230),
("two hundred and thirty", 230),
("two hundred and thirty zero", RecognitionFailure),
("two hundred thirty one", 231),
("two hundred and thirty one", 231),
("three hundred forty nine", 349),
("three hundred fifty zero", RecognitionFailure),
("three hundred fifty", RecognitionFailure),
]


class Limit351TestCase(ElementTestCase):
""" Verify integer limits of range up to 351. """
def _build_element(self):
return Integer(content=IntegerContent, min=230, max=351)
input_output = [
("three hundred forty nine", 349),
("three hundred fifty", 350),
("three hundred fifty zero", RecognitionFailure),
("three hundred fifty one", RecognitionFailure),
]


class Limit352TestCase(ElementTestCase):
""" Verify integer limits of range up to 352. """
def _build_element(self):
return Integer(content=IntegerContent, min=230, max=352)
input_output = [
("three hundred forty nine", 349),
("three hundred fifty", 350),
("three hundred fifty zero", RecognitionFailure),
("three hundred fifty one", 351),
("three hundred fifty two", RecognitionFailure),
]
23 changes: 23 additions & 0 deletions dragonfly/test/__init__.py
@@ -0,0 +1,23 @@
#
# This file is part of Dragonfly.
# (c) Copyright 2007, 2008 by Christo Butcher
# Licensed under the LGPL.
#
# Dragonfly is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Dragonfly is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with Dragonfly. If not, see
# <http://www.gnu.org/licenses/>.
#

#---------------------------------------------------------------------------
from .error import TestError
from .element_test_case import ElementTestCase, RecognitionFailure

0 comments on commit 6461498

Please sign in to comment.