dovetail tool: add unit test into script unittest.sh 69/25469/1
authorxudan <xudan16@huawei.com>
Mon, 5 Dec 2016 08:28:20 +0000 (08:28 +0000)
committerxudan <xudan16@huawei.com>
Mon, 5 Dec 2016 08:38:22 +0000 (08:38 +0000)
1. Since JIRA: DOVETAIL-55 has been merged, unit tests can't pass without
   load_config_files().
2. Fix the bug by adding load_config_files().
3. Add run_tests() into script unittest.sh to include all unit tests in
   tests/unit.

JIRA: DOVETAIL-149

Change-Id: I7bdb0732fefde3a3f3b82441b4cc7e46ece66a1e
Signed-off-by: xudan <xudan16@huawei.com>
dovetail/tests/unit/test_parser.py
unittests/unittest.sh

index b4331ea..2183bd6 100644 (file)
@@ -14,7 +14,6 @@ Test 'parser' module
 import logging
 import os
 import unittest
-
 import yaml
 
 import parser as dovetail_parser
@@ -26,8 +25,10 @@ class TestParser(unittest.TestCase):
 
     def setUp(self):
         """Test case setup"""
-        logging.disable(logging.CRITICAL)
+        from conf.dovetail_config import DovetailConfig as dt_config
+        dt_config.load_config_files()
         dovetail_parser.Parser.create_log()
+        logging.disable(logging.CRITICAL)
 
     def test_parser_cmd(self):
         """Test whether the command is correctly parsed."""
index 1560a90..215d0eb 100755 (executable)
@@ -35,4 +35,26 @@ run_flake8() {
     fi
 }
 
+run_tests() {
+    echo "Running unittest ..."
+    cd dovetail/
+    if [ $FILE_OPTION == "f" ]; then
+        python -m unittest discover -v -s tests/unit > $logfile 2>&1
+    else
+        python -m unittest discover -v -s tests/unit
+    fi
+
+    if [ $? -ne 0 ]; then
+        if [ $FILE_OPTION == "f" ]; then
+            echo "FAILED, results in $logfile"
+        fi
+        exit 1
+    else
+        if [ $FILE_OPTION == "f" ]; then
+            echo "OK, results in $logfile"
+        fi
+    fi
+}
+
 run_flake8
+run_tests