mirror of
https://github.com/yweber/lodel2.git
synced 2025-10-30 19:19:03 +01:00
Tests enhancements
This commit is contained in:
parent
5055b2a6ef
commit
f612e62fbc
6 changed files with 148 additions and 58 deletions
14
nocontext_tests.py
Normal file
14
nocontext_tests.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#-*- coding: utf-8 -*-
|
||||
|
||||
import sys, os, os.path
|
||||
import unittest
|
||||
import nocontext_tests
|
||||
|
||||
loader = unittest.TestLoader()
|
||||
|
||||
suite = loader.discover('tests', pattern='nc_test*.py')
|
||||
with open(sys.argv[1]+'/nocontext_tests.log', 'w') as logfile:
|
||||
unittest.TextTestRunner(
|
||||
logfile,
|
||||
failfast = '-f' in sys.argv,
|
||||
verbosity = 2 if '-v' in sys.argv else 1).run(suite)
|
||||
Binary file not shown.
|
|
@ -63,11 +63,12 @@ if __name__ == '__main__':
|
|||
import tests
|
||||
loader = unittest.TestLoader()
|
||||
test_dir = os.path.join(LODEL2_LIB_ABS_PATH, 'tests')
|
||||
suite = loader.discover(test_dir)
|
||||
runner = unittest.TextTestRunner(
|
||||
failfast = '-f' in sys.argv,
|
||||
verbosity = 2 if '-v' in sys.argv else 1)
|
||||
runner.run(suite)
|
||||
suite = loader.discover(test_dir, pattern='test*.py')
|
||||
with open(sys.argv[1]+'/context_tests.log', 'w') as logfile:
|
||||
unittest.TextTestRunner(
|
||||
logfile,
|
||||
failfast = '-f' in sys.argv,
|
||||
verbosity = 2 if '-v' in sys.argv else 1).run(suite)
|
||||
exit()
|
||||
|
||||
lodel = LodelContext.get()
|
||||
|
|
|
|||
104
runtest.sh
104
runtest.sh
|
|
@ -3,42 +3,21 @@
|
|||
# Usage : ./runtest [OPTIONS] [test_module[.test_class][ test_module2[.test_class2]...]
|
||||
#########
|
||||
#
|
||||
# Options list :
|
||||
################
|
||||
#
|
||||
# -b, --buffer
|
||||
#
|
||||
# The standard output and standard error streams are buffered during the test run. Output during a passing test is discarded. Output is echoed normally on test fail or error and is added to the failure messages.
|
||||
#
|
||||
# -c, --catch
|
||||
#
|
||||
# Control-C during the test run waits for the current test to end and then reports all the results so far. A second control-C raises the normal KeyboardInterrupt exception.
|
||||
#
|
||||
#
|
||||
# -f, --failfast
|
||||
#
|
||||
# Stop the test run on the first error or failure.
|
||||
#
|
||||
# -h, --help
|
||||
#
|
||||
# Get some help
|
||||
#
|
||||
# -v, --verbose
|
||||
#
|
||||
# higher verbosity
|
||||
#
|
||||
# Examples :
|
||||
############
|
||||
#
|
||||
# Running all discoverables tests :
|
||||
# ./runtest
|
||||
#
|
||||
# Running only Em test about component object (only tests about the __init__ and modify_rank methods) with higher verbosity and failfast :
|
||||
# ./runtest -fv EditorialModel.test.test_component.TestInit EditorialModel.test.test_component.TestModifyRank
|
||||
# Options
|
||||
################
|
||||
# -f, --failfast
|
||||
#
|
||||
# Stop the test run on the first error or failure.
|
||||
# -v --verbose
|
||||
#
|
||||
# Running only Em tests
|
||||
# ./runtest discover EditorialModel
|
||||
# higher verbosity
|
||||
#
|
||||
# -d 0 : results are stored in logfiles in /tmp/logXXXXXXX repository, with XXXXXXX a timestamp (default)
|
||||
# -d 1 : results are displayed when tests finish and kept in logfiles in /tmp/logXXXXXXX repository, with XXXXXXX a timestamp
|
||||
# -d 2 : results are displayed when tests finish, they are not stored
|
||||
#
|
||||
# More details :
|
||||
################
|
||||
|
|
@ -52,24 +31,47 @@ then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
PYTHON='env python3'
|
||||
testdir=$(mktemp -td "lodel2_unittest_instance_XXXXXXXX")
|
||||
install_model_dir="[@]INSTALLMODEL_DIR[@]"
|
||||
if [ ! -d "$install_model_dir" ]
|
||||
then
|
||||
install_model_dir="$(dirname $0)/progs/slim/install_model/"
|
||||
fi
|
||||
libdir="$(dirname $(realpath $0))/lodel"
|
||||
rmdir $testdir
|
||||
./progs/create_instance test_instance $testdir "$install_model_dir" ./examples/em_test.pickle "$libdir"
|
||||
echo ./progs/create_instance test_instance $testdir "$install_model_dir" ./examples/em_test.pickle "$libdir"
|
||||
cp -R examples $testdir
|
||||
cp -R tests $testdir
|
||||
cd $testdir
|
||||
chmod +x lodel_admin.py
|
||||
rm -R conf.d && mv tests/tests_conf.d conf.d
|
||||
make
|
||||
make refresh_plugins
|
||||
$PYTHON loader.py $@
|
||||
logdisplay=0;
|
||||
|
||||
while getopts ":d:" opt; do
|
||||
case $opt in
|
||||
d)
|
||||
logdisplay=$OPTARG
|
||||
;;
|
||||
:)
|
||||
echo "Option -$OPTARG requires an argument, as it does not have we assume 0"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ $logdisplay -eq 2 ]]
|
||||
then
|
||||
echo $logdisplay
|
||||
logdir=$(mktemp -td "lodel2_log_unittest_XXXXXXX")
|
||||
else
|
||||
if [ ! -d ./tmp ]
|
||||
then
|
||||
mkdir ./tmp
|
||||
fi
|
||||
timestamp=$(date +%s)
|
||||
logdir="$(dirname $(realpath $0))/tmp/log$timestamp"
|
||||
mkdir $logdir
|
||||
fi
|
||||
|
||||
PYTHON='env python3'
|
||||
$PYTHON ./nocontext_tests.py $logdir $@
|
||||
./runtest_context.sh $logdir $@
|
||||
|
||||
if [[ $logdisplay -eq 1 || $logdisplay -eq 2 ]]
|
||||
then
|
||||
logfiles=$(ls $logdir)
|
||||
for logfile in $logfiles
|
||||
do
|
||||
more $logdir/$logfile
|
||||
done
|
||||
if [[ $logdisplay -eq 2 ]]
|
||||
then
|
||||
rm -rf $logdir
|
||||
fi
|
||||
fi
|
||||
|
||||
rm -Rf $testdir
|
||||
|
|
|
|||
75
runtest_context.sh
Executable file
75
runtest_context.sh
Executable file
|
|
@ -0,0 +1,75 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Usage : ./runtest [OPTIONS] [test_module[.test_class][ test_module2[.test_class2]...]
|
||||
#########
|
||||
#
|
||||
# Options list :
|
||||
################
|
||||
#
|
||||
# -b, --buffer
|
||||
#
|
||||
# The standard output and standard error streams are buffered during the test run. Output during a passing test is discarded. Output is echoed normally on test fail or error and is added to the failure messages.
|
||||
#
|
||||
# -c, --catch
|
||||
#
|
||||
# Control-C during the test run waits for the current test to end and then reports all the results so far. A second control-C raises the normal KeyboardInterrupt exception.
|
||||
#
|
||||
#
|
||||
# -f, --failfast
|
||||
#
|
||||
# Stop the test run on the first error or failure.
|
||||
#
|
||||
# -h, --help
|
||||
#
|
||||
# Get some help
|
||||
#
|
||||
# -v, --verbose
|
||||
#
|
||||
# higher verbosity
|
||||
#
|
||||
# Examples :
|
||||
############
|
||||
#
|
||||
# Running all discoverables tests :
|
||||
# ./runtest
|
||||
#
|
||||
# Running only Em test about component object (only tests about the __init__ and modify_rank methods) with higher verbosity and failfast :
|
||||
# ./runtest -fv EditorialModel.test.test_component.TestInit EditorialModel.test.test_component.TestModifyRank
|
||||
#
|
||||
#
|
||||
# Running only Em tests
|
||||
# ./runtest discover EditorialModel
|
||||
#
|
||||
# More details :
|
||||
################
|
||||
#
|
||||
# https://docs.python.org/3.4/library/unittest.html
|
||||
#
|
||||
if test ! -f lodel/buildconf.py
|
||||
then
|
||||
echo "You have to build the project before running the tests"
|
||||
echo "See README"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PYTHON='env python3'
|
||||
testdir=$(mktemp -td "lodel2_unittest_instance_XXXXXXXX")
|
||||
install_model_dir="[@]INSTALLMODEL_DIR[@]"
|
||||
if [ ! -d "$install_model_dir" ]
|
||||
then
|
||||
install_model_dir="$(dirname $0)/progs/slim/install_model/"
|
||||
fi
|
||||
libdir="$(dirname $(realpath $0))/lodel"
|
||||
rmdir $testdir
|
||||
progs/create_instance test_instance $testdir "$install_model_dir" examples/em_test.pickle "$libdir"
|
||||
echo progs/create_instance test_instance $testdir "$install_model_dir" examples/em_test.pickle "$libdir"
|
||||
cp -R examples $testdir
|
||||
cp -R tests $testdir
|
||||
cd $testdir
|
||||
chmod +x lodel_admin.py
|
||||
rm -R conf.d && mv tests/tests_conf.d conf.d
|
||||
make
|
||||
make refresh_plugins
|
||||
$PYTHON loader.py $@
|
||||
|
||||
rm -Rf $testdir
|
||||
|
|
@ -3,8 +3,6 @@
|
|||
import unittest
|
||||
import copy
|
||||
|
||||
|
||||
import tests.loader_utils
|
||||
from lodel.utils.mlstring import MlString
|
||||
|
||||
class MlStringTestCase(unittest.TestCase):
|
||||
Loading…
Add table
Add a link
Reference in a new issue