0
|
1 |
#
|
|
2 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
|
|
17 |
"""
|
|
18 |
Test the configuration
|
|
19 |
"""
|
|
20 |
import unittest
|
|
21 |
import os
|
3
|
22 |
import re
|
|
23 |
|
0
|
24 |
from testautomation.base_testcase import BaseTestCase
|
|
25 |
from scripttest_common import get_cmd
|
|
26 |
|
|
27 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
28 |
|
|
29 |
class TestConeHelp(BaseTestCase):
|
3
|
30 |
|
|
31 |
def test_get_version(self):
|
|
32 |
cmd = '%s --version' % get_cmd('')
|
|
33 |
out = self.run_command(cmd)
|
|
34 |
print "output from version %s" % out
|
|
35 |
lines = out.split(os.linesep)
|
|
36 |
self.assertTrue(re.match(r'^ConE\s+\d+\.\d+\.\d+.*$', lines[0]))
|
0
|
37 |
|
|
38 |
def test_get_help(self):
|
|
39 |
cmd = '%s -h' % get_cmd('')
|
|
40 |
out = self.run_command(cmd)
|
|
41 |
lines = out.split(os.linesep)
|
|
42 |
self.assertTrue('Available actions ' in lines)
|
|
43 |
|
|
44 |
def test_verbose_level(self):
|
|
45 |
cmd = '%s info --print-runtime-info --verbose=5' % get_cmd('')
|
|
46 |
out = self.run_command(cmd)
|
|
47 |
# Check that there are debug messages in the output
|
3
|
48 |
self.assertTrue('DEBUG: cone' in out)
|
0
|
49 |
self.assertTrue('sys.path contents:' in out)
|
|
50 |
|
|
51 |
def test_empty_verbose_level(self):
|
|
52 |
cmd = '%s info --print-runtime-info --verbose=' % get_cmd('')
|
|
53 |
out = self.run_command(cmd)
|
|
54 |
self.assertTrue('Python version: ' in out)
|
|
55 |
|
|
56 |
def test_runtime_info_logged(self):
|
|
57 |
# This test makes sure that runtime info is always logged
|
|
58 |
# in the log file
|
|
59 |
|
|
60 |
TEST_DIR = os.path.join(ROOT_PATH, "temp", "log_test")
|
|
61 |
self.recreate_dir(TEST_DIR)
|
|
62 |
|
|
63 |
orig_workdir = os.getcwd()
|
|
64 |
os.chdir(TEST_DIR)
|
|
65 |
try:
|
|
66 |
cmd = '%s' % get_cmd('info')
|
|
67 |
self.run_command(cmd)
|
|
68 |
|
|
69 |
# Check that the default log file has been created
|
|
70 |
self.assertTrue(os.path.exists('cone.log'))
|
|
71 |
|
|
72 |
# Check that it contains the runtime info that should
|
|
73 |
# always be logged
|
|
74 |
f = open('cone.log', 'r')
|
|
75 |
try: data = f.read()
|
|
76 |
finally: f.close()
|
|
77 |
self.assertTrue('DEBUG : cone' in data)
|
|
78 |
self.assertTrue('sys.path contents:' in data)
|
|
79 |
self.assertTrue('PATH:' in data)
|
|
80 |
self.assertTrue('PYTHONPATH:' in data)
|
|
81 |
finally:
|
|
82 |
os.chdir(orig_workdir)
|
|
83 |
|
|
84 |
def test_logfile_in_custom_location(self):
|
|
85 |
TEST_DIR = os.path.join(ROOT_PATH, "temp", "log_test_custom_file")
|
|
86 |
self.recreate_dir(TEST_DIR)
|
|
87 |
|
|
88 |
orig_workdir = os.getcwd()
|
|
89 |
os.chdir(TEST_DIR)
|
|
90 |
try:
|
|
91 |
cmd = '%s --log-file foo/bar.log' % get_cmd('info')
|
|
92 |
self.run_command(cmd)
|
|
93 |
|
|
94 |
self.assertFalse(os.path.exists('cone.log'))
|
|
95 |
self.assertTrue(os.path.exists('foo/bar.log'))
|
|
96 |
finally:
|
|
97 |
os.chdir(orig_workdir)
|
|
98 |
|
|
99 |
def test_custom_log_config(self):
|
|
100 |
CONF_FILE = os.path.join(ROOT_PATH, 'testdata', 'log_config.ini')
|
|
101 |
cmd = '%s --log-config "%s"' % (get_cmd('info'), CONF_FILE)
|
|
102 |
out = self.run_command(cmd)
|
|
103 |
self.assertTrue("Level:DEBUG, Logger:cone, Message:sys.path contents:" in out, out)
|
|
104 |
|
3
|
105 |
def test_custom_log_config_with_escaping(self):
|
|
106 |
CONF_FILE = os.path.join(ROOT_PATH, 'testdata', 'log_config.ini')
|
|
107 |
LOG_FILE = os.path.join(ROOT_PATH, 'testdata', "log\\x\\cone.log")
|
|
108 |
cmd = '%s --log-config "%s" --log-file "%s"' % (get_cmd('info'), CONF_FILE, LOG_FILE)
|
|
109 |
out = self.run_command(cmd)
|
|
110 |
self.assertTrue("Level:DEBUG, Logger:cone, Message:sys.path contents:" in out, out)
|
|
111 |
|
|
112 |
|
0
|
113 |
if __name__ == '__main__':
|
3
|
114 |
unittest.main()
|
|
115 |
|