Skip to content

Commit 0595503

Browse files
Increase utests (#2585)
* Fix saving console_log in Linux. Add unit tests from TestRunner submodules * Set version to 2.0.4.1 * Increase tests for FileWriter
1 parent 1310cb8 commit 0595503

File tree

5 files changed

+258
-2
lines changed

5 files changed

+258
-2
lines changed

src/robotide/contrib/testrunner/FileWriter.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,15 @@ def write(file_path, lines, windows_mode, mode='w'):
5959
f.write(b"\n")
6060
else:
6161
f = codecs.open(file_path, mode, "UTF-8")
62-
f.write("\n".join(lines))
62+
# DEBUG: f.write("\n".join(lines))
63+
for item in lines:
64+
if isinstance(item, str):
65+
f.write(item)
66+
f.write("\n")
67+
else:
68+
try:
69+
f.write(item.decode('UTF-8'))
70+
f.write("\n")
71+
except (UnicodeError, TypeError):
72+
raise
6373
f.close()

src/robotide/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
# limitations under the License.
1515
#
1616
# Automatically generated by `tasks.py`.
17-
VERSION = 'v2.0.4'
17+
VERSION = 'v2.0.4.1'
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Copyright 2023- Robot Framework Foundation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import unittest
16+
17+
from robotide.robotapi import LOG_LEVELS
18+
from robotide.contrib.testrunner.ArgsParser import ArgsParser
19+
20+
DEFAULT_LOGS = '/home/tester/logs'
21+
22+
23+
class ArgsParserTests(unittest.TestCase):
24+
25+
def test_get_message_log_level_default(self):
26+
args = ['-C', 'off',
27+
'-W', 7,
28+
'-P', '/Python Dir:/opt/testlibs',
29+
'-d', 'C:\\Work\\Test 1',
30+
'--suite', 'suite_name_1',
31+
'--test', 'test_1']
32+
result = ArgsParser.get_message_log_level(args)
33+
# print(f"DEBUG: ArgsParserTests {result=}")
34+
self.assertEqual(LOG_LEVELS['INFO'], result) # '-L', 'DEBUG',
35+
36+
def test_get_message_log_level_debug_short(self):
37+
args = ['-L', 'DEBUG',
38+
'--suite', 'suite_name_1',
39+
'--test', 'test_1']
40+
result = ArgsParser.get_message_log_level(args)
41+
self.assertEqual(LOG_LEVELS['DEBUG'], result)
42+
43+
def test_get_message_log_level_debug_full(self):
44+
args = ['-d', 'C:\\Work\\Test 1',
45+
'--suite', 'suite_name_1',
46+
'--loglevel', 'DEBUG',
47+
'--test', 'test_1']
48+
result = ArgsParser.get_message_log_level(args)
49+
self.assertEqual(LOG_LEVELS['DEBUG'], result)
50+
51+
def test_get_message_log_level_invalid(self):
52+
args = ['--suite', 'suite_name_1',
53+
'--loglevel', 'INVALID',
54+
'--test', 'test_1']
55+
self.assertRaises(TypeError, ArgsParser.get_message_log_level, args)
56+
57+
def test_get_message_log_level_info_from_multiple(self):
58+
args = ['-L', 'INFO',
59+
'--test', 'test_1',
60+
'--loglevel', 'WARN']
61+
result = ArgsParser.get_message_log_level(args)
62+
self.assertEqual(LOG_LEVELS['INFO'], result)
63+
64+
def test_get_message_log_level_none(self):
65+
args = ['--test', 'test_1',
66+
'--loglevel', 'NONE']
67+
result = ArgsParser.get_message_log_level(args)
68+
self.assertEqual(LOG_LEVELS['NONE'], result)
69+
70+
def test_get_message_log_level_skip(self):
71+
args = ['--test', 'test_1',
72+
'-L', 'SKIP']
73+
result = ArgsParser.get_message_log_level(args)
74+
self.assertEqual(LOG_LEVELS['SKIP'], result)
75+
76+
def test_get_message_log_level_fail(self):
77+
args = ['--test', 'test_1',
78+
'-L', 'FAIL']
79+
result = ArgsParser.get_message_log_level(args)
80+
self.assertEqual(LOG_LEVELS['FAIL'], result)
81+
82+
def test_get_message_log_level_error(self):
83+
args = ['--test', 'test_1',
84+
'-L', 'ERROR']
85+
result = ArgsParser.get_message_log_level(args)
86+
self.assertEqual(LOG_LEVELS['ERROR'], result)
87+
88+
def test_get_message_log_level_warn(self):
89+
args = ['--test', 'test_1',
90+
'-L', 'WARN']
91+
result = ArgsParser.get_message_log_level(args)
92+
self.assertEqual(LOG_LEVELS['WARN'], result)
93+
94+
def test_get_message_log_level_trace(self):
95+
args = ['--test', 'test_1',
96+
'-L', 'TRACE']
97+
result = ArgsParser.get_message_log_level(args)
98+
self.assertEqual(LOG_LEVELS['TRACE'], result)
99+
100+
def test_get_message_log_level_trace_from_all(self):
101+
args = ['--test', 'test_1',
102+
'--loglevel', 'NONE:SKIP:FAIL:ERROR:WARN:INFO:DEBUG:TRACE']
103+
result = ArgsParser.get_message_log_level(args)
104+
self.assertEqual(LOG_LEVELS['TRACE'], result)
105+
106+
def test_get_output_directory_default(self):
107+
args = ['-L', 'INFO:DEBUG',
108+
'--suite', 'suite_name_1',
109+
'--test', 'test_1']
110+
result = ArgsParser.get_output_directory(args, DEFAULT_LOGS)
111+
self.assertEqual(DEFAULT_LOGS, result)
112+
113+
def test_get_output_directory_short(self):
114+
args = ['-d', '/tmp/logs',
115+
'--suite', 'suite_name_1',
116+
'--test', 'test_1']
117+
result = ArgsParser.get_output_directory(args, DEFAULT_LOGS)
118+
self.assertEqual('/tmp/logs', result)
119+
120+
def test_get_output_directory_long(self):
121+
args = ['--outputdir', '/temp/report',
122+
'--suite', 'suite_name_1',
123+
'--test', 'test_1']
124+
result = ArgsParser.get_output_directory(args, DEFAULT_LOGS)
125+
self.assertEqual('/temp/report', result)
126+
127+
128+
if __name__ == '__main__':
129+
unittest.main()
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Copyright 2023- Robot Framework Foundation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
import os
15+
import tempfile
16+
import unittest
17+
18+
from robotide.contrib.testrunner.FileWriter import FileWriter
19+
20+
21+
class FileWriterTests(unittest.TestCase):
22+
23+
def test_file_writer(self):
24+
tmp_dir = tempfile.mkdtemp()
25+
temp_file = tempfile.mkstemp(dir=tmp_dir)
26+
temp_file = os.path.join(tmp_dir, temp_file[1])
27+
args = ['-C', 'off',
28+
'-W', '7',
29+
'-P', '/Python Dir:/opt/testlibs',
30+
'-d', 'C:\\Work\\Test 1',
31+
'--suite', 'suite_name_1',
32+
'--test', 'test_1']
33+
FileWriter.write(temp_file, args, 'wb')
34+
with open(temp_file, 'r') as file_reader:
35+
lines = file_reader.readlines()
36+
try:
37+
os.remove(temp_file)
38+
except PermissionError:
39+
pass
40+
content = [s.strip() for s in lines]
41+
self.assertListEqual(content, args)
42+
43+
def test_file_writer_new_file(self):
44+
temp_file = "/tmp/a/b/new_file.txt"
45+
args = ['-C', 'off',
46+
'-W', '7',
47+
'-P', '/Python Dir:/opt/testlibs',
48+
'-d', 'C:\\Work\\Test 1',
49+
'--suite', 'suite_name_1',
50+
'--test', 'test_1']
51+
FileWriter.write(temp_file, args, 'wb')
52+
with open(temp_file, 'r') as file_reader:
53+
lines = file_reader.readlines()
54+
try:
55+
os.remove(temp_file)
56+
except PermissionError:
57+
pass
58+
content = [s.strip() for s in lines]
59+
self.assertListEqual(content, args)
60+
61+
def test_file_writer_bytes(self):
62+
tmp_dir = tempfile.mkdtemp()
63+
temp_file = tempfile.mkstemp(dir=tmp_dir)
64+
temp_file = os.path.join(tmp_dir, temp_file[1])
65+
args = [b'-C', b'off',
66+
b'-W', b'7',
67+
b'-P', b'/Python Dir:/opt/testlibs',
68+
b'-d', b'C:\\Work\\Test 1',
69+
b'--suite', b'suite_name_1',
70+
b'--test', b'test_1']
71+
FileWriter.write(temp_file, args, 'wb', 'wb')
72+
with open(temp_file, 'rb') as file_reader:
73+
lines = file_reader.readlines()
74+
try:
75+
os.remove(temp_file)
76+
except PermissionError:
77+
pass
78+
content = [s.strip() for s in lines]
79+
self.assertListEqual(content, args)
80+
81+
82+
if __name__ == '__main__':
83+
unittest.main()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2023- Robot Framework Foundation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import unittest
16+
17+
from robotide.contrib.testrunner.SettingsParser import SettingsParser
18+
19+
20+
class SettingsParserTests(unittest.TestCase):
21+
22+
def test_get_console_log_name_default(self):
23+
settings = ['message_log_name', 'Messages.txt']
24+
result = SettingsParser.get_console_log_name(settings)
25+
self.assertEqual('', result)
26+
27+
def test_get_console_log_name(self):
28+
settings = ['console_log_name', 'Console Log.txt']
29+
result = SettingsParser.get_console_log_name(settings)
30+
self.assertEqual('Console Log.txt', result)
31+
32+
33+
if __name__ == '__main__':
34+
unittest.main()

0 commit comments

Comments
 (0)