Browse Source

Tests enhancements

prieto 7 years ago
parent
commit
f612e62fbc

+ 14
- 0
nocontext_tests.py View File

@@ -0,0 +1,14 @@
1
+#-*- coding: utf-8 -*-
2
+
3
+import sys, os, os.path
4
+import unittest
5
+import nocontext_tests
6
+
7
+loader = unittest.TestLoader()
8
+
9
+suite = loader.discover('tests', pattern='nc_test*.py')
10
+with open(sys.argv[1]+'/nocontext_tests.log', 'w') as logfile:
11
+    unittest.TextTestRunner(
12
+    	logfile,
13
+        failfast = '-f' in sys.argv,
14
+        verbosity = 2 if '-v' in sys.argv else 1).run(suite)

BIN
progs/slim/emfile.pickle View File


+ 6
- 5
progs/slim/install_model/loader.py View File

@@ -63,11 +63,12 @@ if __name__ == '__main__':
63 63
         import tests
64 64
         loader = unittest.TestLoader()
65 65
         test_dir = os.path.join(LODEL2_LIB_ABS_PATH, 'tests')
66
-        suite = loader.discover(test_dir)
67
-        runner = unittest.TextTestRunner(
68
-            failfast = '-f' in sys.argv,
69
-            verbosity = 2 if '-v' in sys.argv else 1)
70
-        runner.run(suite)
66
+        suite = loader.discover(test_dir, pattern='test*.py')
67
+        with open(sys.argv[1]+'/context_tests.log', 'w') as logfile:
68
+            unittest.TextTestRunner(
69
+                logfile,
70
+                failfast = '-f' in sys.argv,
71
+                verbosity = 2 if '-v' in sys.argv else 1).run(suite)
71 72
         exit()
72 73
 
73 74
     lodel = LodelContext.get()

+ 48
- 46
runtest.sh View File

@@ -3,42 +3,21 @@
3 3
 # Usage : ./runtest [OPTIONS] [test_module[.test_class][ test_module2[.test_class2]...]
4 4
 #########
5 5
 #
6
-# Options list :
7
-################
8
-#
9
-# -b, --buffer
10
-#
11
-#    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.
12
-#
13
-# -c, --catch
14
-#
15
-#    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.
16
-#
6
+# Running all discoverables tests :
7
+# ./runtest
17 8
 #
9
+# Options
10
+################
18 11
 # -f, --failfast
19 12
 #
20 13
 #    Stop the test run on the first error or failure.
21
-#
22
-# -h, --help
23
-#
24
-#    Get some help
25
-#
26
-# -v, --verbose
14
+# -v --verbose
27 15
 #
28 16
 #   higher verbosity
29 17
 #
30
-# Examples :
31
-############
32
-#
33
-# Running all discoverables tests :
34
-# ./runtest
35
-#
36
-# Running only Em test about component object (only tests about the __init__ and modify_rank methods) with higher verbosity and failfast :
37
-# ./runtest -fv EditorialModel.test.test_component.TestInit EditorialModel.test.test_component.TestModifyRank
38
-#
39
-#
40
-# Running only Em tests
41
-# ./runtest discover EditorialModel
18
+# -d 0 : results are stored in logfiles in /tmp/logXXXXXXX repository, with XXXXXXX a timestamp (default)
19
+# -d 1 : results are displayed when tests finish and kept in logfiles in /tmp/logXXXXXXX repository, with XXXXXXX a timestamp
20
+# -d 2 : results are displayed when tests finish, they are not stored
42 21
 #
43 22
 # More details :
44 23
 ################
@@ -52,24 +31,47 @@ then
52 31
 	exit 1
53 32
 fi
54 33
 
34
+logdisplay=0;
35
+
36
+while getopts ":d:" opt; do
37
+    case $opt in
38
+        d)
39
+          logdisplay=$OPTARG
40
+          ;;
41
+        :)
42
+          echo "Option -$OPTARG requires an argument, as it does not have we assume 0"
43
+          ;;
44
+    esac
45
+done
46
+
47
+if [[ $logdisplay -eq 2 ]]
48
+then
49
+    echo $logdisplay
50
+    logdir=$(mktemp -td "lodel2_log_unittest_XXXXXXX")
51
+else 
52
+    if [ ! -d ./tmp ]
53
+    then
54
+        mkdir ./tmp
55
+    fi
56
+    timestamp=$(date +%s)
57
+    logdir="$(dirname $(realpath $0))/tmp/log$timestamp"
58
+    mkdir $logdir
59
+fi
60
+
55 61
 PYTHON='env python3'
56
-testdir=$(mktemp -td "lodel2_unittest_instance_XXXXXXXX")
57
-install_model_dir="[@]INSTALLMODEL_DIR[@]"
58
-if [ ! -d "$install_model_dir" ]
62
+$PYTHON ./nocontext_tests.py $logdir $@
63
+./runtest_context.sh $logdir $@
64
+
65
+if [[ $logdisplay -eq 1 || $logdisplay -eq 2 ]]
59 66
 then
60
-	install_model_dir="$(dirname $0)/progs/slim/install_model/"
67
+    logfiles=$(ls $logdir)
68
+    for logfile in $logfiles
69
+    do
70
+        more $logdir/$logfile
71
+    done
72
+    if [[ $logdisplay -eq 2 ]]
73
+    then 
74
+        rm -rf $logdir
75
+    fi
61 76
 fi
62
-libdir="$(dirname $(realpath $0))/lodel"
63
-rmdir $testdir
64
-./progs/create_instance test_instance $testdir "$install_model_dir" ./examples/em_test.pickle "$libdir"
65
-echo ./progs/create_instance test_instance $testdir "$install_model_dir" ./examples/em_test.pickle "$libdir"
66
-cp -R examples $testdir
67
-cp -R tests $testdir
68
-cd $testdir
69
-chmod +x lodel_admin.py
70
-rm -R conf.d && mv tests/tests_conf.d conf.d
71
-make
72
-make refresh_plugins
73
-$PYTHON loader.py $@
74 77
 
75
-rm -Rf $testdir

+ 75
- 0
runtest_context.sh View File

@@ -0,0 +1,75 @@
1
+#!/bin/bash
2
+#
3
+# Usage : ./runtest [OPTIONS] [test_module[.test_class][ test_module2[.test_class2]...]
4
+#########
5
+#
6
+# Options list :
7
+################
8
+#
9
+# -b, --buffer
10
+#
11
+#    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.
12
+#
13
+# -c, --catch
14
+#
15
+#    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.
16
+#
17
+#
18
+# -f, --failfast
19
+#
20
+#    Stop the test run on the first error or failure.
21
+#
22
+# -h, --help
23
+#
24
+#    Get some help
25
+#
26
+# -v, --verbose
27
+#
28
+#   higher verbosity
29
+#
30
+# Examples :
31
+############
32
+#
33
+# Running all discoverables tests :
34
+# ./runtest
35
+#
36
+# Running only Em test about component object (only tests about the __init__ and modify_rank methods) with higher verbosity and failfast :
37
+# ./runtest -fv EditorialModel.test.test_component.TestInit EditorialModel.test.test_component.TestModifyRank
38
+#
39
+#
40
+# Running only Em tests
41
+# ./runtest discover EditorialModel
42
+#
43
+# More details :
44
+################
45
+#
46
+# https://docs.python.org/3.4/library/unittest.html
47
+#
48
+if test ! -f lodel/buildconf.py
49
+then
50
+	echo "You have to build the project before running the tests"
51
+	echo "See README"
52
+	exit 1
53
+fi
54
+
55
+PYTHON='env python3'
56
+testdir=$(mktemp -td "lodel2_unittest_instance_XXXXXXXX")
57
+install_model_dir="[@]INSTALLMODEL_DIR[@]"
58
+if [ ! -d "$install_model_dir" ]
59
+then
60
+	install_model_dir="$(dirname $0)/progs/slim/install_model/"
61
+fi
62
+libdir="$(dirname $(realpath $0))/lodel"
63
+rmdir $testdir
64
+progs/create_instance test_instance $testdir "$install_model_dir" examples/em_test.pickle "$libdir"
65
+echo progs/create_instance test_instance $testdir "$install_model_dir" examples/em_test.pickle "$libdir"
66
+cp -R examples $testdir
67
+cp -R tests $testdir
68
+cd $testdir
69
+chmod +x lodel_admin.py
70
+rm -R conf.d && mv tests/tests_conf.d conf.d
71
+make
72
+make refresh_plugins
73
+$PYTHON loader.py $@
74
+
75
+rm -Rf $testdir

tests/test_utils_mlstrings.py → tests/nc_test_utils_mlstrings.py View File

@@ -3,8 +3,6 @@
3 3
 import unittest
4 4
 import copy
5 5
 
6
-
7
-import tests.loader_utils
8 6
 from lodel.utils.mlstring import MlString
9 7
 
10 8
 class MlStringTestCase(unittest.TestCase):

Loading…
Cancel
Save