Skip to content

Commit ce078d6

Browse files
committed
Added few comments to functions. Removed fixed TODO in copy function. Refactored one function to return string instead of priting it.
1 parent a8d4782 commit ce078d6

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

workspace_tools/singletest.py

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -200,24 +200,8 @@ def get_test_loop_count(self, test_id):
200200
return result
201201

202202
def file_copy_method_selector(self, image_path, disk, copy_method):
203-
""" Copy file depending on method you want to use """
204-
# TODO: Add exception handling for copy procedures (disk can be full). See below.
205-
"""
206-
Traceback (most recent call last):
207-
File "mbed\workspace_tools\singletest.py", line 738, in <module>
208-
single_test_result = single_test.handle(test_spec, target, toolchain)
209-
File "mbed\workspace_tools\singletest.py", line 252, in handle
210-
self.file_copy_method_selector(image_path, disk, opts.copy_method)
211-
File "mbed\workspace_tools\singletest.py", line 203, in file_copy_method_selector
212-
copy(image_path, disk)
213-
File "C:\Python27\lib\shutil.py", line 119, in copy
214-
copyfile(src, dst)
215-
File "C:\Python27\lib\shutil.py", line 84, in copyfile
216-
copyfileobj(fsrc, fdst)
217-
File "C:\Python27\lib\shutil.py", line 52, in copyfileobj
218-
fdst.write(buf)
219-
IOError: [Errno 28] No space left on device
220-
"""
203+
""" Copy file depending on method you want to use. Handles exception
204+
and return code from shell copy commands. """
221205
result = True
222206
resutl_msg = ""
223207
if copy_method == "cp" or copy_method == "copy" or copy_method == "xcopy":
@@ -339,6 +323,9 @@ def shape_global_test_loop_result(self, test_all_result):
339323
return result
340324

341325
def run_host_test(self, name, disk, port, duration, verbose=False, extra_serial=""):
326+
""" Function creates new process with host test configured with particular test case.
327+
Function also is pooling for serial port activity from process to catch all data
328+
printed by test runner and host test during test execution."""
342329
# print "{%s} port:%s disk:%s" % (name, port, disk),
343330
cmd = ["python", "%s.py" % name, '-p', port, '-d', disk, '-t', str(duration), "-e", extra_serial]
344331
proc = Popen(cmd, stdout=PIPE, cwd=HOST_TESTS)
@@ -533,6 +520,9 @@ def print_test_configuration_from_json(json_data, join_delim=", "):
533520

534521

535522
def get_avail_tests_summary_table(cols=None, result_summary=True, join_delim=','):
523+
""" Generates table summary with all test cases and additional test cases
524+
information using pretty print functionality. Allows test suite user to
525+
see test cases. """
536526
# get all unique test ID prefixes
537527
unique_test_id = []
538528
for test in TESTS:
@@ -577,8 +567,8 @@ def get_avail_tests_summary_table(cols=None, result_summary=True, join_delim=','
577567
# Update counters
578568
counter_all += 1
579569
counter_dict_test_id_types_all[test_id_prefix] += 1
580-
print pt
581-
print
570+
result = pt.get_string()
571+
result += "\n\n"
582572

583573
if result_summary:
584574
# Automation result summary
@@ -591,9 +581,9 @@ def get_avail_tests_summary_table(cols=None, result_summary=True, join_delim=','
591581
percent_progress = round(100.0 * counter_automated / float(counter_all), 1)
592582
str_progress = progress_bar(percent_progress, 75)
593583
pt.add_row([counter_automated, counter_all, percent_progress, str_progress])
594-
print "Automation coverage:"
595-
print pt
596-
print
584+
result += "Automation coverage:\n"
585+
result += pt.get_string()
586+
result += "\n\n"
597587

598588
# Test automation coverage table print
599589
test_id_cols = ['id', 'automated', 'all', 'percent [%]', 'progress']
@@ -612,10 +602,10 @@ def get_avail_tests_summary_table(cols=None, result_summary=True, join_delim=','
612602
percent_progress,
613603
"[" + str_progress + "]"]
614604
pt.add_row(row)
615-
print "Test automation coverage:"
616-
print pt
617-
print
618-
605+
result += "Test automation coverage:\n"
606+
result += pt.get_string()
607+
result += "\n\n"
608+
return result
619609

620610
def progress_bar(percent_progress, saturation=0):
621611
""" This function creates progress bar with optional simple saturation mark"""
@@ -834,13 +824,13 @@ def generate_test_summary(test_summary):
834824

835825
# Print summary / information about automation test status
836826
if opts.test_automation_report:
837-
get_avail_tests_summary_table()
827+
print get_avail_tests_summary_table()
838828
exit(0)
839829

840830
# Print summary / information about automation test status
841831
if opts.test_case_report:
842832
test_case_report_cols = ['id', 'automated', 'description', 'peripherals', 'host_test', 'duration', 'source_dir']
843-
get_avail_tests_summary_table(cols=test_case_report_cols, result_summary=False, join_delim='\n')
833+
print get_avail_tests_summary_table(cols=test_case_report_cols, result_summary=False, join_delim='\n')
844834
exit(0)
845835

846836
# Only prints matrix of supported toolchains

0 commit comments

Comments
 (0)