mirror of
				https://github.com/yweber/lodel2.git
				synced 2025-10-31 03:29: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 |         import tests | ||||||
|         loader = unittest.TestLoader() |         loader = unittest.TestLoader() | ||||||
|         test_dir = os.path.join(LODEL2_LIB_ABS_PATH, 'tests') |         test_dir = os.path.join(LODEL2_LIB_ABS_PATH, 'tests') | ||||||
|         suite = loader.discover(test_dir) |         suite = loader.discover(test_dir, pattern='test*.py') | ||||||
|         runner = unittest.TextTestRunner( |         with open(sys.argv[1]+'/context_tests.log', 'w') as logfile: | ||||||
|             failfast = '-f' in sys.argv, |             unittest.TextTestRunner( | ||||||
|             verbosity = 2 if '-v' in sys.argv else 1) |                 logfile, | ||||||
|         runner.run(suite) |                 failfast = '-f' in sys.argv, | ||||||
|  |                 verbosity = 2 if '-v' in sys.argv else 1).run(suite) | ||||||
|         exit() |         exit() | ||||||
| 
 | 
 | ||||||
|     lodel = LodelContext.get() |     lodel = LodelContext.get() | ||||||
|  |  | ||||||
							
								
								
									
										104
									
								
								runtest.sh
									
										
									
									
									
								
							
							
						
						
									
										104
									
								
								runtest.sh
									
										
									
									
									
								
							|  | @ -3,42 +3,21 @@ | ||||||
| # Usage : ./runtest [OPTIONS] [test_module[.test_class][ test_module2[.test_class2]...] | # 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 : | # Running all discoverables tests : | ||||||
| # ./runtest | # ./runtest | ||||||
| # | # | ||||||
| # Running only Em test about component object (only tests about the __init__ and modify_rank methods) with higher verbosity and failfast : | # Options | ||||||
| # ./runtest -fv EditorialModel.test.test_component.TestInit EditorialModel.test.test_component.TestModifyRank | ################ | ||||||
|  | # -f, --failfast | ||||||
| # | # | ||||||
|  | #    Stop the test run on the first error or failure. | ||||||
|  | # -v --verbose | ||||||
| # | # | ||||||
| # Running only Em tests | #   higher verbosity | ||||||
| # ./runtest discover EditorialModel | # | ||||||
|  | # -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 : | # More details : | ||||||
| ################ | ################ | ||||||
|  | @ -52,24 +31,47 @@ then | ||||||
| 	exit 1 | 	exit 1 | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| PYTHON='env python3' | logdisplay=0; | ||||||
| testdir=$(mktemp -td "lodel2_unittest_instance_XXXXXXXX") | 
 | ||||||
| install_model_dir="[@]INSTALLMODEL_DIR[@]" | while getopts ":d:" opt; do | ||||||
| if [ ! -d "$install_model_dir" ] |     case $opt in | ||||||
| then |         d) | ||||||
| 	install_model_dir="$(dirname $0)/progs/slim/install_model/" |           logdisplay=$OPTARG | ||||||
| fi |           ;; | ||||||
| libdir="$(dirname $(realpath $0))/lodel" |         :) | ||||||
| rmdir $testdir |           echo "Option -$OPTARG requires an argument, as it does not have we assume 0" | ||||||
| ./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" |     esac | ||||||
| cp -R examples $testdir | done | ||||||
| cp -R tests $testdir | 
 | ||||||
| cd $testdir | if [[ $logdisplay -eq 2 ]] | ||||||
| chmod +x lodel_admin.py | then | ||||||
| rm -R conf.d && mv tests/tests_conf.d conf.d |     echo $logdisplay | ||||||
| make |     logdir=$(mktemp -td "lodel2_log_unittest_XXXXXXX") | ||||||
| make refresh_plugins | else  | ||||||
| $PYTHON loader.py $@ |     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 unittest | ||||||
| import copy | import copy | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| import tests.loader_utils |  | ||||||
| from lodel.utils.mlstring import MlString | from lodel.utils.mlstring import MlString | ||||||
| 
 | 
 | ||||||
| class MlStringTestCase(unittest.TestCase): | class MlStringTestCase(unittest.TestCase): | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 prieto
				prieto