Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruff UP015 (1) #34959

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def read_file(input_data, input_type):
return_error("Entry {} not found".format(input_data))
file_path = res['path']
if input_type.startswith('json'):
with open(file_path, 'r') as f:
with open(file_path) as f:
file_content = f.read()
if input_type.startswith('csv'):
return pd.read_csv(file_path).fillna('').to_dict(orient='records')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def test_read_file(mocker):
mocker.patch.object(demisto, 'getFilePath', return_value={'path': './TestData/input_json_file_test'})
obj = read_file('231342@343', 'json')
assert len(obj) >= 1
with open('./TestData/input_json_file_test', 'r') as f:
with open('./TestData/input_json_file_test') as f:
obj = read_file(f.read(), 'json_string')
assert len(obj) >= 1

Expand All @@ -441,15 +441,15 @@ def test_read_file(mocker):
assert len(obj_from_pickle) >= 1

mocker.patch.object(demisto, 'getFilePath', return_value={'path': './TestData/input_json_file_test'})
with open('./TestData/input_json_file_test', 'r') as f:
with open('./TestData/input_json_file_test') as f:
obj = read_file(f.read(), 'json_string')
df = pd.DataFrame.from_dict(obj)
df.to_csv("./TestData/test.csv", index=False)
mocker.patch.object(demisto, 'getFilePath', return_value={'path': './TestData/test.csv'})
obj2 = read_file('231342@343', 'csv')
assert len(obj2) == len(obj)

with open('./TestData/input_json_file_test', 'r') as f:
with open('./TestData/input_json_file_test') as f:
b64_input = base64.b64encode(f.read().encode('utf-8'))
obj = read_file(b64_input, 'json_b64_string')
assert len(obj) >= 1
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def read_file(input_data, input_type):
return_error("Entry {} not found".format(input_data))
file_path = res['path']
if input_type.startswith('json'):
with open(file_path, 'r') as f:
with open(file_path) as f:
file_content = f.read()
if input_type.startswith('csv'):
return pd.read_csv(file_path).fillna('').to_dict(orient='records')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def test_read_file(mocker):
mocker.patch.object(demisto, 'getFilePath', return_value={'path': './TestData/input_json_file_test'})
obj = read_file('231342@343', 'json')
assert len(obj) >= 1
with open('./TestData/input_json_file_test', 'r') as f:
with open('./TestData/input_json_file_test') as f:
obj = read_file(f.read(), 'json_string')
assert len(obj) >= 1
with open('./TestData/input_json_file_test', 'r') as f:
with open('./TestData/input_json_file_test') as f:
b64_input = base64.b64encode(f.read().encode('utf-8')) # base64.b64encode(f.read())
obj = read_file(b64_input, 'json_b64_string')
assert len(obj) >= 1
Expand Down
2 changes: 1 addition & 1 deletion Packs/Base/Scripts/StixParser/StixParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,7 @@ def main(): # pragma: no cover
raise Exception('You must enter iocXml or entry_id of the Indicator.')
elif entry_id:
file_path = demisto.getFilePath(entry_id).get('path')
with open(file_path, 'r') as f:
with open(file_path) as f:
indicator_txt = f.read()

if stix2 := convert_to_json(indicator_txt):
Expand Down
4 changes: 2 additions & 2 deletions Packs/Base/Scripts/ValidateContent/ValidateContent.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,15 @@ def validate_content(filename: str, data: bytes, tmp_directory: str) -> List:
demisto.debug("log capture:" + tmp.read())

all_outputs = []
with open(json_output_path, 'r') as json_outputs:
with open(json_output_path) as json_outputs:
outputs_as_json = json.load(json_outputs)
if outputs_as_json:
if type(outputs_as_json) == list:
all_outputs.extend(outputs_as_json)
else:
all_outputs.append(outputs_as_json)

with open(lint_output_path, 'r') as json_outputs:
with open(lint_output_path) as json_outputs:
outputs_as_json = json.load(json_outputs)
if outputs_as_json:
if type(outputs_as_json) == list:
Expand Down
2 changes: 1 addition & 1 deletion Packs/BmcITSM/Integrations/BmcITSM/BmcITSM_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def load_mock_response(file_name: str) -> str:
Returns:
str: Mock file content.
"""
with open(os.path.join("test_data", file_name), mode="r", encoding="utf-8") as mock_file:
with open(os.path.join("test_data", file_name), encoding="utf-8") as mock_file:
return json.loads(mock_file.read())


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@pytest.mark.parametrize('incident_data_path, expected_severity', data_test_get_incident_severity)
def test_get_incident_severity(mocker, incident_data_path, expected_severity):
with open(incident_data_path, 'r') as incident_data_file:
with open(incident_data_path) as incident_data_file:
incident_data = json.load(incident_data_file)
mocker.patch.object(demisto, 'executeCommand', return_value=incident_data)
assert get_incident_severity('test') == expected_severity
Expand All @@ -22,7 +22,7 @@ def test_get_incident_severity(mocker, incident_data_path, expected_severity):

@pytest.mark.parametrize('context_data_path, expected_ids', data_test_incidents_id)
def test_incidents_id(mocker, context_data_path, expected_ids):
with open(context_data_path, 'r') as context_data_file:
with open(context_data_path) as context_data_file:
context_data = json.load(context_data_file)
mocker.patch.object(demisto, 'context', return_value=context_data)
assert list(incidents_id()) == expected_ids
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def load_mock_response(file_name: str) -> str:
str: Mock file content.
"""

with open(os.path.join('test_data', file_name), mode='r', encoding='utf-8') as mock_file:
with open(os.path.join('test_data', file_name), encoding='utf-8') as mock_file:
return json.loads(mock_file.read())


Expand Down
2 changes: 1 addition & 1 deletion Packs/CiscoASA/Integrations/CiscoASA/CiscoASA_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def load_mock_response(file_name: str) -> str | io.TextIOWrapper:
Returns:
str: Mock file content.
"""
with open(f'test_data/{file_name}', mode='r') as mock_file:
with open(f'test_data/{file_name}') as mock_file:
return json.loads(mock_file.read())


Expand Down
Loading