Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 7cb5d42

Browse files
authored
Merge pull request #215 from Honny1/fix-details-tests
Fix details
2 parents 76d40e0 + f8db143 commit 7cb5d42

File tree

21 files changed

+64
-71
lines changed

21 files changed

+64
-71
lines changed

oval_graph/arf_xml_parser/_comments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from .global_namespaces import namespaces
22

33

4-
class _Comments:
4+
class _Comments: # pylint: disable=R0903
55
def __init__(self, oval_definitions):
66
self.oval_definitions = oval_definitions
77

oval_graph/arf_xml_parser/_oval_scan_definitions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
STR_NEGATE_BOOL = {'true': 'false', 'false': 'true'}
66

77

8-
class _OVALScanDefinitions:
8+
class _OVALScanDefinitions: # pylint: disable=R0903
99
def __init__(self, definitions, oval_definitions, report_data):
1010
self.definitions = definitions
1111
self.comments_parser = _Comments(oval_definitions)

oval_graph/arf_xml_parser/_test_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
MAX_MESSAGE_LEN = 99
66

77

8-
class _TestInfo:
8+
class _TestInfo: # pylint: disable=R0903
99
def __init__(self, report_data):
1010
self.report_data = report_data
1111
self.oval_definitions = self._get_oval_definitions()
@@ -124,7 +124,7 @@ def _get_ref_var(self, element, collected_object):
124124
@staticmethod
125125
def _complete_message(item, var_id):
126126
if len(item.text) == MAX_MESSAGE_LEN and var_id[:item.text.find('(')] in var_id:
127-
return "{}{})".format(item.text[:item.text.find('(') + 1], var_id)
127+
return f"{item.text[:item.text.find('(') + 1]}{var_id})"
128128
return item.text
129129

130130
@staticmethod

oval_graph/arf_xml_parser/arf_xml_parser.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ def __init__(self, src):
2424
if not self.validate(self.arf_schemas_path):
2525
start_red_color = '\033[91m'
2626
end_red_color = '\033[0m'
27-
message = "{}Warning: This file is not valid arf report.{}".format(
28-
start_red_color, end_red_color)
29-
print(message, file=sys.stderr)
27+
message = "Warning: This file is not valid arf report."
28+
print(f"{start_red_color}{message}{end_red_color}", file=sys.stderr)
3029
try:
3130
self.used_rules, self.not_tested_rules = self._get_rules_in_profile()
3231
self.report_data_href = list(self.used_rules.values())[0]['href']
@@ -37,8 +36,8 @@ def __init__(self, src):
3736
self.definitions, self.oval_definitions, self.report_data).get_scan()
3837
except BaseException as error:
3938
raise ValueError(
40-
'This file "{}" is not arf report file or there are no results'.format(
41-
self.src)) from error
39+
f'This file "{self.src}" is not arf report file or there are no results'
40+
) from error
4241

4342
def validate(self, xsd_path):
4443
xsd_path = str(LOCAL_DATA_DIR / xsd_path)
@@ -105,9 +104,9 @@ def _get_definition_of_rule(self, rule_id):
105104

106105
if rule_id in self.not_tested_rules:
107106
raise NotTestedRule(
108-
'Rule "{}" is {}, so there are no results.'
109-
.format(rule_id, self.not_tested_rules[rule_id]))
110-
raise ValueError('404 rule "{}" not found!'.format(rule_id))
107+
f'Rule "{rule_id}" is {self.not_tested_rules[rule_id]}, so there are no results.'
108+
)
109+
raise ValueError(f'404 rule "{rule_id}" not found!')
111110

112111
def get_oval_tree(self, rule_id):
113112
return Builder.dict_of_rule_to_oval_tree(

oval_graph/command_line.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def catch_errors(client_class, params):
3333
except ERRORS as error:
3434
if client.verbose:
3535
traceback.print_exc()
36-
print('{}Error: {}{}'.format(C_RED, error, C_END))
36+
print(f'{C_RED}Error: {error}{C_END}')
3737

3838

3939
def main(client):

oval_graph/command_line_client/arf_to_json.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ def file_is_empty(path):
2929

3030
def save_dict_as_json(self, dict_, src):
3131
if os.path.isfile(src) and not self.file_is_empty(src):
32-
with open(src, "r") as file_:
32+
with open(src, "r", encoding="utf-8") as file_:
3333
data = json.load(file_)
3434
dict_.update(data)
35-
with open(src, "w+") as file_:
35+
with open(src, "w+", encoding="utf-8") as file_:
3636
json.dump(dict_, file_)
3737

3838
def _get_rule_key(self, rule):
@@ -41,7 +41,7 @@ def _get_rule_key(self, rule):
4141
def prepare_data(self, rules):
4242
out = []
4343
rule = None
44-
out_oval_tree_dict = dict()
44+
out_oval_tree_dict = {}
4545
for rule in rules['rules']:
4646
try:
4747
out_oval_tree_dict[self._get_rule_key(rule)] = self.create_dict_of_rule(rule)

oval_graph/command_line_client/client_arf_input.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ def search_rules_id(self):
5353
wanted_rules = self._get_wanted_rules(self.arf_xml_parser.used_rules.keys())
5454
not_tested_rule = self.get_matched_not_tested_rules()
5555
if not wanted_rules and not not_tested_rule:
56-
raise ValueError('404 rule "{}" not found!'.format(self.rule_name))
56+
raise ValueError(f'404 rule "{self.rule_name}" not found!')
5757
if self.rule_name in not_tested_rule:
58-
raise NotTestedRule(
59-
'Rule "{}" is {}, so there are no results.'
60-
.format(self.rule_name, self.arf_xml_parser.not_tested_rules[self.rule_name]))
58+
raise NotTestedRule((
59+
f'Rule "{self.rule_name}" '
60+
f'is {self.arf_xml_parser.not_tested_rules[self.rule_name]},'
61+
' so there are no results.'))
6162
return wanted_rules

oval_graph/command_line_client/client_html_output.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def _put_to_dict_oval_trees(self, dict_oval_trees, rule):
3535
raise NotImplementedError
3636

3737
def _prepare_data(self, rules):
38-
dict_oval_trees = dict()
38+
dict_oval_trees = {}
3939
paths_to_generated_rules = []
4040
if len(rules['rules']) == 1:
4141
self.selected_only_one_rule = True
@@ -50,7 +50,7 @@ def _prepare_data(self, rules):
5050
except NotTestedRule as error:
5151
start_red_color = '\033[91m'
5252
end_red_color = '\033[0m'
53-
message = '{}{}{}'.format(start_red_color, str(error), end_red_color)
53+
message = f'{start_red_color}{str(error)}{end_red_color}'
5454
raise NotTestedRule(message) from error
5555
if self.all_in_one:
5656
path = self.get_save_src('rules' + self._get_date())
@@ -63,7 +63,7 @@ def _get_src_for_one_graph(self, rule):
6363

6464
@staticmethod
6565
def get_file_name(rule):
66-
return "{}{}.html".format(START_OF_FILE_NAME, rule)
66+
return f"{START_OF_FILE_NAME}{rule}.html"
6767

6868
def get_save_src(self, rule):
6969
if self.out is not None:
@@ -103,12 +103,14 @@ def _open_web_browser(self, path_to_result):
103103
is_firefox_installed = self._is_firefox_installed()
104104
if is_firefox_installed:
105105
command = ["firefox", path_to_result]
106+
# pylint: disable=bad-option-value,R1732
106107
browser = Popen(command, stdout=PIPE, stderr=PIPE)
107108
self.web_browsers.append(browser)
108109
time.sleep(0.2)
109110
else:
110111
default_web_browser_name = webbrowser.get().name
111112
command = [default_web_browser_name, path_to_result]
113+
# pylint: disable=bad-option-value,R1732
112114
browser = Popen(command, stdout=PIPE, stderr=PIPE)
113115
self.web_browsers.append(browser)
114116
time.sleep(0.2)

oval_graph/command_line_client/client_json_input.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ def _get_rows_of_unselected_rules(self):
2525
raise NotImplementedError
2626

2727
def get_json_data_file(self):
28-
with open(self.source_filename, 'r') as file_:
28+
with open(self.source_filename, 'r', encoding="utf-8") as file_:
2929
try:
3030
return json.load(file_)
3131
except json.JSONDecodeError as error:
3232
raise ValueError(
33-
'Used file "{}" is not valid json.'.format(
34-
self.source_filename)) from error
33+
f'Used file "{self.source_filename}" is not valid json.') from error
3534

3635
def search_rules_id(self):
3736
rules = self._get_wanted_rules(self.json_data_file.keys())
3837
if not rules:
39-
raise ValueError('404 rule "{}" not found!'.format(self.rule_name))
38+
raise ValueError(f'404 rule "{self.rule_name}" not found!')
4039
return rules

oval_graph/html_builder/graph.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def _get_data_of_graphs_in_js(self, dict_of_rules):
9090
json_of_graphs = {self._remove_unfit_chars(key): value
9191
for key, value in dict_of_rules.items()}
9292
data = str(json.dumps(json_of_graphs))
93-
return "var data_of_tree = {};".format(data)
93+
return f"var data_of_tree = {data};"
9494

9595
def _get_titles_and_places_for_graph(self, dict_of_rules):
9696
rules_html = E.div({'id': 'graphs'})
@@ -104,15 +104,15 @@ def _get_titles_and_places_for_graph(self, dict_of_rules):
104104
@staticmethod
105105
def _get_part(part):
106106
out = ''
107-
with open(LOCAL_DATA_DIR / part, "r") as data_file:
107+
with open(LOCAL_DATA_DIR / part, "r", encoding="utf-8") as data_file:
108108
out = ''.join(data_file.readlines())
109109
return out
110110

111111
@staticmethod
112112
def print_output_message(src, rules):
113113
if len(rules) > 1:
114114
rule_names = "\n" + "\n".join(rules)
115-
print('Rules "{}" done!'.format(rule_names), file=sys.stderr)
115+
print(f'Rules "{rule_names}" done!', file=sys.stderr)
116116
else:
117-
print('Rule "{}" done!'.format(rules.pop()), file=sys.stderr)
118-
print('Result is saved:"{}"'.format(src), file=sys.stderr)
117+
print(f'Rule "{rules.pop()}" done!', file=sys.stderr)
118+
print(f'Result is saved:"{src}"', file=sys.stderr)

0 commit comments

Comments
 (0)