from datetime import datetime import pytest from dialogy import constants as const from dialogy.base import Input, Output from dialogy.plugins import CombineDateTimeOverSlots, DucklingPlugin from dialogy.workflow import Workflow from tests import EXCEPTIONS, load_tests @pytest.mark.parametrize("payload", load_tests("cases", __file__)) def test_plugin_cases(payload) -> None: """ Test cases where the plugin should work. """ entities = payload.get("inputs", {}).get("entities", []) tracker = payload.get("inputs", {}).get("tracker", []) expected = payload.get("expected", {}) duckling_plugin = DucklingPlugin(dimensions=["date", "time"], timezone="Asia/Kolkata", dest="output.entities") for i, entity in enumerate(entities): current_turn_entities = duckling_plugin._reshape(entity, i) combine_date_time_plugin = CombineDateTimeOverSlots( trigger_intents=["_callback_"], dest="output.entities", )
def main(argv=None): '''Run either all tests, or those specified in argv''' if argv is None: argv = sys.argv # parse options covreport = False failfast = False loglevel = logging.WARNING opts, args = getopt.gnu_getopt(argv[1:], 'hVD', ['help', 'coverage', 'fast', 'failfast', 'ff', 'full', 'debug', 'verbose']) for o, a in opts: if o in ('-h', '--help'): print '''\ usage: %s [OPTIONS] [MODULES] Where MODULE should a module name from ./tests/ If no module is given the whole test suite is run. Options: -h, --help print this text --fast skip a number of slower tests and mock filesystem --failfast stop after the first test that fails --ff alias for "--fast --failfast" --full full test for using filesystem without mock --coverage report test coverage statistics -V, --verbose run with verbose output from logging -D, --debug run with debug output from logging ''' % argv[0] return elif o == '--coverage': if coverage: covreport = True else: print >>sys.stderr, '''\ Can not run test coverage without module 'coverage'. On Ubuntu or Debian install package 'python-coverage'. ''' sys.exit(1) elif o == '--fast': tests.FAST_TEST = True # set before any test classes are loaded ! elif o == '--failfast': failfast = True elif o == '--ff': # --fast --failfast tests.FAST_TEST = True failfast = True elif o == '--full': tests.FULL_TEST = True elif o in ('-V', '--verbose'): loglevel = logging.INFO elif o in ('-D', '--debug'): loglevel = logging.DEBUG else: assert False, 'Unkown option: %s' % o # Start tracing if coverage: cov = coverage.coverage(source=['zim'], branch=True) cov.erase() # clean up old date set cov.exclude('assert ') cov.exclude('raise NotImplementedError') cov.start() # Set logging handler (don't use basicConfig here, we already installed stuff) handler = logging.StreamHandler() handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s')) logger = logging.getLogger() logger.setLevel(loglevel) logger.addHandler(handler) #logging.captureWarnings(True) # FIXME - make all test pass with this enabled # Build the test suite loader = unittest.TestLoader() try: if args: suite = unittest.TestSuite() for name in args: module = name if name.startswith('tests.') else 'tests.' + name test = loader.loadTestsFromName(module) suite.addTest(test) else: suite = tests.load_tests(loader, None, None) except AttributeError as error: # HACK: unittest raises and attribute errors if import of test script # fails try to catch this and show the import error instead - else raise # original error import re m = re.match(r"'module' object has no attribute '(\w+)'", error.args[0]) if m: module = m.group(1) m = __import__('tests.' + module) # should raise ImportError raise error # And run it unittest.installHandler() # Fancy handling for ^C during test result = \ unittest.TextTestRunner(verbosity=2, failfast=failfast, descriptions=False).run(suite) # Check the modules were loaded from the right location # (so no testing based on modules from a previous installed version...) mylib = os.path.abspath('./zim') for module in [m for m in sys.modules.keys() if m == 'zim' or m.startswith('zim.')]: if sys.modules[module] is None: continue file = sys.modules[module].__file__ assert file.startswith(mylib), \ 'Module %s was loaded from %s' % (module, file) test_report(result, 'test_report.html') print '\nWrote test report to test_report.html\n' # Stop tracing if coverage: cov.stop() cov.save() # Create coverage output if asked to do so if covreport: print 'Writing coverage reports...' cov.html_report(directory='./coverage', omit=['zim/inc/*']) print 'Done - Coverage reports can be found in ./coverage/'
# type : ignore import json from copy import copy import numpy as np import pandas as pd from dialogy.plugins.text.calibration.xgb import FeatureExtractor from tests import load_tests mock_data = load_tests("df", __file__, ext=".json") df = pd.DataFrame(mock_data, columns=["conv_id", "data", "tag", "value", "time"]) feature_extractor = FeatureExtractor() def test_feature_extractor_fit(): feature_extractor.fit(df) # pre-calculated values def test_feature_extractor_features(): alternative = json.loads(df.iloc[0]["data"])[0] assert feature_extractor.features(alternative) == [ [ 0.3889910975917115, 0.3889910975917115, 0.3889910975917115, 0.3889910975917115, 0.49338588343402934,
def main(argv=None): '''Run either all tests, or those specified in argv''' if argv is None: argv = sys.argv coverage = None loglevel = logging.WARNING opts, args = getopt.gnu_getopt(argv[1:], 'hVD', ['help', 'debug', 'verbose', 'coverage']) for o, a in opts: if o in ('-h', '--help'): print '''\ usage: %s [OPTIONS] [MODULES] Where MODULE should a module name from ./tests/ If no module is given the whole test suite is run. Options: --coverage report test coverage statistics -h, --help print this text -V, --verbose run with verbose output from logging -D, --debug run with debug output from logging ''' % argv[0] return elif o == '--coverage': try: import coverage as coverage_module except ImportError: print >>sys.stderr, '''\ Can not run test coverage without module 'coverage'. On Ubuntu or Debian install package 'python-coverage'. ''' sys.exit(1) #~ coverage = coverage_module.coverage(data_suffix=True, auto_data=True) print "running unittest with coverage." coverage = coverage_module.coverage(data_suffix=True) coverage.erase() # clean up old date set coverage.exclude('assert ') coverage.exclude('raise NotImplementedError') coverage.start() elif o in ('-V', '--verbose'): loglevel = logging.INFO elif o in ('-D', '--debug'): loglevel = logging.DEBUG else: assert False # Set logging handler logging.basicConfig(level=loglevel, format='%(levelname)s: %(message)s') # # Build the test suite loader = unittest.TestLoader() suite = tests.load_tests(loader, None, None) # And run it unittest.installHandler() # Fancy handling for ^C during test unittest.TextTestRunner(verbosity=2).run(suite) # Create coverage output if asked to do so if coverage: coverage.stop() #~ coverage.combine() print 'Writing coverage reports...' pyfiles = list(tests.all_files()) #~ coverage.report(pyfiles, show_missing=False) #~ coverage.html_report(pyfiles, directory='./coverage', omit=['zim/inc/*']) coverage_report(coverage, pyfiles, './coverage') print 'Done - Coverage reports can be found in ./coverage/'
import unittest if __name__ == '__main__': import tests loader = unittest.TestLoader() suite = tests.load_tests(loader, []) unittest.TextTestRunner().run(suite)
import sys import unittest from chirp import directory from tests import load_tests class TestSuiteAdapter(object): """Adapter for pytest since it doesn't support the loadTests() protocol""" def __init__(self, locals): self.locals = locals def loadTestsFromTestCase(self, test_cls): self.locals[test_cls.__name__] = test_cls @staticmethod def addTests(tests): pass directory.safe_import_drivers() adapter = TestSuiteAdapter(locals()) load_tests(adapter, None, None, suite=adapter)
#!/usr/bin/env python # -*- coding: utf-8 -*- import tests import unittest __author__ = 'James Iter' __date__ = '2017/03/31' __contact__ = '*****@*****.**' __copyright__ = '(c) 2017 by James Iter.' if __name__ == '__main__': suite = tests.load_tests(unittest.TestLoader(), unittest.TestSuite()) unittest.TextTestRunner(verbosity=2).run(suite)
def main(argv=None): '''Run either all tests, or those specified in argv''' if argv is None: argv = sys.argv # parse options coverage = None failfast = False loglevel = logging.WARNING opts, args = getopt.gnu_getopt(argv[1:], 'hVD', ['help', 'coverage', 'fast', 'failfast', 'debug', 'verbose']) for o, a in opts: if o in ('-h', '--help'): print '''\ usage: %s [OPTIONS] [MODULES] Where MODULE should a module name from ./tests/ If no module is given the whole test suite is run. Options: -h, --help print this text --fast skip a number of slower tests (assumes --failfast) --failfast stop after the first test that fails --coverage report test coverage statistics -V, --verbose run with verbose output from logging -D, --debug run with debug output from logging ''' % argv[0] return elif o == '--coverage': try: import coverage as coverage_module except ImportError: print >>sys.stderr, '''\ Can not run test coverage without module 'coverage'. On Ubuntu or Debian install package 'python-coverage'. ''' sys.exit(1) #~ coverage = coverage_module.coverage(data_suffix=True, auto_data=True) coverage = coverage_module.coverage(data_suffix=True) coverage.erase() # clean up old date set coverage.exclude('assert ') coverage.exclude('raise NotImplementedError') coverage.start() elif o == '--fast': failfast = True tests.FAST_TEST = True # set before any test classes are loaded ! elif o == '--failfast': failfast = True elif o in ('-V', '--verbose'): loglevel = logging.INFO elif o in ('-D', '--debug'): loglevel = logging.DEBUG else: assert False # Set logging handler logging.basicConfig(level=loglevel, format='%(levelname)s: %(message)s') # Build the test suite loader = unittest.TestLoader() if args: suite = unittest.TestSuite() for module in [ 'tests.'+name for name in args ]: test = loader.loadTestsFromName(module) suite.addTest(test) else: suite = tests.load_tests(loader, None, None) # And run it unittest.installHandler() # Fancy handling for ^C during test result = \ unittest.TextTestRunner(verbosity=2, failfast=failfast, descriptions=False).run(suite) # Check the modules were loaded from the right location # (so no testing based on modules from a previous installed version...) mylib = os.path.abspath('./zim') for module in [m for m in sys.modules.keys() if m == 'zim' or m.startswith('zim.')]: if sys.modules[module] is None: continue file = sys.modules[module].__file__ assert file.startswith(mylib), \ 'Module %s was loaded from %s' % (module, file) test_report(result, 'test_report.html') print '\nWrote test report to test_report.html\n' # Create coverage output if asked to do so if coverage: coverage.stop() #~ coverage.combine() print 'Writing coverage reports...' pyfiles = list(tests.zim_pyfiles()) #~ coverage.report(pyfiles, show_missing=False) #~ coverage.html_report(pyfiles, directory='./coverage', omit=['zim/inc/*']) coverage_report(coverage, pyfiles, './coverage') print 'Done - Coverage reports can be found in ./coverage/'
body = "test" entities = [ KeywordEntity( body=body, value=body, range={ "start": 0, "end": len(body), }, entity_type=body, ) ] assert entity_extractor.remove_low_scoring_entities(entities) == entities @pytest.mark.parametrize("payload", load_tests("entity_extractor", __file__)) def test_entity_extractor_for_thresholding(payload) -> None: """ We test threshold on entity extractors. :param payload: Test case body. :type payload: Dict[str, Any] """ entity_extractor = EntityScoringMixin() entity_extractor.threshold = payload["threshold"] input_size = payload["input_size"] expected = payload["expected"] entities = make_entity_object(payload["mock_entities"]) entities = [ entity.json()
from flask import Flask, render_template, g from students import students, load_students from tests import tests, load_tests from admin import admin app = Flask(__name__) app.register_blueprint(tests) app.register_blueprint(students) app.register_blueprint(admin) app.config.from_pyfile('defaults/defaults.conf') app.config.from_pyfile('tester.conf') load_tests() load_students() @app.route('/') def index(): return render_template('index.html') @app.route('/about/') def about(): return render_template('about.html') @app.before_request def before_request(): g.db = MongoClient( app.config['DB_HOST'], app.config['DB_PORT']
def main(argv=None): '''Run either all tests, or those specified in argv''' if argv is None: argv = sys.argv # parse options coverage = None failfast = False loglevel = logging.WARNING opts, args = getopt.gnu_getopt(argv[1:], 'hVD', ['help', 'coverage', 'fast', 'failfast', 'debug', 'verbose']) for o, a in opts: if o in ('-h', '--help'): print '''\ usage: %s [OPTIONS] [MODULES] Where MODULE should a module name from ./tests/ If no module is given the whole test suite is run. Options: -h, --help print this text --fast skip a number of slower tests (assumes --failfast) --failfast stop after the first test that fails --coverage report test coverage statistics -V, --verbose run with verbose output from logging -D, --debug run with debug output from logging ''' % argv[0] return elif o == '--coverage': try: import coverage as coverage_module except ImportError: print >>sys.stderr, '''\ Can not run test coverage without module 'coverage'. On Ubuntu or Debian install package 'python-coverage'. ''' sys.exit(1) #~ coverage = coverage_module.coverage(data_suffix=True, auto_data=True) coverage = coverage_module.coverage(data_suffix=True) coverage.erase() # clean up old date set coverage.exclude('assert ') coverage.exclude('raise NotImplementedError') coverage.start() elif o == '--fast': failfast = True tests.FAST_TEST = True # set before any test classes are loaded ! elif o == '--failfast': failfast = True elif o in ('-V', '--verbose'): loglevel = logging.INFO elif o in ('-D', '--debug'): loglevel = logging.DEBUG else: assert False # Set logging handler logging.basicConfig(level=loglevel, format='%(levelname)s: %(message)s') # Build the test suite loader = unittest.TestLoader() if args: suite = unittest.TestSuite() for name in args: module = name if name.startswith('tests.') else 'tests.' + name test = loader.loadTestsFromName(module) suite.addTest(test) else: suite = tests.load_tests(loader, None, None) # And run it unittest.installHandler() # Fancy handling for ^C during test result = \ unittest.TextTestRunner(verbosity=2, failfast=failfast, descriptions=False).run(suite) # Check the modules were loaded from the right location # (so no testing based on modules from a previous installed version...) mylib = os.path.abspath('./zim') for module in [m for m in sys.modules.keys() if m == 'zim' or m.startswith('zim.')]: if sys.modules[module] is None: continue file = sys.modules[module].__file__ assert file.startswith(mylib), \ 'Module %s was loaded from %s' % (module, file) test_report(result, 'test_report.html') print '\nWrote test report to test_report.html\n' # Create coverage output if asked to do so if coverage: coverage.stop() #~ coverage.combine() print 'Writing coverage reports...' pyfiles = list(tests.zim_pyfiles()) #~ coverage.report(pyfiles, show_missing=False) #~ coverage.html_report(pyfiles, directory='./coverage', omit=['zim/inc/*']) coverage_report(coverage, pyfiles, './coverage') print 'Done - Coverage reports can be found in ./coverage/'
def main(argv=None): '''Run either all tests, or those specified in argv''' if argv is None: argv = sys.argv # parse options covreport = False failfast = False loglevel = logging.WARNING opts, args = getopt.gnu_getopt(argv[1:], 'hVD', ['help', 'coverage', 'fast', 'failfast', 'ff', 'full', 'debug', 'verbose']) for o, a in opts: if o in ('-h', '--help'): print '''\ usage: %s [OPTIONS] [MODULES] Where MODULE should a module name from ./tests/ If no module is given the whole test suite is run. Options: -h, --help print this text --fast skip a number of slower tests and mock filesystem --failfast stop after the first test that fails --ff alias for "--fast --failfast" --full full test for using filesystem without mock --coverage report test coverage statistics -V, --verbose run with verbose output from logging -D, --debug run with debug output from logging ''' % argv[0] return elif o == '--coverage': if coverage: covreport = True else: print >>sys.stderr, '''\ Can not run test coverage without module 'coverage'. On Ubuntu or Debian install package 'python-coverage'. ''' sys.exit(1) elif o == '--fast': tests.FAST_TEST = True # set before any test classes are loaded ! elif o == '--failfast': failfast = True elif o == '--ff': # --fast --failfast tests.FAST_TEST = True failfast = True elif o == '--full': tests.FULL_TEST = True elif o in ('-V', '--verbose'): loglevel = logging.INFO elif o in ('-D', '--debug'): loglevel = logging.DEBUG else: assert False, 'Unkown option: %s' % o # Start tracing if coverage: cov = coverage.coverage(source=['zim'], branch=True) cov.erase() # clean up old date set cov.exclude('assert ') cov.exclude('raise NotImplementedError') cov.start() # Set logging handler (don't use basicConfig here, we already installed stuff) handler = logging.StreamHandler() handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s')) logger = logging.getLogger() logger.setLevel(loglevel) logger.addHandler(handler) # Build the test suite loader = unittest.TestLoader() try: if args: suite = unittest.TestSuite() for name in args: module = name if name.startswith('tests.') else 'tests.' + name test = loader.loadTestsFromName(module) suite.addTest(test) else: suite = tests.load_tests(loader, None, None) except AttributeError, error: # HACK: unittest raises and attribute errors if import of test script # fails try to catch this and show the import error instead - else raise # original error import re m = re.match(r"'module' object has no attribute '(\w+)'", error.args[0]) if m: module = m.group(1) m = __import__('tests.'+module) # should raise ImportError raise error
#!/usr/bin/env python # -*- coding: utf-8 -*- __author__ = 'James Iter' __date__ = '15/5/17' __contact__ = '*****@*****.**' __copyright__ = '(c) 2015 by James Iter.' import tests import unittest if __name__ == '__main__': suite = tests.load_tests(unittest.TestLoader(), unittest.TestSuite()) unittest.TextTestRunner(verbosity=2).run(suite)