Skip to content

Commit

Permalink
chore: remove noqa PLR2004 comments from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jstucke authored and maringuu committed Nov 14, 2024
1 parent 0842d8c commit 6dee673
Show file tree
Hide file tree
Showing 53 changed files with 106 additions and 120 deletions.
4 changes: 2 additions & 2 deletions src/plugins/analysis/device_tree/test/test_device_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def test_analyze(analysis_plugin):
@pytest.mark.parametrize('file', [TEST_EMBEDDED, TEST_IMAGE])
def test_multiple_device_trees(file, analysis_plugin):
result = analysis_plugin.analyze(io.FileIO(file), {}, {})
assert len(result.device_trees) == 2 # noqa: PLR2004
assert len(result.device_trees) == 2
for device_tree in result.device_trees:
assert 'foo = "bar";' in device_tree.string
assert device_tree.header.version == 17 # noqa: PLR2004
assert device_tree.header.version == 17
assert device_tree.model in ['DeviceTreeTest-1', 'FooBar 1.0']


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_get_results_from_parent_fos__multiple_vfps_in_one_fw(self):

assert results is not None
assert results != {}, 'result should not be empty'
assert len(results) == 3, 'wrong number of results' # noqa: PLR2004
assert len(results) == 3, 'wrong number of results'
assert all(f in results for f in file_names), 'files missing from result'
assert 'result' in results[file_names[0]], 'analysis result is missing'
assert results[file_names[0]]['result'] == 'value', 'wrong value of analysis result'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_extract_metadata_from_file_system(self, analysis_plugin):
assert result[testfile_sticky_key].group == 'root'
assert result[testfile_sticky_key].uid == 0
assert result[testfile_sticky_key].gid == 0
assert result[testfile_sticky_key].modification_time == 1518167842.0 # noqa: PLR2004
assert result[testfile_sticky_key].modification_time == 1518167842.0

def test_extract_metadata_from_file_system__unmountable(self, analysis_plugin):
with pytest.raises(RuntimeError, match='Mounting the file system failed'):
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_extract_metadata_from_tar(self):
assert result[testfile_sticky_key].group == 'root'
assert result[testfile_sticky_key].uid == 0
assert result[testfile_sticky_key].gid == 0
assert result[testfile_sticky_key].modification_time == 1518167842 # noqa: PLR2004
assert result[testfile_sticky_key].modification_time == 1518167842

def test_extract_metadata_from_tar_gz(self):
metadata = _extract_metadata_from_tar(FileIO(TEST_DATA_DIR / 'test.tar.gz'))
Expand Down Expand Up @@ -179,7 +179,7 @@ def test_extract_metadata_tar_unreadable(self):

def test_extract_metadata_from_tar__eof_error(self):
result = _extract_metadata_from_tar(FileIO(TEST_DATA_DIR / 'broken.tar.gz'))
assert 0 < len(result) < 5, 'Some files should be found but not all' # noqa: PLR2004
assert 0 < len(result) < 5, 'Some files should be found but not all'

@pytest.mark.parametrize(
('mode', 'expected'),
Expand Down Expand Up @@ -266,7 +266,7 @@ def test_yaffs(self, analysis_plugin):
}
result = analysis_plugin.analyze(FileIO(self.test_file_fs), {}, analysis)
assert isinstance(result, analysis_plugin.Schema)
assert len(result.files) == 5 # noqa: PLR2004
assert len(result.files) == 5
file_results = {r.name: r for r in result.files}
assert 'busybox' in file_results
assert file_results['busybox'].path == '/bin/busybox'
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/analysis/hash/test/test_plugin_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ def test_imphash(self, analysis_plugin):
]

assert isinstance(result['imphash'], str), 'imphash should be a string'
assert len(result['imphash']) == 32, 'imphash does not look like an md5' # noqa: PLR2004
assert len(result['imphash']) == 32, 'imphash does not look like an md5'
4 changes: 2 additions & 2 deletions src/plugins/analysis/kernel_config/test/test_kernel_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ def test_check_kernel_hardening():
result = check_kernel_hardening(kernel_config)
assert isinstance(result, list)
assert all(isinstance(tup, tuple) for tup in result)
assert len(result) > 50 # noqa: PLR2004
assert all(len(tup) == 7 for tup in result), 'all results should have 6 elements' # noqa: PLR2004
assert len(result) > 50
assert all(len(tup) == 7 for tup in result), 'all results should have 6 elements'
assert any(len(tup[5]) > 0 for tup in result), 'some "protection against" info shouldn\'t be empty'


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def test_process_object_yara(self, analysis_plugin):

results = analysis_plugin.process_object(test_file).processed_analysis[analysis_plugin.NAME]

assert (
len(results) == 4 # noqa: PLR2004
), 'incorrect number of vulnerabilities found (summary + tag + one result)'
assert len(results) == 4, 'incorrect number of vulnerabilities found (summary + tag + one result)'
assert 'DLink_Bug' in results, 'test match not found'
assert results['DLink_Bug']['score'] == 'high', 'incorrect or no score found in meta data'

Expand All @@ -36,9 +34,7 @@ def test_process_object_software(self, analysis_plugin):

results = analysis_plugin.process_object(test_file).processed_analysis[analysis_plugin.NAME]

assert (
len(results) == 3 # noqa: PLR2004
), 'incorrect number of vulnerabilities found (summary + tag + one result)'
assert len(results) == 3, 'incorrect number of vulnerabilities found (summary + tag + one result)'
assert 'Heartbleed' in results, 'test match not found'
assert results['Heartbleed']['score'] == 'high', 'incorrect or no score found in meta data'

Expand All @@ -61,9 +57,7 @@ def test_process_object_hash(self, analysis_plugin):

results = analysis_plugin.process_object(test_file).processed_analysis[analysis_plugin.NAME]

assert (
len(results) == 3 # noqa: PLR2004
), 'incorrect number of vulnerabilities found (summary + tag + one result)'
assert len(results) == 3, 'incorrect number of vulnerabilities found (summary + tag + one result)'
assert 'Netgear_CGI' in results, 'test match not found'
assert results['Netgear_CGI']['score'] == 'medium', 'incorrect or no score found in meta data'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_get_dotted_path_from_dictionary():
abc = {'a': {'b': {'c': 5}}}
assert _get_dotted_path_from_dictionary(abc, 'a') == {'b': {'c': 5}}
assert _get_dotted_path_from_dictionary(abc, 'a.b') == {'c': 5}
assert _get_dotted_path_from_dictionary(abc, 'a.b.c') == 5 # noqa: PLR2004
assert _get_dotted_path_from_dictionary(abc, 'a.b.c') == 5


def test_get_value():
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/analysis/linter/test/test_lua_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_do_analysis(monkeypatch):
)
result = run_luacheck('any/path')
assert result
assert len(result) == 10 # noqa: PLR2004
assert len(result) == 10
assert result[0] == {'message': "unused variable 'select'", 'line': 88, 'column': 7, 'symbol': 'W211'}


Expand Down
2 changes: 1 addition & 1 deletion src/plugins/analysis/linter/test/test_python_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_do_analysis(monkeypatch):
)
result = run_pylint('any/path')

assert len(result[0].keys()) == 5 # noqa: PLR2004
assert len(result[0].keys()) == 5
assert result[0]['type'] == 'warning'


Expand Down
4 changes: 2 additions & 2 deletions src/plugins/analysis/linter/test/test_ruby_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def test_do_analysis_unmocked():
hello_world_ruby = Path(__file__).parent / 'data/hello_world_ruby'
result = run_rubocop(str(hello_world_ruby))

assert len(result) == 2 # noqa: PLR2004
assert len(result) == 2

hello_world_dot_ruby = Path(__file__).parent / 'data/hello_world.ruby'
result = run_rubocop(str(hello_world_dot_ruby))

assert len(result) == 2 # noqa: PLR2004
assert len(result) == 2
4 changes: 2 additions & 2 deletions src/plugins/analysis/linter/test/test_shell_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def test_do_analysis(monkeypatch):
result = run_shellcheck('any/path')

assert result
assert len(result) == 2, 'info issue should be discarded' # noqa: PLR2004
assert len(result) == 2, 'info issue should be discarded'

assert len(result[0].keys()) == 5 # noqa: PLR2004
assert len(result[0].keys()) == 5
assert result[0]['type'] == 'warning'


Expand Down
8 changes: 4 additions & 4 deletions src/plugins/analysis/qemu_exec/test/test_plugin_qemu_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_find_relevant_files(self, analysis_plugin):
analysis_plugin.root_path = tmp_dir.name
analysis_plugin.unpacker.set_tmp_dir(tmp_dir)
result = sorted(analysis_plugin._find_relevant_files(Path(tmp_dir.name)))
assert len(result) == 4 # noqa: PLR2004
assert len(result) == 4

path_list, mime_types = list(zip(*result))
for path in ['/lib/ld.so.1', '/lib/libc.so.6', '/test_mips_static', '/usr/bin/test_mips']:
Expand Down Expand Up @@ -154,7 +154,7 @@ def test_process_object(self, analysis_plugin):
analysis_plugin.process_object(test_fw)
result = test_fw.processed_analysis[analysis_plugin.NAME]
assert 'files' in result
assert len(result['files']) == 4 # noqa: PLR2004
assert len(result['files']) == 4
assert any(result['files'][uid]['executable'] for uid in result['files'])

@pytest.mark.timeout(15)
Expand All @@ -166,7 +166,7 @@ def test_process_object__with_extracted_folder(self, analysis_plugin):
analysis_plugin.process_object(test_fw)
result = test_fw.processed_analysis[analysis_plugin.NAME]
assert 'files' in result
assert len(result['files']) == 3 # noqa: PLR2004
assert len(result['files']) == 3
assert result['files'][test_file_uid]['executable'] is True

@pytest.mark.timeout(10)
Expand Down Expand Up @@ -346,7 +346,7 @@ def test_merge_similar_entries():
'option_5': {'a': 'x', 'b': 'x', 'c': 'x'},
}
qemu_exec.merge_identical_results(test_dict)
assert len(test_dict) == 3 # noqa: PLR2004
assert len(test_dict) == 3
assert any(all(option in k for option in ['option_1', 'option_2', 'option_5']) for k in test_dict)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_process_object(self, analysis_plugin):

processed_file = analysis_plugin.process_object(test_file)
results = processed_file.processed_analysis[analysis_plugin.NAME]
assert len(results) == 2, 'incorrect number of software components found' # noqa: PLR2004
assert len(results) == 2, 'incorrect number of software components found'
assert 'MyTestRule' in results, 'test Rule match not found'
assert (
results['MyTestRule']['meta']['software_name'] == 'Test Software'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_check_meta_fields(self):

def test_check_meta_fields_missing(self):
missing_fields = self.sigTest.check_meta_fields(TEST_SIGNATURE_PATH)
assert len(missing_fields) == 3 # noqa: PLR2004
assert len(missing_fields) == 3
assert all(
entry in missing_fields
for entry in ['website in missing_meta_1', 'description in missing_meta_1', 'ALL in missing_meta_2']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_add_format_string_score(self):
def test_add_length_score(self):
input_data = 'four'
result = _add_length_score(input_data, 0)
assert result == 2, 'Parameter not detected' # noqa: PLR2004
assert result == 2, 'Parameter not detected'

def test_add_path_score(self):
input_true = 'path: /home/user'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_process_object_shadow_file(self, analysis_plugin):
processed_object = analysis_plugin.process_object(test_file)
results = processed_object.processed_analysis[analysis_plugin.NAME]

assert len(results) == 15 # noqa: PLR2004
assert len(results) == 15
for item in [
'vboxadd:unix',
'mongodb:unix',
Expand Down Expand Up @@ -55,7 +55,7 @@ def test_process_object_password_in_binary_file(self, analysis_plugin):
processed_object = analysis_plugin.process_object(test_file)
results = processed_object.processed_analysis[analysis_plugin.NAME]

assert len(results) == 4 # noqa: PLR2004
assert len(results) == 4
for item in ['johndoe:unix', 'max:htpasswd']:
assert item in results
assert item in results['summary']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ def test_run_compare_plugin(self):
self.fw_one.list_of_all_included_files.append('foo')
self.fw_two.list_of_all_included_files.append('foo')
result = self.c_plugin.compare_function([self.fw_one, self.fw_two], {})
assert len(result.keys()) == 5 # noqa: PLR2004
assert len(result.keys()) == 5

def test_find_changed_text_files(self):
result = self.c_plugin._find_changed_text_files([self.fw_one, self.fw_two], common_files=[])
assert '/foo' in result
assert '/bar' in result
assert result['/foo'] == [('uid_1', 'uid_4')]
assert len(result['/bar']) == 2 # noqa: PLR2004
assert len(result['/bar']) == 2


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion src/test/acceptance/rest/test_rest_statistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_status(self, test_client, workload_statistic, unpacking_scheduler, anal

rv = test_client.get('/rest/status', follow_redirects=True)

assert rv.status_code == 200 # noqa: PLR2004
assert rv.status_code == 200
assert all(key in rv.json for key in ['system_status', 'plugins'])
assert 'backend' in rv.json['system_status']
assert rv.json['system_status']['backend']['status'] == 'online'
Expand Down
4 changes: 2 additions & 2 deletions src/test/acceptance/test_io_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ def test_ida_download_bad_uid(self, test_client):

def test_pdf_download(self, test_client, backend_db):
response = test_client.get(f'/pdf-download/{self.test_fw.uid}')
assert response.status_code == 200, 'pdf download link failed' # noqa: PLR2004
assert response.status_code == 200, 'pdf download link failed'
assert b'File not found in database' in response.data, 'radare view should fail on missing uid'

backend_db.add_object(self.test_fw)

response = test_client.get(f'/pdf-download/{self.test_fw.uid}')

assert response.status_code == 200, 'pdf download failed' # noqa: PLR2004
assert response.status_code == 200, 'pdf download failed'
device = self.test_fw.device_name.replace(' ', '_')
assert response.headers['Content-Disposition'] == f'attachment; filename={device}_analysis_report.pdf'
assert magic.from_buffer(response.data, mime=True) == 'application/pdf'
2 changes: 1 addition & 1 deletion src/test/acceptance/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _show_home(self, test_client):
assert b'backend cpu load' in rv.data
assert b'test comment' in rv.data
assert (
rv.data.count(f'onclick="location.href=\'/analysis/{test_fw_a.uid}\'"'.encode()) == 2 # noqa: PLR2004
rv.data.count(f'onclick="location.href=\'/analysis/{test_fw_a.uid}\'"'.encode()) == 2
), 'There should be two analysis links: one for latest comments and one for latest submissions'

def _show_system_monitor(self, test_client):
Expand Down
2 changes: 1 addition & 1 deletion src/test/integration/intercom/test_backend_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self):

def get_next_task(self):
self.counter.value += 1
return 'test_task' if self.counter.value < 2 else None # noqa: PLR2004
return 'test_task' if self.counter.value < 2 else None

def shutdown(self):
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_check_collision(
assert unpacking_finished_event.wait(timeout=25)

fo_from_db = frontend_db.get_object(TARGET_UID)
assert len(fo_from_db.virtual_file_path) == 2, 'fo should have two parents' # noqa: PLR2004
assert len(fo_from_db.virtual_file_path) == 2, 'fo should have two parents'
assert FIRST_ROOT_ID in fo_from_db.virtual_file_path
assert fo_from_db.virtual_file_path[FIRST_ROOT_ID] == ['/test']
assert SECOND_ROOT_ID in fo_from_db.virtual_file_path
Expand Down
2 changes: 1 addition & 1 deletion src/test/integration/scheduler/test_unpack_and_analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_unpack_and_analyse(self, analysis_scheduler, unpacking_scheduler, post_
processed_container.setdefault(uid, {}).setdefault(plugin, {})
processed_container[uid][plugin] = analysis_result

assert len(processed_container) == 4, '4 files should have been analyzed' # noqa: PLR2004
assert len(processed_container) == 4, '4 files should have been analyzed'
assert all(
sorted(processed_analysis) == ['file_hashes', 'file_type']
for processed_analysis in processed_container.values()
Expand Down
2 changes: 1 addition & 1 deletion src/test/integration/scheduler/test_unpack_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_unpack_only(self, unpacking_scheduler, post_unpack_queue):

processed_container = post_unpack_queue.get(timeout=5)

assert len(processed_container.files_included) == 3, 'not all included files found' # noqa: PLR2004
assert len(processed_container.files_included) == 3, 'not all included files found'
included_uids = {
'289b5a050a83837f192d7129e4c4e02570b94b4924e50159fad5ed1067cfbfeb_20',
'd558c9339cb967341d701e3184f863d3928973fccdc1d96042583730b5c7b76a_62',
Expand Down
2 changes: 1 addition & 1 deletion src/test/integration/statistic/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_get_general_stats(stats_updater, backend_db):
backend_db.add_object(child_fo)
stats = stats_updater.get_general_stats()
assert stats['number_of_firmwares'] == 1, 'number of firmwares not correct'
assert stats['number_of_unique_files'] == 3, 'number of files not correct' # noqa: PLR2004
assert stats['number_of_unique_files'] == 3, 'number of files not correct'


def test_get_mitigation_stats(stats_updater, backend_db):
Expand Down
2 changes: 1 addition & 1 deletion src/test/integration/storage/test_binary_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_get_repacked_binary_and_file_name_invalid_uid(binary_service):

def test_read_partial_binary(binary_service):
partial_binary = binary_service.read_partial_binary(TEST_FW.uid, 30, 14)
assert len(partial_binary) == 14 # noqa: PLR2004
assert len(partial_binary) == 14
assert partial_binary == b'get_files_test', 'invalid result not correct'


Expand Down
2 changes: 1 addition & 1 deletion src/test/integration/storage/test_db_interface_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_update_duplicate_same_fw(backend_db, frontend_db):

db_fo = frontend_db.get_object(fo.uid)
assert list(db_fo.virtual_file_path) == [fw.uid]
assert len(db_fo.virtual_file_path[fw.uid]) == 2 # noqa: PLR2004
assert len(db_fo.virtual_file_path[fw.uid]) == 2
assert db_fo.parents == {fw.uid}


Expand Down
Loading

0 comments on commit 6dee673

Please sign in to comment.