CT metric code pylint clean up
Changes:
- W0611: Unused import
- C0116: Missing function or method docstring
- W1514: Using open without explicitly specifying an encoding
- R1732: Consider using 'with' for resource-allocating operations
- C0103: Variable name
- C0115: Missing class docstring
- R1722: Consider using 'sys.exit'
Tested:
- Ran the script with test data.
Change-Id: I2f2930ee488e88cb40ab37cae575619d020c5919
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/tools/ct_metrics/gen_csv_results.py b/tools/ct_metrics/gen_csv_results.py
index ccdf966..e46dca4 100755
--- a/tools/ct_metrics/gen_csv_results.py
+++ b/tools/ct_metrics/gen_csv_results.py
@@ -8,19 +8,16 @@
import csv
import datetime
-import getopt
import os
-import re
import stat
import sys
from xml.etree import ElementTree
-import robot.errors
from robot.api import ExecutionResult
from robot.result.visitor import ResultVisitor
# Remove the python library path to restore with local project path later.
-save_path_0 = sys.path[0]
+SAVE_PATH_0 = sys.path[0]
del sys.path[0]
sys.path.append(os.path.join(os.path.dirname(__file__), "../../lib"))
@@ -29,7 +26,7 @@
from gen_valid import * # NOQA
# Restore sys.path[0].
-sys.path.insert(0, save_path_0)
+sys.path.insert(0, SAVE_PATH_0)
this_program = sys.argv[0]
@@ -149,7 +146,7 @@
# Calling exit prevents us from returning to the code that was running
# when the signal was received.
- exit(0)
+ sys.exit(0)
def validate_parms():
@@ -242,16 +239,20 @@
print("Test End Time:\t\t %s" % result.suite.endtime)
print("--------------------------------------")
- # Use ResultVisitor object and save off the test data info
+ # Use ResultVisitor object and save off the test data info.
class TestResult(ResultVisitor):
+ r"""
+ Class methods to save off the test data information.
+ """
+
def __init__(self):
- self.testData = []
+ self.test_data = []
def visit_test(self, test):
- self.testData += [test]
+ self.test_data += [test]
- collectDataObj = TestResult()
- result.visit(collectDataObj)
+ collect_data_obj = TestResult()
+ result.visit(collect_data_obj)
# Write the result statistics attributes to CSV file
l_csvlist = []
@@ -322,7 +323,7 @@
print("Writing data into csv file:%s" % l_csvfile)
- for testcase in collectDataObj.testData:
+ for testcase in collect_data_obj.test_data:
# Functional Area: Suite Name
# Test Name: Test Case Name
l_func_area = str(testcase.parent).split(" ", 1)[1]
@@ -360,10 +361,11 @@
l_csvlist.append(l_data)
# Open the file and write to the CSV file
- l_file = open(l_csvfile, "w")
- l_writer = csv.writer(l_file, lineterminator="\n")
- l_writer.writerows(l_csvlist)
- l_file.close()
+ with open(l_csvfile, "w", encoding="utf8") as l_file:
+ l_writer = csv.writer(l_file, lineterminator="\n")
+ l_writer.writerows(l_csvlist)
+ l_file.close()
+
# Set file permissions 666.
perm = (
stat.S_IRUSR
@@ -408,7 +410,7 @@
bmc_version_id = ""
bmc_platform = ""
- with open(xml_file_path, "rt") as output:
+ with open(xml_file_path, "rt", encoding="utf-8") as output:
tree = ElementTree.parse(output)
for node in tree.iter("msg"):
@@ -428,6 +430,10 @@
def main():
+ r"""
+ Main caller.
+ """
+
if not gen_get_options(parser, stock_list):
return False
@@ -446,4 +452,4 @@
# Main
if not main():
- exit(1)
+ sys.exit(1)