|
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 string |
|
22 import sys |
|
23 import os |
|
24 import subprocess |
|
25 import __init__ |
|
26 from testautomation.base_testcase import BaseTestCase |
|
27 from scripttest_common import get_cmd |
|
28 |
|
29 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
|
30 |
|
31 class TestConeHelp(BaseTestCase): |
|
32 |
|
33 def test_get_help(self): |
|
34 cmd = '%s -h' % get_cmd('') |
|
35 out = self.run_command(cmd) |
|
36 lines = out.split(os.linesep) |
|
37 self.assertTrue('Available actions ' in lines) |
|
38 |
|
39 def test_verbose_level(self): |
|
40 cmd = '%s info --print-runtime-info --verbose=5' % get_cmd('') |
|
41 out = self.run_command(cmd) |
|
42 # Check that there are debug messages in the output |
|
43 self.assertTrue('DEBUG : cone' in out) |
|
44 self.assertTrue('sys.path contents:' in out) |
|
45 |
|
46 def test_empty_verbose_level(self): |
|
47 cmd = '%s info --print-runtime-info --verbose=' % get_cmd('') |
|
48 out = self.run_command(cmd) |
|
49 self.assertTrue('Python version: ' in out) |
|
50 |
|
51 def test_runtime_info_logged(self): |
|
52 # This test makes sure that runtime info is always logged |
|
53 # in the log file |
|
54 |
|
55 TEST_DIR = os.path.join(ROOT_PATH, "temp", "log_test") |
|
56 self.recreate_dir(TEST_DIR) |
|
57 |
|
58 orig_workdir = os.getcwd() |
|
59 os.chdir(TEST_DIR) |
|
60 try: |
|
61 cmd = '%s' % get_cmd('info') |
|
62 self.run_command(cmd) |
|
63 |
|
64 # Check that the default log file has been created |
|
65 self.assertTrue(os.path.exists('cone.log')) |
|
66 |
|
67 # Check that it contains the runtime info that should |
|
68 # always be logged |
|
69 f = open('cone.log', 'r') |
|
70 try: data = f.read() |
|
71 finally: f.close() |
|
72 self.assertTrue('DEBUG : cone' in data) |
|
73 self.assertTrue('sys.path contents:' in data) |
|
74 self.assertTrue('PATH:' in data) |
|
75 self.assertTrue('PYTHONPATH:' in data) |
|
76 finally: |
|
77 os.chdir(orig_workdir) |
|
78 |
|
79 def test_logfile_in_custom_location(self): |
|
80 TEST_DIR = os.path.join(ROOT_PATH, "temp", "log_test_custom_file") |
|
81 self.recreate_dir(TEST_DIR) |
|
82 |
|
83 orig_workdir = os.getcwd() |
|
84 os.chdir(TEST_DIR) |
|
85 try: |
|
86 cmd = '%s --log-file foo/bar.log' % get_cmd('info') |
|
87 self.run_command(cmd) |
|
88 |
|
89 self.assertFalse(os.path.exists('cone.log')) |
|
90 self.assertTrue(os.path.exists('foo/bar.log')) |
|
91 finally: |
|
92 os.chdir(orig_workdir) |
|
93 |
|
94 def test_custom_log_config(self): |
|
95 CONF_FILE = os.path.join(ROOT_PATH, 'testdata', 'log_config.ini') |
|
96 cmd = '%s --log-config "%s"' % (get_cmd('info'), CONF_FILE) |
|
97 out = self.run_command(cmd) |
|
98 self.assertTrue("Level:DEBUG, Logger:cone, Message:sys.path contents:" in out, out) |
|
99 |
|
100 if __name__ == '__main__': |
|
101 unittest.main() |
|
102 |